|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
>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. ![]() |
|
#3
|
||||
|
||||
|
I think by 'spawning' he's referring to backticks, execs, syscalls, qx's.. whatever the favourite method is these days..
christo
__________________
. Spiration channels: Free scripts, programming tutorials and articles Dotcut alerts: Online Press cuttings / news alerts Clearprop: UK microlight school, wiltshire Uk dating: UK safe dating with Topdates About Christo . . |
|
#4
|
|||
|
|||
|
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.
|
|
#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 |
|
#6
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Killing processes related to a job |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|