SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old September 24th, 2003, 04:36 PM
tsu tsu is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: In Waterloo, Canada
Posts: 7 tsu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Killing processes related to a job

Hi,
I have a perl script blah.pl that spawns a bunch of other processes,(it runs a bunch of other pl scripts which may do other things, including spawning more child processes) but once in a while I will like to clean the whole damn thing. Basically, do a fresh restart. I am thinking of writing a perl script to kill off all the processes, however I am not sure how to find out which process was actually spawned by the blah.pl I don't want to crash the system or piss off other people, by killing random processes. any suggestions?
also if you guys know where i can find sample script that will save me the trouble, please let me know. thanks a bunch

Reply With Quote
  #2  
Old September 29th, 2003, 10:52 AM
Kung Foo Master Kung Foo Master is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 68 Kung Foo Master User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
>any suggestions?
When you say spawn I'll assume that you're forking children and exec'ing new programs. Since fork returns the child PID, you can save it in a list and kill all of the processes in the list when you want a clean restart.

>also if you guys know where i can find sample script that will save me the trouble
Then you wouldn't have the fun of doing it yourself.

Reply With Quote
  #3  
Old September 30th, 2003, 01:29 PM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,296 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 5 m 42 sec
Reputation Power: 101
Send a message via ICQ to christo Send a message via Yahoo to christo
I think by 'spawning' he's referring to backticks, execs, syscalls, qx's.. whatever the favourite method is these days..

christo

Reply With Quote
  #4  
Old October 1st, 2003, 09:42 AM
tsu tsu is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: In Waterloo, Canada
Posts: 7 tsu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Basically i didn't write the perl scripts my script blah.pl runs, so I don't have access to the child PID, if the scripts do use fork. Also, what christo said is closer to the mark, I believe the scripts use syscalls.

Reply With Quote
  #5  
Old December 7th, 2003, 02:15 AM
jayakhanna jayakhanna is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: India
Posts: 61 jayakhanna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
I think you can try this out

While running your script just store the Process id of your script

export PID=`echo $$`

then after the script is over just grep for the process id of all the processes whose ParentId is equal to PID, and store it in an array. Then again search for the values of these store values in the parentId and store. This is a recursive process. And then you can kill all the processes.

I haven' t tried writing a script, may be that' s the easiest thing to do here
__________________
Regards
JK

Reply With Quote
  #6  
Old December 9th, 2003, 07:35 AM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
Use a shell with job control and then use the shell's kill command on the job.

A decent shell will place the job into a separate process group. And it will send a kill to the process group leader using a negative pid in the kill() system call. That will signal all group members simultaneously. Your kernel needs to support broadcast signals for this to work, but all modern kernels do.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Killing processes related to a job


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway