使用
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