Need a script to kill processes with PPID of 1


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a script to kill processes with PPID of 1
# 1  
Old 04-13-2005
Need a script to kill processes with PPID of 1

Hi,
I have been trying to come up with a script to run as a cron job to kill any processes that have PPID of 1. I have created a file that contains the PID and the PPID. How can I read this file and then execute a kill on any PID where PPID is 1. The file looks like this:

4904 1
4455 1
6561 6560
5678 1

I create the file using:
ps -ef|grep -v root|grep rp_h1|awk '{print $2 , $3}' > killog

Then I want to read the killog file and issue a kill -9 on each PID that has a PPID of 1. This seems like it should be simple, but I am not very good with script writing. Thanks in advance for your help!!!

Lori
# 2  
Old 04-13-2005
you could also do the code below but I wouldn't advise doing what you think you should be doing as more than a few system processes have PPID 1 (check "ps -ef | grep inetd") ...
Code:
kill -9 `ps -ef | awk '$3 == 1 {print $2}'`

however, you can restrict to non-root user processes ...
Code:
kill -9 `ps -ef | awk '$3 == 1 && !/root/ {print $2}'`


Last edited by Just Ice; 04-13-2005 at 12:13 PM.. Reason: clarification
# 3  
Old 04-13-2005
ummm...you are not going to be able to kill all processes with a PID of 1. Besides, why would you want to do that? See article here
# 4  
Old 04-13-2005
Yes, you are right about the killing of all processes with PPID of 1. My problem initially stems from my oracle application server report printing. Every day there are about 50 processes left hanging after the batch printing finishes

example:
oracle 5321 1 0 Apr 04 ? 0:00 lp -d rp_h1-batch2_lp

So what I really want is to specify that this type of process be cleaned up. Right now I have to manually do them every few days. I could match up the character string of rp_h1, which is what I do with my grep statement in my initial posting, that way I would not eleminate any processes uneccesarily.
That was why I was doing the grep and excluding root and specifying a character string then writing to a file. I'm going to mess around with Ice's suggestions and see what I can come up with. Thanks and further advice will be appreciated!!
# 5  
Old 04-13-2005
if you just needed rp_h1 ...
Code:
kill -9 `ps -ef | awk '$3 == 1 && /rp_h1/ {print $2}'`

# 6  
Old 04-13-2005
Worked like a charm!! Thank you Thank you Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

kill multiple processes by name

Want to kill multiple processes by name. for the example below, I want to kill all 'proxy-stagerd_copy' processes. I tried this but didn't work: >> ps -ef|grep proxy_copy root 991 986 0 14:45:34 ? 0:04 proxy-stagerd root 1003 991 0 14:45:49 ? 0:01... (2 Replies)
Discussion started by: catalinawinemxr
2 Replies

2. Shell Programming and Scripting

script to kill tail processes

my unix machine is currently shared by many teams, because of that lots of processess are running and bad part is taht when I do psu ...i can see all tail processes as well , meaning ppl who have viewed files with tail and have forgotten to close it. command prompt >> psu tail -n 0 -f... (2 Replies)
Discussion started by: mitsyjohn
2 Replies

3. Shell Programming and Scripting

need to kill a number of processes with name "XYZ" at a time using shell script

Hi, when i grep for the process "XYZ" , there will be some good number of processes with that name, i want to kill all the these processes at a time using shell script? Any help needed for this action. Thanks Regards, Anil (6 Replies)
Discussion started by: anilmanepu
6 Replies

4. Shell Programming and Scripting

Kill processes

for i in 'ps -f | grep textedit' do kill $i done I wrote this but it wont work. I am trying to find processes and kill them. Any help would be welcome. (1 Reply)
Discussion started by: hawaiifiver
1 Replies

5. UNIX for Dummies Questions & Answers

script to kill related processes

hi guys, can anyone help me out with the script to kill all the related process at once. i have something like below ps -fu UID PID PPID C STIME TTY TIME CMD xyz 17398 1 2 Dec30 ? 00:31:20 ./psa_mux -simulate -client_ports 22000 xyz 17399 1 2... (2 Replies)
Discussion started by: smithaph
2 Replies

6. Solaris

kill processes

how to kill the processes of aperticular user? because i have nearly 25000 process are there for perticular user. i need to kill. Please provide the information? Regards, Rajesh (3 Replies)
Discussion started by: pmrajesh21
3 Replies

7. Shell Programming and Scripting

kill all processes

i have a very short file that has in it a line for a find command. now, when i run this script and I kill the script later, using the ps -ef | grep scriptname. i noticed kill -9 kills the script itself but does not kill the internal find command that it gave birth to. say theres a file... (0 Replies)
Discussion started by: Terrible
0 Replies

8. UNIX for Dummies Questions & Answers

Script to kill rsh processes running for more than 10 mins

Hi Friends, I need to write a script to kill some processes running for more than 10 minutes. Can I get some pointers on that. Thanks for ur help in Advance. Thanks&Regards, Amit (3 Replies)
Discussion started by: amitsayshii
3 Replies

9. Shell Programming and Scripting

script to kill rsh processes running for more than 10 minutes

Hi Friends, I need to write a script to kill some processes running for more than 10 minutes. Can I get some pointers on that. Thanks for ur help in Advance. Thanks&Regards, Amit (1 Reply)
Discussion started by: amitsayshii
1 Replies

10. UNIX for Advanced & Expert Users

script to kill rsh processes running for more than 10 minutes

Hi Friends, I need to write a script to kill some processes running for more than 10 minutes. Can I get some pointers on that. Thanks for ur help in Advance. Thanks&Regards, Amit (1 Reply)
Discussion started by: amitsayshii
1 Replies
Login or Register to Ask a Question