Sending SIGSTOP to a child process stops all execution. C
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.
Related videos on Youtube
Comments
-
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 over 6 yearsI've run across this kind of problem. Try to run
ps
and see if it really stopped (It should). I suspect you should addWUNTRACED
in yourwaitpid()
to detect the stopped children from your main process.
-
-
Braden over 13 yearsOk, 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 over 13 years@Braden: that's because you used
SIGSTOP
rather thanSIGKILL
or any other signal for that matter. that is the expected behaviour. -
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 over 13 yearsI was meaning that even the parent stopped executing after the signal was sent to the child.
-
Hasturkun over 13 years@Braden: Is it possible that
Child_PID
is0
from some reason (since that would send the signal to all processes in the current process group) or negative?