CTRL+C is not killing my program
I have a program which fork
s a child.
I am trying to catch following signals: SIGINT
, SIGPIPE
and SIGTERM
.
On Ctrl+c (which generates SIGINT - afaik) I want to make sure I kill the child process before main program terminates which I am doing in my signal handler.
Now my expectation/understanding is that parent process will be automatically be killed on Ctrl+c. But that is not happening.
On Ctrl+c I get the shell prompt back but I can still see m开发者_运维技巧y process in ps
. So basically my main program is not getting killed.
Is my understanding wrong?
Edit 0: One observation: Before Ctrl+c, in ps
main program status says S
but after Ctrl+c its I
.
It gets killed after the signal handler code finishes running, in your case it won't actually die until the code you placed in the handler code for SIGINT executes (which should close the child process if you wrote it correctly).
It seems that maybe your handler code is doing something incorrectly that is not letting the process exit, please post your handler code and how you setup your handler as it is possible to do a SIGIGN (ignore) on SIGINT so that CTRL+C effectively does nothing to your program.
Make sure you call exit(0) or exit(1) or with an error code to tell the process to terminate if not the process will not exit.
精彩评论