Go Back   The UNIX and Linux Forums > Homework and Emergencies > Homework & Coursework Questions


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-16-2012
Registered User
 
Join Date: Jul 2012
Posts: 12
Thanks: 4
Thanked 0 Times in 0 Posts
Unix Script -- To Skip killing a specific process

Hi,

By using

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

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


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

I use

Code:
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 :

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

Any alternative ways are most welcome

--- Murali.


Moderator's Comments:
Please use code tags next time for your code and data.

Last edited by zaxxon; 07-16-2012 at 04:59 AM.. Reason: code tags, see PM
Sponsored Links
    #2  
Old 07-16-2012
Registered User
 
Join Date: Feb 2010
Posts: 347
Thanks: 23
Thanked 8 Times in 8 Posts
What do you mean GENE processes?
Sponsored Links
    #3  
Old 07-16-2012
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Location: Zürich
Posts: 6,966
Thanks: 220
Thanked 762 Times in 666 Posts
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


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

    #4  
Old 07-18-2012
Registered User
 
Join Date: Jul 2011
Location: Pune, India
Posts: 54
Thanks: 9
Thanked 6 Times in 6 Posts
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 ]

you can google more about kill signals
Sponsored Links
    #5  
Old 07-18-2012
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Location: Zürich
Posts: 6,966
Thanks: 220
Thanked 762 Times in 666 Posts
Or you could just read the manual page: signal(3)
Sponsored Links
    #6  
Old 07-18-2012
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Location: Zürich
Posts: 6,966
Thanks: 220
Thanked 762 Times in 666 Posts
We seem to have overlooked that this is posted in the Homework Forum. Please, in future, follow the guidelines for posting here. Thanks.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Finding the age of a unix process, killing old processes, killing zombie processes sukerman Shell Programming and Scripting 0 04-14-2010 04:48 AM
Killing a process within 5 min it starts in Unix using perl nishank.jain Shell Programming and Scripting 3 01-15-2010 04:14 AM
Killing specific process benefactr Shell Programming and Scripting 6 10-25-2007 12:23 PM
killing a unix job after the job process gets completed dtazv Solaris 7 09-28-2005 07:18 AM
killing unix job after the job process completes dtazv Shell Programming and Scripting 1 07-22-2005 06:44 AM



All times are GMT -4. The time now is 02:04 AM.