Unix Script -- To Skip killing a specific process

Hi,

By using

ps -aux | awk '/mine/{split($15,a,"/");print $1,$2,a[length(a)]}'

i get the below listed PID's with there corresponding processes.

adm 1522 ABC_Process.tra
adm 1939 GENE_Process.tra
adm 2729 GENE_Archive.tra
adm 3259 xyz_Process.tra

I use

ps -aux | awk '/mine/{split($15,a,"/");print $1,$2,a[length(a)]}' | while read a PID b; do kill -9 $PID; done

to kill the process gracefully.

But from the listed processes i do not want "GENE" processes to be killed, and the rest should be.

Is there a way to perform it in the unix script and print me the output of the same, in which GENE process should not be touched.

Expecting output like :

1522 ABC_Process.tra  is killed gracefully
3259  XYZ_Process.tra is killed gracefully

Any alternative ways are most welcome

--- Murali.

What do you mean GENE processes?

Where do the words "is killed gracefully" in your expected output come from? There's nothing graceful about "kill -9".

Since you have already concocted a somewhat overly-complicated command (which I'm sure someone will take the time to simplify), you could simply add a grep -v GENE before the while

ps -aux | awk ... | grep -v GENE_ | while ...

kill -9 kills a process abruptly
to cleanly kill a process kill -15 is used.

the difference between the two is,
kill -9 murders the process [doesn't care if it has any unfinished job], whereas
kill -15 requests the process to die hence, the process can finish it's unfinished jobs and die peacefulle [RIP :D]

you can google more about kill signals

Or you could just read the manual page: signal(3) :slight_smile:

We seem to have overlooked that this is posted in the Homework Forum. Please, in future, follow the guidelines for posting here. Thanks.