# Include <unistd. h> sleep (unsigned
This function suspends the calling process until one of the following conditions is met:
(1) The wall clock time specified by seconds has passed.
(2) Call the process to capture a signal and return it from the signal processing program.
If the alarm signal is the same, because of other system activities, the actual return time is later than the required time.
In the (1) case, the return value is 0. When sleep returns early (Case 2) because a signal is captured, the returned value is the number of seconds (the required time minus the actual sleep time ).
Although sleep can be implemented using the alarm function (http://www.cnblogs.com/nufangrensheng/p/3515013.html), this is not necessary. If alarm is used, the two functions may interact with each other.
Program list 10-21 reliable implementation of sleep
# Include = & newact, & newmask, & = & suspmask, SIGALRM); & suspmask); = alarm (& oldact, NULL );&
This blog is excerpted from advanced programming for UNIX environments (version 2) and used only for personal learning records. For more information about this book, see:Http://www.apuebook.com/.