Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wait(null) and wait(&status) C language and Status

Tags:

What is the difference between wait(null) and wait(&status) in c system programming?

And what is the content of the pointer status ?

like image 886
user3260388 Avatar asked Apr 15 '14 19:04

user3260388


People also ask

What does wait NULL means?

wait(NULL) or more accurately wait(0) means wait until a state change in the child process. To find out about Unix / Linux C api calls, type man <function Name> on the command line. You'll need to get used to reading those pages, so better start now.

What does wait () do in C?

A call to wait() blocks the calling process until one of its child processes exits or a signal is received. After child process terminates, parent continues its execution after wait system call instruction.

What is the difference between wait () and waitpid ()?

Difference between wait and waitpid():Wait() waits for any child process but waitpid() waits for a specific child equal to pid. By default waitpid() waits for the only terminated child where as wait() waits for both terminated or a signaled child.

Does wait NULL wait for all child processes?

while(wait(NULL) > 0); This ensures that you wait for ALL the child processes and only when all have returned, you move to the next instruction.


2 Answers

If you call wait(NULL) (wait(2)), you only wait for any child to terminate. With wait(&status) you wait for a child to terminate but you want to know some information about it's termination.

You can know if the child terminate normally with WIFEXITED(status) for example.

status contains information about processes that you can check with some already defined MACRO.

like image 51
user43968 Avatar answered Oct 04 '22 23:10

user43968


wait(NULL) will only wait until the child process is completed. But, wait(&status) will return the process id of the child process that is terminated.

pid = wait(&status); // the information is returned 
like image 33
lahiruhashan Avatar answered Oct 04 '22 23:10

lahiruhashan