1845838 Members
3155 Online
110250 Solutions
New Discussion

ps command question

 
Doug High_1
Occasional Contributor

ps command question

I am on an HP-UX 11.11 box and wish to obtain the process id of a specific program (let's call it happy). Long ago, I thought I used to use a variation of the ps command such as:
ps -C happy

This doesn't seem to work on HP-UX 11.11. Does any one know how I could obtain the process id of the program (which I need to feed to a kill -9 command to shut down each instance of the "happy" program.

Thank you!!!
11 REPLIES 11
Pete Randall
Outstanding Contributor

Re: ps command question

ps -ef |grep happy

should do it.


Pete

Pete
Uday_S_Ankolekar
Honored Contributor

Re: ps command question

-C option I thing is for xpg4.

Try this..
UNIX95= ps -C happy

-USA..
Good Luck..
Uday_S_Ankolekar
Honored Contributor

Re: ps command question

think..not thing...!!Sorry.
Good Luck..
Doug High_1
Occasional Contributor

Re: ps command question

Hi. I tried the ps -C happy and I got an "illegal option" message.

I'm familiar with the ps -ef | grep happy but the only thing I need is the actual PID of happy (not the rest of the stuff) and I then want to pass the PID's of any occurence to happy to:

kill -9 PID1 PID2 PID3, etc.,etc,e tc.

(all within a script). Manually doing this is no problem....but I'd really like to pass the PID and only the PID's of happy to kill -9.

Thanks for the prompt responses!
Olav Baadsvik
Esteemed Contributor

Re: ps command question



Hello,

Try this script.

Olav
Dario_1
Trusted Contributor

Re: ps command question

Try this:

for i in `ps -ef | grep happy | grep -v grep | awk '{print $2}'`
do
kill -9 $i
done

DR
Pete Randall
Outstanding Contributor

Re: ps command question

Doug,

Then this should do it:

ps -ef | grep ' '$USERNAME' ' | grep -v "resetuser" | awk '{ print $1,$2 }'
> /tmp/reset.tmp
PROCESSES=`grep $USERNAME /tmp/reset.tmp | awk '{ print $2 }' | sort -n`
for PROC in $PROCESSES
do
echo "\tKilling process $PROC"
kill $PROC
done


Pete

Pete
Doug High_1
Occasional Contributor

Re: ps command question

Dario. That did the trick. Many thanks to you and to all who responded so promptly!
Pete Randall
Outstanding Contributor

Re: ps command question

Actually, that's going after all processes of a particular user. Change $USERID to $PROGRAM and set it to "happy".


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: ps command question

Hi Doug:

You merely forgot to set the XPG4 (UNIX95) option. For exmaple, to find the 'pid' of the 'syncer' daemon, di:

# UNIX95= ps -C syncer|awk 'NR>1 {print $1}'

Note that a space follows the UNIX95= and there is no semicolon before the 'ps'. That set's UNIX95 only for the command line.

In the avove, I skip the header returned from 'ps' and grab the pid (column-1) for the "syncer" daemon.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: ps command question

Hi (again) Doug:

Beware using a simple 'grep' to find the process you truly want! You will return lines that match "happy" when "happy" is a command (basename) *and* when "happy" happens to be an argument to some other command!

Therein lies the value of using XPG4 (UNIX95) extentions.

Regards!

...JRF...