Killing all the process of a particular enviroment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Killing all the process of a particular enviroment
# 1  
Old 03-02-2014
Wrench Killing all the process of a particular enviroment

Hi Folks,

I have the below command that will kill all the process of an environment,
lets say if I have reached to the location cont directory under which I want to kill multiple process so the command will be ....
Code:
kill -9 `ps -ef | grep cont | grep -v grep | awk '{print $2}'`

Now please advise is there any better alternative of the above command that is more efficient .Smilie

Second thing is that I want to kill the multiple process in such an order such that once which started first shoulbe get killed as it is in ascending order and should show in console also while doing., please advise.Smilie
# 2  
Old 03-02-2014
Code:
kill -9 `ps -ef | awk '/cont/ {print $2}'`

If you want to kill the processes in sorted order, you might want to you sort between ps and awk command
# 3  
Old 03-02-2014
Code:
kill -9 `ps -ef | awk '/[c]ont/ {print $2}'`

The [ ] trick prevents a match of the own process (i.e. awk's argument)
Another method
Code:
pkill -f cont

A normal kill is normally better.
With a ps -ef output we perhaps could suggest a more precise match.

Last edited by MadeInGermany; 03-02-2014 at 05:38 PM..
# 4  
Old 03-02-2014
Quote:
Originally Posted by MadeInGermany
Code:
kill -9 `ps -ef | awk '/[c]ont/ {print $2}'`

The [ ] trick prevents a match of the own process (i.e. awk's argument)
.
Can you please explain in detail about the meaning that ...The [ ] trick prevents a match of the own process, i haven't grasp that..!Thanks
# 5  
Old 03-03-2014
Quote:
Originally Posted by punpun66
Can you please explain in detail about the meaning that ...The [ ] trick prevents a match of the own process, i haven't grasp that..!Thanks
The two regular expressions cont and [c]ont are equivalent and will result in the same set of lines being selected. The difference is that the 2nd version will not match it's self so even thought awk '/[c]ont/...' appears in the ps listing it will not be matched.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Killing the process ID's

Hi , I have a list of application process id's. Is there a way to kill all the process listed below using the script, except the once which are starting with " Genesis " adm 1522 ABC_Process.tra adm 1939 Genesis_Process.tra adm 2729 Genesis_Archive.tra adm 3259 xyz_Process.tra (5 Replies)
Discussion started by: murali1687
5 Replies

2. UNIX for Dummies Questions & Answers

Killing the shell Process

I was just playing with the processes and suddenly a question striked my mind: What will happen if we kill directly the shell process?? :rolleyes: Do anyone know? Will the system shutdown? Or the system wont let it be killed? (5 Replies)
Discussion started by: paras.oriental
5 Replies

3. Shell Programming and Scripting

Finding the age of a unix process, killing old processes, killing zombie processes

I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time. Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
Discussion started by: sukerman
0 Replies

4. Shell Programming and Scripting

script not killing process!

i am using script to connect remotly to server and run some commands , one of these commands is to kill some process but tried different ways with no hope sshpass -p 'pass' ssh -o StrictHostKeyChecking=no server kill -9 `pgrep procs` getting error message "kill: bad argument count" ... (2 Replies)
Discussion started by: mogabr
2 Replies

5. Shell Programming and Scripting

Killing process!!!!

Hi friends, i m in big trouble.... i have one script which connects two server ...like below.. script1.sh ------------------------------------- bash test.sh & eval x=$@ export x=`echo $x` #echo $x # ssh user@8.2.5.6 bash /mbbv/location/script.sh $x|sed '/Binary file/d'... (1 Reply)
Discussion started by: Shahul
1 Replies

6. UNIX for Dummies Questions & Answers

killing the process

Hi, First, I am running a scipt.While the script is running I realize that I dont want the script to be run so I am killing the script externally.Before the process gets terminated or killed it should delete all the temporary files created by the script.How to do this?Can anyone help me? ... (3 Replies)
Discussion started by: arthi
3 Replies

7. Shell Programming and Scripting

Killing of a process and send a mail if the process doesnot come up within 2 minutes

Hi Friends, I am new to this forum as well as new to shell scripting. I have a problem here and i need someone to solve this. Let us consider there are two processes(abc & def).There is a script which kills these two processes(i.e killtheprocess abc). Here abc is the argument . There is a... (1 Reply)
Discussion started by: Prince89
1 Replies

8. Shell Programming and Scripting

Killing specific process

Hello, I need to create a process that will kill a specific process if it's running. Let's just say the process is called win, actually called something else. It could be running multiple times on the machine and I would want to kill them all. Below is the code I have written so far, and it... (6 Replies)
Discussion started by: benefactr
6 Replies

9. UNIX for Dummies Questions & Answers

killing a process

I can kill running processes on my linux red hat system using ctrl-c but cannot do it from command line of another terminal using kill -2 pid. Although I can kill them from command line using kill -9 pid and other signals. I would like to do it using the kill -2 pid. Thanks for your suggestions (6 Replies)
Discussion started by: bbhayana
6 Replies

10. UNIX for Advanced & Expert Users

killing a process pid

What option is used with kill to cause the server to reread its config file. (16 Replies)
Discussion started by: jo calamine
16 Replies
Login or Register to Ask a Question