LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-13-2011, 08:50 AM   #16
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191

Well firstly I would probably suggest you look at pkill to replace your pgrep, sed, xargs line.

As for the extra output, it may be because it is not part of the pgid and hence throws an unrelated error??
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 07-13-2011, 09:09 AM   #17
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by acc_Wk View Post
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
 
Old 07-13-2011, 09:31 AM   #18
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by acc_Wk View Post
The portion in bold removes all messages except the one below:
Code:
/etc/opt/common.sh: line 241:  5633 Killed                  $cmd
      5634                       | tee -a $log_file
I suspect something to do with tee command is causing the problem.. Any idea?

Thanks a lot for all the help!!
This is job control output printed directly to the terminal.
Kevin Barry

Last edited by ta0kira; 07-13-2011 at 09:45 AM.
 
Old 07-14-2011, 06:54 AM   #19
ambrop7
Member
 
Registered: May 2011
Distribution: Gentoo
Posts: 98

Rep: Reputation: 16
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.
 
1 members found this post helpful.
Old 07-14-2011, 08:10 AM   #20
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939
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:

Actum Ne Agas: "do not do a thing already done."
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
killng parent process without killing child process (Linux C programming) lettuce84@naver.com Linux - Newbie 3 07-24-2015 08:37 AM
Sending Signal from Child Process to Parent Process : Not getting desired output thelink123 Linux - General 4 10-26-2012 09:05 PM
[SOLVED] Why does a child exit when the parent receives a signal? jmarcet Programming 4 03-16-2011 06:45 PM
memory leak: Parent killing child process wkhoo Programming 12 06-04-2008 05:39 PM
How to kill a Child and all its subsequent child process in C shayer009 Programming 3 12-04-2007 12:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration