0
我必須使用fork()
函數編寫一個創建進程樹的腳本。然後,我需要使用腳本中的exec()
函數來生成只有一個進程樹,並使用pstree -c
命令。使用exec的單進程樹
好了,我創建的進程樹,這不是一個問題,比方說:
int main() {
int pid1, pid2;
if(pid1 = fork()) {
printf("%d", pid1);
} else if (pid2 = fork()) {
printf("%d", pid2);
} else {
printf("%s", "parent process");
}
return 0;
}
但我如何使用exec函數來調用pstree -c命令?我怎樣才能只顯示一個特定的樹?
execl("/bin/pstree -c", "pstree -c", 0, 0);
我試圖與/bin/
,沒有它......沒有什麼作品,當我運行該腳本不顯示樹。
無論如何,它會顯示整棵樹,而不僅僅是我使用的叉子。
我該怎麼做?