[GNU Manual] [POSIX requirement] [Linux man] [FreeBSD man]
Summary
sleep - delay for a specified time
Lines of code: 155
Principal syscall: nanosleep()
Support syscalls: None
Options: 2 (help and version)
Spirtually linked to the sleep utility from Version 3 (4?) UNIX (1973)
Added to Shellutils in November 1992 [First version]
Number of revisions: 131 [Code Evolution]
apply_suffix()
- Converts the input value to seconds from the given suffix basis
die()
- Exit with mandatory non-zero error and message to stderrerror()
- Outputs error message to standard error with possible process terminationxnanosleep()
- gnulib wrapper for thenanosleep()
syscall
Setup
sleep only uses the default parsing options, which require no initialization
main() initializes the following:
ok
- The status of parsingseconds
- The number of seconds to sleep
Parsing
Parsing sleep means interpreting the interval argument. We separate the number from the suffix and then multiply the number based on the suffix to find the number of seconds.
Parsing failures
This failure case is explicitly checked:
- No argument is provided
- An unknown time interval is used
This failure result in a short error message followed by the usage instructions.
Execution
Execution is merely passing the calculated seconds to xnanosleep()
.
Failure occurs if xnanosleep()
fails.