使用
ps -o user,pid,ppid,command -ax | grep <process name>
获取所有子进程信息。实际上 popen() 使用 pipe() 机制来执行命令。请参阅popen()的手册页
在手册页中,
The environment of the executed command will be as if a
child process were created within the popen() call using
fork(2). If the application is standard-conforming (see
standards(5)), the child is invoked with the call:
execl("/usr/xpg4/bin/sh", "sh", "-c",command, (char *)0);
otherwise, the child is invoked with the call:
execl("/usr/bin/sh", "sh", "-c",command, (char *)0);
The pclose() function closes a stream opened by popen() by
closing the pipe. It waits for the associated process to
terminate and returns the termination status of the process
running the command language interpreter. This is the value
returned by waitpid(3C).
它清楚地表明 popen 使用 pipe 和 fork 和 execl 来处理 popen() 函数。因此,您可以使用 ps 和 aux 来获取所有子进程信息。