The simple way to wait until a signal arrives is to call
Please read about its disadvantages, in the following section, before
you use it.
Preliminary: | MT-Unsafe race:sigprocmask/!bsd!linux | AS-Unsafe lock/hurd | AC-Unsafe lock/hurd | See POSIX Safety Concepts.
pausefunction suspends program execution until a signal arrives whose action is either to execute a handler function, or to terminate the process.
If the signal causes a handler function to be executed, then
pausereturns. This is considered an unsuccessful return (since “successful” behavior would be to suspend the program forever), so the return value is
-1. Even if you specify that other primitives should resume when a system handler returns (see Interrupted Primitives), this has no effect on
pause; it always fails when a signal is handled.
errnoerror conditions are defined for this function:
- The function was interrupted by delivery of a signal.
If the signal causes program termination,
pausedoesn't return (obviously).
This function is a cancellation point in multithreaded programs. This is a problem if the thread allocates some resources (like memory, file descriptors, semaphores or whatever) at the time
pauseis called. If the thread gets cancelled these resources stay allocated until the program ends. To avoid this calls to
pauseshould be protected using cancellation handlers.
pausefunction is declared in unistd.h.