使用
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使用管道和叉子EXECL用于处理POPEN()函数。所以,你可以使用ps和aux来获取所有的子进程信息。
没有人,它会如果我的项目有许多发生冲突具有相同名称的子进程。 – quanrock
从C/C++代码执行命令,您必须使用fork()和exec() – Saravanan