简体   繁体   中英

Java - get parent process

我认为Java在获取进程的API中没有提供太多信息,您是否可以通过Java获得父进程的PID / ID?

如果您在Linux上运行,则可以使用/ proc / self / stat检查procfs

Following from @Imz's answer, on Linux, grab the output of /proc/self/stat (it's a one-line file, so just read it like a normal file)

43732 (java) S 43725 43725 11210 34822 43725 4202496 127791 387073 4055 0 3188 79 4597 253 20 0 53 0 16217706 39231705088 188764 18446744073709551615 4194304 4196452 140735605394256 140735605376816 274479481597 0 0 2 16800973 18446744073709551615 0 0 17 13 0 0 0 0 0

The 4th field (in bold above) is your parent process id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM