This is rather a beginner question. I wonder what happens when sleep
command is triggered from a bash script, for example. That job would still running, with less priority?
Asked
Active
Viewed 6,405 times
2

muru
- 197,895
- 55
- 485
- 740

whitenoisedb
- 733
- 4
- 12
- 18
1 Answers
8
Typically, sleep
is the GNU sleep
program. This program calls the GNU function xnanosleep
, which in turn calls the Linux nanosleep
system call. And:
nanosleep() suspends the execution of the calling thread until either
at least the time specified in *req has elapsed, or the delivery of a
signal that triggers the invocation of a handler in the calling thread
or that terminates the process.
So the process is, by definition, not running (whatever maybe the priority), but suspended.
Testing this out:
sleep 10 & ps aux | grep $!
[1] 25682
muru 25682 0.0 0.0 7196 620 pts/13 SN 04:10 0:00 sleep 10
The process state is SN
:
S interruptible sleep (waiting for an event to complete)
N low-priority (nice to other users)
Ignore the N
, I'd guess that's how it was when it started out. So the effective state of sleep
is interruptible sleep
.
-
1Thanks for your clear answer. It was a good approach to check the process state while running it and see what those letters mean. – whitenoisedb Sep 17 '14 at 00:35
sleep
to target other processes. – terdon Sep 16 '14 at 22:39