O'Reilly logo

Advanced UNIX Programming by Warren W. Gay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required