The Sleep Functions
Chapter 15 stated that the sleep(3) function is often implemented in terms of the alarm(3) function. You will look at one such hypothetical implementation of sleep(3) in this section. The function synopsis for sleep(3) is as follows:
#include <unistd.h> unsigned int sleep(unsigned int seconds);
The function accepts a time value in seconds to pause the execution of the calling process. If the sleep(3) call is interrupted because a signal was received, the remaining time in seconds is returned to the caller. The return value 0 indicates that the full sleep time has elapsed.
Listing 17.1 shows a simple program that calls on sleep(3). The program simply reports the starting time, sleeps for five seconds, and then reports the ...
Get Advanced UNIX Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.