[SOLVED] Killing subsequent child process upon parent receiving a signal
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.
Thanks for this tip!! Indeed this is a much better way to kill all my processes by way of group id.. But can you please elaborate on what exaclty "jobs -x kill %%" does ?
As for the disadvantages of using kill -9, I agree, but in my case, I dont want to do any clean up in processes B&C (which i'm SIGKILLing) and dont have a handler for them.. So if I reach the handler of A immediately after a signal arrival, I would like to kill it's children and do clean up pertaining to A...
You can get more information with help jobs. The jobs built-in operates on background jobs, and -x executes a command with the pid substituted for %%. It's similar to -exec with find.
I think you misunderstand the scope of exit handlers. When you SIGKILL a shell script you deny the shell its proper exit procedures. Even though your script doesn't need cleanup, you don't know what bash needs to do to exit gracefully.
Kevin Barry
Last edited by ta0kira; 07-13-2011 at 09:43 AM.
Reason: wording
I highly recommend that you use a programming language other than Bash for that. Shell scripts are terrible for event-driven programming (which this is - waiting for events (signals, child terminated) and responding to events).
I've developed a comprehensive framework for event-driven programming in C, focused on networking, as part of my open-source BadVPN project. It supports management of child processes. I even have a nice example.
Following-on to ambrop7's post ... always look first for "prior art." Choose a "real" programming language ... I have become quite fond of Perl (specifically because of its vast CPAN library), but you have a half-dozen or more to choose from. Then, look for an existing framework that you can simply grab off the shelf and use. While programming is (sometimes) great fun, remember this rune:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.