sleep() causes the current process to be suspended from execution until either the number of real-time seconds specified by seconds has elapsed or a signal is delivered to the calling process, and the action of that signal is to invoke a signal-handler or to terminate the process. The actual suspension time may be longer than seconds for priority reasons (i.e. due to the scheduling of other activity by the system).
If a SIGALRM signal is generated for the calling process during execution of sleep() and if the SIGALRM signal is being ignored or blocked from delivery, it is undefined whether sleep() will return when the signal is processed. If the signal is blocked, it is likewise undefined whether it will still be pending after sleep() returns or whether it will be discarded. If a SIGALRM signal is generated for the calling process during the execution of sleep() , except as a result of a prior call to alarm() , and if the SIGALRM signal is not being ignored or blocked from delivery, it is undefined whether that signal will have any effect other than forcing sleep() to return. If sleep() is interrupted by a signal handler, the results are undefined under the following conditions: if the signal handler examines or changes the time at which a SIGALRM signal is to be generated if the signal handler changes the action associated with the SIGALRM signal if the signal handler changes whether the SIGALRM signal is to be blocked from delivery
If a signal handler interrupts sleep() and calls siglongjmp() or longjmp() to restore an environment saved prior to the sleep() call, both the action associated with the SIGALRM signal and the time at which the signal is to be generated are undefined. It is likewise undefined whether the SIGALRM signal will be blocked if the signal mask of the process is not also restored as part of the environment (see also sigsetjmp() ). If threads are used, then the function affects the process or a thread in the following manner: sleep() causes the current thread to be suspended until the specified time has expired or until a signal is sent to the thread. |