views:

63

answers:

3

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

A: 

This is the expected behavior.

Use strace your_program to see what's happening.

Nicolas Viennot
+2  A: 

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.

Jonathan Leffler
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.
Braden
@Braden: that's because you used `SIGSTOP` rather than `SIGKILL` or any other signal for that matter. that is the expected behaviour.
Hasturkun
@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).
Jonathan Leffler
@Jonathan I was meaning that even the parent stopped executing after the signal was sent to the child.
Braden
@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?
Hasturkun
+2  A: 

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.

jweyrich