cancel
Showing results for 
Search instead for 
Did you mean: 

query on process id

nav882
Advisor

query on process id

hi all,
assume tht i am running a process run.sh.My question is that how to run another script where it should get the pid of run.sh and kill it.
wht are the commands to get the pid alone of run.sh
3 REPLIES
Oviwan
Honored Contributor

Re: query on process id

Hey

#ps -ef | grep run.sh | grep -v grep | awk '{print $2}'

this returns the second field of the ps output. perhaps it's another field number.

Regards
Hemmetter
Esteemed Contributor

Re: query on process id

hi

$ UNIX95= ps -fC test.sh
and only the PID:
$ UNIX95= ps -C test.sh -o pid=

rgds
HGH
Stuart Browne
Honored Contributor

Re: query on process id

'pidof' is your friend:

kill -TERM `pidof run.sh`

It will return a space-separated list of PID's that match the process name you give. It usually lives as a symbolic link as '/sbin/pidof'.
One long-haired git at your service...