First, you can't get the process id of a process that's complete, as it goes away.
Second, ps is a command that given the right flags returns more than just a single number - it returns a lot of data. You have to parse it to get the specific numbers you want.
Try running "ps" from your command line, and depending on your flavor of unix, "ps -ef" or "ps -aux" for more output.
Thanks for the tip.I am running c shell and in that i am getting the pid in a varible x thru the below statements
foreach x (`ps -o ppid | cut -c2-8`)
inside this loop i want to skip the first word of the string that x has i.e PPID is not i want as i want to kill the processes..Please let me know how to do this.
end
will obtain a list of all your child processes. don't forget the parentahsis in case it returns more than 1 value.
My CSH KILLJOBS script goes like this. I let the user ( me ) Pass in a string to search processes for to kill.
I am a little paranoid about killing more than one job in any run of the script. I guess I could use ps -ef but I would have to count the column ( or maybe 2-8 is correct ).
if ( $#PIDS == 0 ) then
echo "No Processes selected to kill"
exit 5
endif
if ( $#PIDS > 1 ) then
echo "More than one process selected"
echo "Are you sure you want to kill these $#PIDS tasks?"
set a = $<
if ( "$a" != "YES#" ) then
echo "$0 aborted without killing jobs"
exit 5
endif
endif
prouve you readed once again 'man ps' and realized:
ps -ef|grep something|grep -v grep|awk OR cut OR sed'
was perfectly correct ... 10 years ago.
(sys5) ps has better options:
NOTA: interprete ' as a back quote and Q as a space
#!/bin/sh
WHAT_YOU_WANT=xxx
WHAT_YOU_GET='/bin/ps -efocomm,pid|sed -en "s/.*$WHAT_YOU_WANT.*Q//p"'
[ x$WHAT_YOU_GET = x ] && echo $WHAT_YOU_WANT not found && exit 1
kill 0 $WHAT_YOU_GET || exit 1
kill -9 $WHAT_YOU_GET
exit 0 -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.