4

Many years ago I had an issue with Linux where processes would randomly go to sleep. Back then, I knew a trick with the /proc filesystem to trigger a wakeup of the process. I vaguely remember being able to do something like "echo R" >/proc/pid/stat but that doesn't appear to be the right command.

There are lots of hits on the internet for "how do I wake a sleeping process?" and so many of the answers are "oh, just kill it!" I know there's another way, but my memory is failing me now.

So far I've tried:

kill -SIGCONT <pid>
echo "R" > /proc/<pid>/status
echo "R" > /proc/<pid>/stat
11

What do you mean by “sleep”?

If you mean state S (interruptible sleep), that means that the process is waiting for I/O. The process is currently engaged in a blocking system call. You can't force it to “wake up” in a generic way — what would it do then? It'll wake up when the input or output operation it wants to make is possible (e.g. when data is available to read, when a write channel becomes ready, etc.).

If you mean state T (stopped), that means that the process is currently suspended. You can unsuspend it by sending it a CONT signal (SIGCONT): kill -CONT PID.

Processes do not “randomly go to sleep”. They sleep when they have nothing to do. They get suspended if they receive a signal that stops them: SIGTSTP, SIGSTOP, SIGTTIN, SIGTTOU. These last two signals are sent by the terminal interface in the kernel when a background process tries to read from the terminal (resp. write to the terminal); if you aren't aware of that, you might think that the process randomly stops. If that's what happened, you need to bring it to the foreground; run fg in the shell from which you started that background job, with the right argument to indicate the job that the process is part of, e.g. fg %3.

The stat* files in Linux's /proc are read-only and I'm not aware of any time when they were writable. I don't know what you could hope to write there. The data reported by this file is kernel-managed data, and some of it can be changed more or less directly by the process, but it isn't something you can modify from the outside. For example you can't magically make a process become runnable.

0

It depends on how a process handles a signal. If it doesn’t handle it the way the process want , the default action of signal will take place , some signals can be trapped and some can't be.

I am not sure , but you should look at the difference between stopped and sleeping process , as far as the signal manual says:

  Cont   Default action is to continue the process if it is currently stopped.

For the sleeping process it may be the fg command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.