2

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?

muru
  • 207,228
whitenoisedb
  • 743
  • 5
  • 12
  • 18

1 Answers1

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.

muru
  • 207,228