How do I exit two child processes in C?

Posted 09 April 2013 - 08:18 AM

Geez. It seems whenever I'm back here, it's always because I have a problem with my schoolwork.

Basically, my task is to "Write a program in C that fork() 2 child and wait for the 2 child to exit,
and then the program will output the exit status of both child.", and I was given this as my refernce:

$ ./Exercise1ba.out
This is the parent process. My PID is 6985
I am child number 1 , and my PID is: 6986
And my parent ID is 6985
I am child number 2 , and my PID is: 6987
And my parent ID is 6985
This is the parent process. My PID is 6985

So what I would like to know is how do I implement the exits
in this case, as I'm unsure on where to place it inside
the code. I've searched for a solution in my textbook (The Definite Guide
To Linux Network Programming) and the internet, to no avail, so
any help is greatly appreciated.

Replies To: How do I exit two child processes in C?

Re: How do I exit two child processes in C?

Posted 09 April 2013 - 08:35 AM

You shouldn't use return or exit from the child. The reason for this is that exit will perform cleanup and then call the _exit() function. Call the _exit() function instead. Also, have a look at the man pages for the wait() command, if you look at the reference you posted, the wait() function is used to wait for the child to close. The man pages have a few examples to go by as well. Specifically, man 2 wait, should help you.