You are not logged in.
Pages: 1
Does anyone know how sleep command works?
If I send "sleep 2m" to terminal.. would cpu be idling during those 2 minutes (from that command itself)? Is there something that is implemented in kernel that tells how sleep command works? and how its implemented in code?
Last edited by kdar (2012-08-08 21:39:54)
Offline
Here's the code: http://git.savannah.gnu.org/cgit/coreut … rc/sleep.c
Offline
ah thanks.
Offline
the sleep command doesn't do anything to your cpu. all it does is pause the shell for the specified length of time. it is handy for scripting mostly.
for instance, if you ran the following in your shell:
sleep 5; echo hello
the shell will wait for 5 seconds before printing "hello"
the important point is that other programs and processes are still running, and you can still run other commands on another shell during the sleep time. you can also "ctrl-c" to cancel sleep while it's waiting.
Last edited by paranoos (2012-08-22 06:04:31)
Offline
Here's the code: http://git.savannah.gnu.org/cgit/coreut … rc/sleep.c
Looks like the real work is done in gnulib: http://git.savannah.gnu.org/cgit/gnulib … anosleep.c
It looks like a loop that just continuously counts the number of nanoseconds that have passed to see if you've reached the requested time.
Actually keeping track of nanoseconds is handled by timespec. Doesn't look like a lot of code is involved, but I can't follow it. I'd be interested to hear an explanation!
Offline
Pages: 1