[英]How can I know which child has exited in C?
i have 3 child that end at different times in different order each time, but i dont know how to get which end first 我有3个孩子每次在不同的时间以不同的顺序结束,但我不知道如何首先得到哪一端
i have something like this, where "winner", "second" and "third" are, random generated times, the first ending is "winner" but i dont know who it is 我有类似的东西,“赢家”,“第二”和“第三”,随机生成的时间,第一个结局是“赢家”,但我不知道它是谁
wait(&winner);
wait(&second);
wait(&third);
printf("======================================\n");
printf("----------Classification---------------\n");
printf("======================================\n");
printf("-First-.... Team %d , time: %d\n",/*1*/, WEXITSTATUS(winner));
printf("-Second-.... Team %d , time: %d\n",/*2*/, WEXITSTATUS(second));
printf("-Third-.... Team %d , time: %d\n",/*3*/, WEXITSTATUS(third));
You should read the man page of wait(2) . 您应该阅读wait(2)的手册页。 It returns the
pid_t
of the waited process. 它返回等待进程的
pid_t
。
You may also want to use waitpid
(with W_NOHANG
if you don't want to really wait in a blocking manner). 您可能还想使用
waitpid
(如果不想真正地以阻塞方式使用W_NOHANG
)。
Also, read signal(7) . 另外,读信号(7) 。 You could handle
SIGCHLD
.... 您可以处理
SIGCHLD
....
And Advanced Linux Programming has several chapters related to the issue. 高级Linux编程有几个与此问题相关的章节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.