简体   繁体   English

我怎么知道哪个孩子退出了C语言?

[英]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.

相关问题 如何从父进程获取子进程的状态,即它是停止、继续还是退出? 对于 Linux、C 语言 - How do I get the status of a child process from a parent, i.e. has it stopped, continued, or exited? For Linux, C lang 我怎么知道子进程是否正在等待 C 中的键盘输入 - How can I know if child process is waiting for keyboard input in C 子进程退出后如何执行父进程? - how to execute parent process after child process has exited? 如何知道字符串中的哪些字符是 C 中单个重音字符的组合? - How can I know which characters inside a string are compositions of a single accentuated character in C? 我怎么知道c的版本? - How can I know the version of c? 我如何在SWIG中包装一个C库,而SWIG通常在C编译期间被链接? - How can I wrap a C-Library in SWIG, which has usually to be linked during C-compilation? 如何知道我使用的是哪个版本的 C 语言? - How to know which version of C language I am using? 在 Windows 中,如何在 C 中跟踪子进程读取和写入的文件? - In Windows, how can I trace in C which files a child process reads and writes? 管道保证在孩子退出后关闭 - Pipe guarantee to close after the child has exited 孩子退出后,waitpid不返回 - waitpid not returning after child has exited
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM