How can I know which child has exited in C?

jadelabe

i have 3 child that end at different times in different order each time, but i dont know how to get which end first

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));
Basile Starynkevitch

You should read the man page of wait(2). It returns the pid_t of the waited process.

You may also want to use waitpid (with W_NOHANG if you don't want to really wait in a blocking manner).

Also, read signal(7). You could handle SIGCHLD ....

And Advanced Linux Programming has several chapters related to the issue.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Xcode How can I know which subclass has my class?

From Dev

How can I get the state of a child after it exited?

From Dev

How can I join the 2nd process which has exited while 1st process is still running?

From Dev

How can I have an abstract parent state know which child state is active?

From Java

How to continue a Docker container which has exited

From Dev

How can I know which AWS region has the lowest latency from my location?

From Dev

How can I know which image has been downloaded with a custom image pipeline?

From Dev

how can i know which button is cliked

From Dev

How can I know which folders are created by which program?

From Dev

How can I know which folders are created by which program?

From Dev

How do I know which scene has called a particular scene?

From Dev

How can i know which link i clicked in an HTML

From Dev

How can I know which version of the C++ "standard library" is installed?

From Dev

How can i know if a sorted vector has duplicate values or not in C++

From Dev

using d3.js, how can i select a particular <g> which has particular text in <text> as its child?

From Dev

How can I know how long the application has been used?

From Dev

Pyside: How can i know which thread emitted the signal "finished"?

From Java

How can I know which button was clicked in the notification?

From Dev

How can I know which machine Juju is actually using?

From Dev

How can I know which properties are applicable for MSBuild?

From Dev

How can I know which element in a list triggered an any() function?

From Java

How can I know which radio button is selected via jQuery?

From Dev

How can I know which nodes in a cluster are actual master nodes?

From Dev

How can I know which objects retain an object?

From Dev

How can I know which type of process of linux will use for these?

From Dev

How can I know which tasks are running in the background?

From Dev

How can I know which process is using swap?

From Dev

Tcl/tk How can i know when and which radiobutton is selected?

From Dev

How can I know the cursor in which edittext in Android

Related Related

  1. 1

    Xcode How can I know which subclass has my class?

  2. 2

    How can I get the state of a child after it exited?

  3. 3

    How can I join the 2nd process which has exited while 1st process is still running?

  4. 4

    How can I have an abstract parent state know which child state is active?

  5. 5

    How to continue a Docker container which has exited

  6. 6

    How can I know which AWS region has the lowest latency from my location?

  7. 7

    How can I know which image has been downloaded with a custom image pipeline?

  8. 8

    how can i know which button is cliked

  9. 9

    How can I know which folders are created by which program?

  10. 10

    How can I know which folders are created by which program?

  11. 11

    How do I know which scene has called a particular scene?

  12. 12

    How can i know which link i clicked in an HTML

  13. 13

    How can I know which version of the C++ "standard library" is installed?

  14. 14

    How can i know if a sorted vector has duplicate values or not in C++

  15. 15

    using d3.js, how can i select a particular <g> which has particular text in <text> as its child?

  16. 16

    How can I know how long the application has been used?

  17. 17

    Pyside: How can i know which thread emitted the signal "finished"?

  18. 18

    How can I know which button was clicked in the notification?

  19. 19

    How can I know which machine Juju is actually using?

  20. 20

    How can I know which properties are applicable for MSBuild?

  21. 21

    How can I know which element in a list triggered an any() function?

  22. 22

    How can I know which radio button is selected via jQuery?

  23. 23

    How can I know which nodes in a cluster are actual master nodes?

  24. 24

    How can I know which objects retain an object?

  25. 25

    How can I know which type of process of linux will use for these?

  26. 26

    How can I know which tasks are running in the background?

  27. 27

    How can I know which process is using swap?

  28. 28

    Tcl/tk How can i know when and which radiobutton is selected?

  29. 29

    How can I know the cursor in which edittext in Android

HotTag

Archive