bassman
05-15-2003, 02:25 PM
Hello! Given this example C code:
/*
* The child executes the code inside the if.
*/
if (pid == 0) {
/*do something here*/
exit(numbersRead);
/*
* The parent executes the wait.
*/
while (wait(&status) != pid)
/* empty */ ;
What I'd like to do is, spawn a child process, make it work on something while the parent waits for it to finish (let's says, for example, read numbers from stdin) and then return it's results (in this case, return the amount of numbers read) to the parent process, using the exit() call. Meaning, for example, can I do exit(6) and the parent process acknowledge the child read 6 lines? Also, I can't understand the line
"while (wait(&status) != pid)", because it seems "status" isn't even used on the whole example program!
/*
* The child executes the code inside the if.
*/
if (pid == 0) {
/*do something here*/
exit(numbersRead);
/*
* The parent executes the wait.
*/
while (wait(&status) != pid)
/* empty */ ;
What I'd like to do is, spawn a child process, make it work on something while the parent waits for it to finish (let's says, for example, read numbers from stdin) and then return it's results (in this case, return the amount of numbers read) to the parent process, using the exit() call. Meaning, for example, can I do exit(6) and the parent process acknowledge the child read 6 lines? Also, I can't understand the line
"while (wait(&status) != pid)", because it seems "status" isn't even used on the whole example program!