Unix Script -- To Skip killing a specific process

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Unix Script -- To Skip killing a specific process
# 1  
Old 07-16-2012
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:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 07-16-2012 at 05:59 AM.. Reason: code tags, see PM
# 2  
Old 07-16-2012
What do you mean GENE processes?
# 3  
Old 07-16-2012
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
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 Smilie]

you can google more about kill signals
# 5  
Old 07-18-2012
Or you could just read the manual page: signal(3) Smilie
# 6  
Old 07-18-2012
We seem to have overlooked that this is posted in the Homework Forum. Please, in future, follow the guidelines for posting here. Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automated Script for Process killing

Hello all, I'm in need of a Script which needs to wait for all the child process to end and then kill the main process. I have a process called mainpp which runs for different instances like evpn, nge, gmn etc so when i query for mainpp process it looks like below. bash-3.2$ ps -eaf |... (6 Replies)
Discussion started by: Mahesh_RPM
6 Replies

2. UNIX and Linux Applications

Unix pkill error; does wily obstruct me killing the process?

have two scripts on Unix; one that starts some processes and the other one for killing a process. At first, I ran the .sh without WILY in it and it worked perfectly; in this way, I could also ran my stopper process. However I need WILY in this so I added it to my script but this time, a message... (1 Reply)
Discussion started by: nerdogan551
1 Replies

3. Shell Programming and Scripting

**need help for killing a process through script**

Hello All, i hope you are fine. I need a little help from you people-- inside a script i want to kill a parent process by checking it with the child process.. p_pid=`ps -e | awk '/ra_cmd_d/ {print$1}'` here i am selecting the child process id in p_pid. next-- sleep_pid=`ps -af |... (3 Replies)
Discussion started by: onlyniladri
3 Replies

4. 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

5. Shell Programming and Scripting

Killing a process within 5 min it starts in Unix using perl

Hi All, I have to kill a program whose pid, i will be getting. Multiple processes will be getting started by my script of same kind in a series. So for after each call to a process i need to write a command or script which can kill the process if it takes more than 5min. In this i will... (3 Replies)
Discussion started by: nishank.jain
3 Replies

6. 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

7. 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

8. Shell Programming and Scripting

While killing the process, Script gets hanged. Please help me on this.

Hi Everyone, I have written a script to automate the docbase cleanup process on every weekly basis. That is in this script i have to shutdown the docbase and then kill all the process that are hanged except one process(epic process) and need to delete some log files and then i have to start the... (8 Replies)
Discussion started by: Sheethal
8 Replies

9. AIX

killing a process from a script

Hey all. I'm brand new to this forum and am looking for some help. I have a script that verifies that the backup tapes are working correctly. Basically is uses 1 command: restore -xpqvf > rootvglog I use this for each volume group that we have. We run this everyday but the problem is, we... (4 Replies)
Discussion started by: jalge2
4 Replies

10. Shell Programming and Scripting

killing process using a script

can I do ps -ef | grep <process_name> and kill the process is it exists? and send a mail to me that the process was found and killed Thanks much... KS (4 Replies)
Discussion started by: skotapal
4 Replies
Login or Register to Ask a Question