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?

2
  • I mean, in general, when our script is an infinite loop and we call sleep 120 (for example). What are the CPU decisions on that script? I think it should have less priority, because the script is like paused. Sep 16, 2014 at 22:34
  • Ah, gotcha. Please edit your question to make that clearer (I will delete my comment), I thought you were under the impression that you could use sleep to target other processes.
    – terdon
    Sep 16, 2014 at 22:39

1 Answer 1

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.

1
  • 1
    Thanks for your clear answer. It was a good approach to check the process state while running it and see what those letters mean. Sep 17, 2014 at 0:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .