[SOLVED] making child process die on SIGKILL to parent
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi!
I am trying to ensure child processes exit when parent is killed. I have registered signal handler for all the "bad" signals to ensure clean exit, but I also want parent to kill children when it gets SIGKILL.
I have tried the following:
polling for getppid() == 1 on child, then exit
prctl(PR_SET_PDEATHSIG, SIGTERM);
setpgid() for child to join parent's process group, called in child process after fork() before exec()
Still, when I kill my parent process with -9, the child processes keep running.
I would appreciate any suggestions.
Thank you!
Olga
Last edited by olga_chotinun; 02-26-2015 at 05:38 PM.
PR_SET_PDEATHSIG (since Linux 2.1.57)
Set the parent process death signal of the calling process to arg2 (either a signal value in the range
1..maxsig, or 0 to clear). This is the signal that the calling process will get when its parent dies.
This value is cleared for the child of a fork(2) and (since Linux 2.4.36 / 2.6.23) when executing a
set-user-ID or set-group-ID binary. This value is preserved across execve(2).
PR_GET_PDEATHSIG (since Linux 2.3.15)
Return the current value of the parent process death signal, in the location pointed to by (int *)
arg2.
from what the man page says arg2 to prctl's PR_GET_PDEATHSIG is a pointer to that (childs, in this case) memory
so you would have to periodically check if the value of that int changed
something like (never tried)
int asd = 0;
prctl(PR_GET_PDEATHSIG, &asd);
then check every once in a while if that int holds a SIG (non-null) value
PS thank YOU, didn't know about this call and it seems like fun
Thanks! I am very frustrated because I think PR_SET_PDEATHSIG() alone should have worked for me when I call it on the child! I will try polling and report here on my success/failure
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.