if (pid == 0)
{
// descendant - call exec ()
}
else
{
// ancestor
- wait for posterity
int status;
waitpid (pid, & status, 0);
// continue execution
}
The status value gives you more information about the completed
descendant process. There
are a number of macros with < sys/wait for .h>:
WIFEXITED ( status ) - a non-zero value when the descendant
of a step has completed normally;
WEXITSTATUS ( status ) - descendant return code (only when
WIFEXITED ()! = 0).
The descendant return code is obtained as follows :
waitpid (pid, & status, 0);
if (WIFEXITED (status))
printf (" Descendant ended with code % d \ n",
WEXITST A TUS (status));
5/3 7 Alerts
In the case of multitasking, there is a need to report processes about events
occurring in the system or other processes. The simplest mechanism for this
alert, defined by POSIX , is the
alerts . The
process after receiving the
signal immediately responds to his call special functions - a
handler of the
signal ( signal handler ), or action by default for this signal with each signal
related to its number, which is unique in the system. No other information
along with the signal can be transmitted.
Alarms are the simplest mechanism for interprocess on UNIX systems but
since they allow the transmission of limited data, they are mainly used for
event reporting.