mawenbao
mawenbao

Reputation: 279

kill -SIGCONT does not work

I want to use SIGTSTP(or SIGSTOP) to pause a process and resume it later with SIGCONT. SIGTSTP and SIGSTOP work just as expected, but SIGCONT does not woke up the stopped process some times.

For example: SIGCONT works well with the find command:

find / kill -SIGSTOP $pid_of_the_find_proc [1]+ Stopped find / kill -SIGCONT $pid_of_the_find_proc // find / woke up

But when I tested it with the sleep command, it just failed.

sleep 100 kill -SIGSTOP $pid_of_the_sleep_proc [1]+ Stopped sleep 100 kill -SIGCONT $pid_of_the_sleep_proc // nothing happened after sending the SIGCONT signal

However, bash's builtin command fg worked with sleep well

sleep 100 kill -SIGSTOP $pid_of_the_sleep_proc [1]+ Stopped sleep 100 kill -SIGCONT $pid_of_the_sleep_proc fg 1 // the sleep process woke up after the fg command

So my question is why kill -SIGCONT does not work with sleep and why does fg work. By the way, I run these tests on my Ubuntu 13.10 x86-64 pc. Thanks in advance.

Upvotes: 2

Views: 6238

Answers (1)

Ralf
Ralf

Reputation: 21

How do you know that sending SIGCONT doesn't wake up the sleep process? What do you expect to happen? The fg command wakes up the process and brings it to the foreground (hence fg). The bg command wakes up the process and brings it to the background (hence bg).

In implementation details, the shell uses wait on a process in the foreground, while it doesn't use wait on processes in the background.

So after SIGCONT your sleep probably continues to run in the background. You could wait for 100 seconds after sending SIGCONT, then the sleep command should have terminated and you should get a notification (immediately or after pressing return, depending on the configuration of your shell).

Upvotes: 2

Related Questions