Professional Documents
Culture Documents
Wait Vs waitpid
• The wait function can block the caller until a
child process terminates, whereas waitpid has
an option that prevents it from blocking.
WIFSIGNALED (status) True if status was returned for a child that terminated
abnormally, by receipt of a signal that it didn't catch. In this
case, we can execute
WTERMSIG (status)
to fetch the signal number that caused the termination.
Additionally, some implementations (but not the Single
UNIX Specification) define the macro
WCOREDUMP (status)
that returns true if a core file of the terminated process
was generated.
WIFSTOPPED (status) True if status was returned for a child that is currently
stopped. In this case, we can execute
WSTOPSIG (status)
to fetch the signal number that caused the child to stop.
WIFCONTINUED (status) True if status was returned for a child that has been
continued after a job control stop (XSI extension to POSIX.1;
waitpid only).
Waitpid
• Waits for a specific process
• pid == 1
– Waits for any child process. In this respect, waitpid
is equivalent to wait.
• pid > 0
– Waits for the child whose process ID equals pid
• pid == 0
– Waits for any child whose process group ID equals
that of the calling process
Self Suspension
• A process must obtain its process ID and then pass
the ID as an argument to suspend.
• Pause function
– int pause(void);
– Causes the invoking process (or thread) to sleep until a
signal is received that either terminates it or causes it
to call a signal-catching function.
– Since pause() suspends thread execution indefinitely
unless interrupted by a signal, there is no successful
completion return value.
Continued…
• Kill
– int kill(pid_t pid, int sig);
– If pid is greater than 0, sig shall be sent to the process
whose process ID is equal to pid.
– If pid is 0, sig shall be sent to all processes (excluding
an unspecified set of system processes)
– If pid is -1, sig shall be sent to all processes (excluding
an unspecified set of system processes) for which the
process has permission to send that signal.
Continued..
• Sigaction()
– #include <signal.h>
– int sigaction(int sig, const struct sigaction
*restrict act, struct sigaction *restrict oact);
• The sigaction() function allows the calling
process to examine and/or specify the action
to be associated with a specific signal.
Continued…
• Alarm Function:
– The alarm function allows us to set a timer that
will expire at a specified time in the future
– When the timer expires, the SIGALRM signal is
generated
– If we ignore or don't catch this signal, its default
action is to terminate the process.
Continued…
• #include <unistd.h>
unsigned int alarm(unsigned int seconds);
• The seconds value is the number of clock
seconds in the future when the signal should
be generated.
• There is only one of these alarm clocks per
process