Your Browser is not longer supported
Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...
{{viewport.spaceProperty.prod}}
sleep - Suspend a program for a fixed period of time
&pagelevel(4)&pagelevel
Definition | #include <signal.h> int sleep(unsigned int sec); sleep suspends a program for sec seconds.
|
Return val. | Requested time minus actual time. If sleep was ended earlier than specified in sec, the time still remaining will be indicated (cf. note). |
Note | sleep delays the program for sec seconds by internally calling the VPASS macro with a value of one second in a loop.
Although the program is suspended for sec seconds when sleep is called, time continues to run for a previously set alarm clock (with alarm ). The implications of this are detailed below: If the previously set alarm time is less than the sleep time, e.g. alarm(2);
sleep(30);
the alarm is triggered and the sleep call is ended after two "sleep" seconds have elapsed. If the previously set alarm time is greater than the sleep time, e.g. alarm(30);
sleep(5);
time continues to run on the alarm clock for 5 "sleeping" seconds. Following the sleep call, the alarm clock will be set at 25.
The time for which the program is actually suspended may also deviate from sec for the following reasons: |
See also | alarm, signal |