Sending SIGSTOP to a child process stops all execution. C

12,141

Solution 1

POSIX says:

The system shall not allow a process to catch the signals SIGKILL and SIGSTOP.

So, the child has no option but to stop - if the signal is sent successfully. And you cannot set a SIGSTOP handler in the child (or parent, or any other) process.

Solution 2

That's the expected behaviour. Quoting from the unix man page:

The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.

And the BSD man page mentions that:

The signal() function will fail and no action will take place if one of the following occur:

[EINVAL]           The sig argument is not a valid signal number.
[EINVAL]           An attempt is made to ignore or supply a handler
                   for SIGKILL or SIGSTOP.

Concluding, you're not permitted to install a handler for SIGSTOP. And the process will remain in the suspended state until it receives a SIGCONT.

Solution 3

This is the expected behavior.

Use strace your_program to see what's happening.

Share:
12,141

Related videos on Youtube

Braden
Author by

Braden

0x4532071F6b7E7212d766Ae1b80F0eC5684eAAbA1

Updated on June 04, 2022

Comments

  • Braden
    Braden almost 2 years

    When I call kill(Child_PID, SIGSTOP); from the parent, I expect the child to halt execution and the parent to continue. Is that the expected behavior or do I have to explicitly declare the SIGSTOP handler in the child? I have searched everywhere and not been able to find this information.

    Thanks. Braden

    • Emil Terman
      Emil Terman over 6 years
      I've run across this kind of problem. Try to run ps and see if it really stopped (It should). I suspect you should add WUNTRACED in your waitpid() to detect the stopped children from your main process.
  • Braden
    Braden over 13 years
    Ok, I have run strace on my program and watched the children as well, and as soon as the call to kill is made, all execution stops, it doesnt exit, but just stops.
  • Hasturkun
    Hasturkun over 13 years
    @Braden: that's because you used SIGSTOP rather than SIGKILL or any other signal for that matter. that is the expected behaviour.
  • Jonathan Leffler
    Jonathan Leffler over 13 years
    @Braden: what else did you expect? SIGSTOP says "stop executing; go into suspended animation until further notice", where 'further notice' is a SIGCONT signal (or possibly a SIGKILL signal).
  • Braden
    Braden over 13 years
    I was meaning that even the parent stopped executing after the signal was sent to the child.
  • Hasturkun
    Hasturkun over 13 years
    @Braden: Is it possible that Child_PID is 0 from some reason (since that would send the signal to all processes in the current process group) or negative?