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 
while read x pid name; do [[ $name =~ "Genesis" ]] && continue || kill $pid; done < inputfile

OR

grep -v 'Genesis' inputfile | cut -d" " -f2 | xargs kill

Hi Bala,

Can you please explain me what the above scripts are doing. I'm new to unix just want bit explaination to understand.

Hi Murali,

Scripts are killing all the processes mentioned in the text file except the Genesis processes.
Scripts are written assuming you have the list of processes to be killed in a file.

The first script reads the inputfile ( containtig list of processes to be killed) line by line , if it finds third column to be Genesis then it moves to next line, otherwise it kills the process.

In the second script, grep -v is used to search all the lines which do not contain "Genesis" , cut is used to extract its pids. and then the processes are killed

1 Like

Aashish,

Thanks alot for explaining the scripts.
The above scripts is used to exclude one Process from killing.
What if i want to exclude couple of more process say -- " murali" and "hippo" from being killed

this will exclude the first and second from the file..
You can add how many you want to add just insert '|' between them...

grep -v -E "first|second"
1 Like