Unix Script -- Suggestions to list and kill PID's sequentially


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix Script -- Suggestions to list and kill PID's sequentially
# 8  
Old 07-03-2012
@murali, the greps with ... were not to be taken literally. The ... stands for the code in the curly brackets that was provided by others. You also missed a closing /
The square brackets are needed to keep awk from occasionally matching itself..
This User Gave Thanks to Scrutinizer For This Post:
# 9  
Old 07-03-2012
Hi,

Now I'm able to get the output as required and i can see all the tra files along with the PID's. Please help me to kill the PID's sequentially.
By Manual process when i kill the PID, the log of "ABC_Process.tra" says "Stopped"
How can i Kill each PID sequentially and get the message "Stopped" displayed by the script.

Code:
adm 1522 ABC_Process.tra
adm 1939 XYZ_Process.tra
adm 2729 EDB_Archive.tra


Last edited by Scott; 07-03-2012 at 12:34 PM.. Reason: Code tags
# 10  
Old 07-03-2012
Code:
$ ps -aux | awk '/mine/{split($15,a,"/");print $1,$2,a[length(a)]}' | while read a PID b; do kill -9 $PID; done

# 11  
Old 07-03-2012
Quote:
Originally Posted by itkamaraj
Code:
 ... kill -9 $PID ...

Just a heads up to the OP: that SIGKILL won't let your processes exit gracefully. Unless there's a good reason, better to use the default SIGTERM.

Regards,
Alister
# 12  
Old 07-03-2012
I agree with alister. To put it in other words, better use kill instead of kill -9
# 13  
Old 07-10-2012
Thank you All for your wonderful responses.
I was sick all these days hence was not able to respond.

One last thing i need to know. Hope you to help me on this.

==================================================

I tried killing one PID (27739) manually, the log file read "Terminating" when it killed the PID.

These process will RE-STARTED automatically and when it re-started the corresponding process the log file read "Started"

Can i kill these PID's seqentially using unix script and get the Message -- Terminated / Started, in my script output ?

adm 27739 ABC_Process.tra
adm 28765 XYZ_Process.tra
adm 29132 BCY_Archive.tra


Expecting Output like :
=======================

ProcessID Stopped for ABC_Process.tra
Terminated process ABC_Process.tra
Starting process ABC_Process.tra


Similary for the rest. Alternative solutions if any are most welcome.
======================================================

---------- Post updated at 03:56 PM ---------- Previous update was at 12:48 PM ----------

Raj,

Can you explain me the script you have given

ps -aux | awk '/mine/{split($15,a,"/");print $1,$2,a[length(a)]}'
I searched in forums did not get the concept behind, expect for split Syntax,
split(string,array,separator).


Please let me know how the script is working to get the preferred output


---------- Post updated at 03:59 PM ---------- Previous update was at 03:56 PM ----------

Quote:
Originally Posted by itkamaraj
Code:
$ ps -aux | awk '/mine/{split($15,a,"/");print $1,$2,a[length(a)]}'
adm 27739 ABC_Process.tra
adm 28765 XYZ_Process.tra
adm 29132 BCY_Archive.tra


Raj,

Can you explain me the script you have given


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

I searched in forums did not get the concept behind, expect for split Syntax,
split(string,array,separator).


Please let me know how the script is working to get the preferred output
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to report file size, pid and also kill the process

Hi All, Looking for a quick LINUX shell script which can continuously monitors the flle size, report the process which is creating a file greater than certain limit and also kill that process. Can someone please help me on this? (4 Replies)
Discussion started by: vasavimacherla
4 Replies

2. Shell Programming and Scripting

script to kill a pid giving error

Hi, I simply want to kill a running process using a script that read pid from a file and tries to kill it .Getting error as shown below code.. cat $HOME/BackupScript.ksh.run | head -1 | while read pid do ps -p $pid > /dev/null 2>&1 if ; then kill -9 $pid else echo "no running $pid... (5 Replies)
Discussion started by: dhirajdsharma
5 Replies

3. Shell Programming and Scripting

Kill a PID using script

Hi, I wrote a script to kill a process id. I am able to kill the PID only if I enter the root password in the middle of the execution because I did not run as root i.e after i run the script from the terminal, instead of killing directly, it is killing only after entering the pass when it... (12 Replies)
Discussion started by: rajkumarme_1
12 Replies

4. Shell Programming and Scripting

Kill a Script based on the pid and sleep

I would want to run a code for 1 min and if it doesnt succeed in 1 min..I would want to exit it..I am using the following code...But the script is not going into my code part.It is waiting for 60 secs and then getting killed. The code which is in the while loop actually takes less than 60 secs...... (6 Replies)
Discussion started by: infernalhell
6 Replies

5. UNIX for Dummies Questions & Answers

Run Processes Sequentially Using Process ID (PID)

Hi, I'm a newbie when it comes to using UNIX, and I'm hoping someone here can help me out. I have a set of processes that I want to run sequentially: process1.py process2.py process3.py I want to know I can run these sequentially using their process IDs (PIDs). Ideally, I want to... (2 Replies)
Discussion started by: shelata
2 Replies

6. Shell Programming and Scripting

grab PID of a process and kill it in a script

#!/bin/sh who echo "\r" echo Enter the terminal ID of the user in use: echo "\r" read TERM_ID echo "\r" ps -t $TERM_ID | grep sh echo "\r" echo Enter the process number to end: echo "\r" read PID echo "\r" kill -9 $PID What this code does is ultimately grab the PID of a users sh... (6 Replies)
Discussion started by: psytropic
6 Replies

7. UNIX for Advanced & Expert Users

KILL without PID

Hellow Experts i have one problem. i run one script in backgroun. and i want to kill that script with only script name..... so what's the solution.. for your info my script name is "testscript" n it contains "sleep 100" thanks.... (16 Replies)
Discussion started by: luckypower
16 Replies

8. Shell Programming and Scripting

KILL PID, intern should kill another PID.

Hi All, In my project i have two process runs in the back end. Once i start my project, and execute the command ps, i get below output: PID TTY TIME CMD 9086 pts/1 0:00 ksh 9241 pts/1 0:02 java 9240 pts/1 0:00 shell_script_bg java with 9241 PID is the main... (4 Replies)
Discussion started by: rkrgarlapati
4 Replies

9. Shell Programming and Scripting

pass pid to kill using script

Hi there, i wonder if anyone can help is there any way that i can write a script that will kill all current ftp processes, for example if ps -ef | grep ftp produces 3 active proceses, then I would like to somehow extract the PID for each one and pass that to kill -9 has anybody done this... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

10. UNIX for Dummies Questions & Answers

Script to kill all child process for a given PID

Is there any build in command in unix to kill all the child process for a given process ID ? If any one has script or command, please let me know. Thanks Sanjay (4 Replies)
Discussion started by: sanjay92
4 Replies
Login or Register to Ask a Question