-1
pid_t pid;
if ((pid == fork()) == 0){
if (execvp(arg[0], arg) < 0) {
printf("%s: Command not found.\n", arg[0]);
exit(0);
}
}
if (background == 0)
{
int status;
if (waitpid(pid, &status, 0) < 0)
printf("waitfg: waitpid error");
while(waitpid(-1, 0, WNOHANG) >= 0){}
}
else
{
printf("%d %s", pid, cmdline);
}
我有這個代碼爲我的程序,我想讓父母收穫所有子進程,問題是它仍然沒有收穫。我想使用的代碼:C-收穫子進程和背景
while(waitpid(-1, 0, WNOHANG) >= 0){}
爲了謀取但它似乎無法擺脫殭屍進程。那我該怎麼做,而不是謀取然後
而且我不知道如果我這樣做的背景就在這裏。
更改'if((pid == fork())== 0){'by'if((pid = fork())== 0){' – Garf365
另一個咬住灰塵,('聰明'複合表達式)。 –