marque
marque

Reputation: 45

Resuming stopped process doesn't resume its children

I wrote a mock mini-shell program which could accept user commands just as a shell would. I am trying to replicate the functionality of stopping/resuming a process launched from within my mini-shell.

I was able to intercept and handle the SIGTSTP signal to stop a long-running process (w/o stopping my mini-shell) which simply echoes "Hi" every X seconds.

enter image description here

I was also able to resume the long-running process using kill(pid, SIGCONT); (in this case kill(2903651, SIGCONT) will be executed). Problem is, the sleep child process still remains in a stopped state and the "Hi" messages doesn't resume printing. Other processes which doesn't have a child process works just fine.

enter image description here

My question is, are there any ways to make the process of the given pid resume entirely, including its children?

Upvotes: 2

Views: 262

Answers (1)

sj95126
sj95126

Reputation: 6908

Assuming that the parent didn't change the process group of the children (and grandchildren), you should be able to use killpg() to signal the entire process group. By default, the process group will have the same value as the parent PID and will include all of PID's children.

In your example above, that would be:

killpg(2903651, SIGCONT);

For testing purposes, inside a shell, you can accomplish the same thing by specifying the parent PID as the process group, as a negative, e.g.

kill -CONT -2903651

Upvotes: 1

Related Questions