Blocking non-blocking process waiting for wait waitpid

Process waiting: The
parent process waits for the launch of the child process, obtains the return value of the child process, and releases resources to prevent zombie processes.

operating:

pid_t wait(int* status)

status: an address in the plastic space, accepts the return value of the child process;
return value:
returns the child process pid on success, and returns -1 on failure; **
Wait for any child process to exit. If it does not exit, it will block and wait forever;

Blocking: In order to complete a certain purpose to call a certain function, if it does not meet the completion conditions, it will wait forever;
if the child process exits before the call, it will be processed immediately when the call is made

pid_t waitpid(pid_t childpid,int  *status,int options)

You can wait for one or the specified one;
you can either block or non-block to wait for
childpid: -1 waiting for any child process
greater than 0 means waiting for the specified child process
status to get the return value of the child process
option : 0-default blocking Waiting for
WNOHANG-Set the non-blocking waiting
return value: error returns -1;
no child process exits returns 0;
child process exits returns to child process pid

.

Non-blocking: In order to complete a certain function, initiate a call, and the current conditions are not met, then immediately return;
as long as the call, exit is processed directly;

Guess you like

Origin blog.51cto.com/14982125/2667901