如何从父进程获取子进程 [英] How to get child process from parent process
本文介绍了如何从父进程获取子进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从Shell脚本中的父进程ID获取子进程ID?
Is it possible to get the child process id from parent process id in shell script?
我有一个要使用Shell脚本执行的文件,该文件会导致一个新进程 process1 (父进程).此 process1 已分叉了另一个进程 process2 (子进程).使用脚本,我可以使用以下命令获取 process1 的pid:
I have a file to execute using shell script, which leads to a new process process1 (parent process). This process1 has forked another process process2(child process). Using script, I'm able to get the pid of process1 using the command:
cat /path/of/file/to/be/executed
但是我无法获取子进程的pid.
but i'm unable to fetch the pid of the child process.
推荐答案
只需使用:
pgrep -P $your_process1_pid
这篇关于如何从父进程获取子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文