Home > Blockchain >  Resuming stopped process doesn't resume its children
Resuming stopped process doesn't resume its children

Time:09-23

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?

CodePudding user response:

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
  • Related