ps command

Hi
ca any one give clear idea on the below command
let say
PROG=invexe ( invexe is a process )
ps -ef | grep $PROG | grep -v grep|awk -F"|" '{print $9}'

By using the above command I tried to find out the above process name it give some unexpected result. What I believe that when we enter "ps -ef" command we get the values like ...

UID PID PPID C STIME TTY TIME CMD
root 0 0 0 Apr 06 ? 4:11 sched
root 1 0 0 Apr 06 ? 41:47 /etc/init -r
root 2 0 0 Apr 06 ? 1:28 pageout
root 3 0 2 Apr 06 ? 2369:19 fsflush

Ideally $8 should give the process name, but I found the process name by giving $9. So I am confuse, plz anyone make clear on it.

Is there any other way to find out the process name in unix using command?

What with the -F"|" in the awk statement.

Try this.

ps -xo pid,comm | grep $PROG | grep -v grep|awk '{print $2}'

Or better yet

ps -xo comm | grep $PROG | grep -v grep

If you know PROG will always be invexe then you can do this as well

ps -xo pid,comm | grep 'nvexe'

What I believe that there is no such option "x" for ps command. So plz resend it again.

If it is, then make it ps -efo. Read the man pages of ps for the available output formats.

dear frnd
for example say
root 0 0 0 Apr 06 ? 4:11 sched
in the above example the delimiter is "blank space", so there is no point in using awk -F, when the delimiter or the space between two fields is other than blank space, say it is "|", then we have to give as awk -F"|"

as u said when using $9, ur getting the process name.... see exactly it is the 9th field only
root 0 0 0 Apr 06 ? 4:11 sched
1 2 3 4 5 6 7 8 9 field names in awk

   i hope u get clarified, if not plz reply
                                               -  manikumar

hello,

I agree with manikumar you have to take " " as delimeter or you can change the delimeter by "|" and use the following command

ps -ef | grep $PROG | grep -v grep|tr -s " " "|" |cut -d"|" -f8-

or
ps -ef | grep $PROG | grep -v grep|awk -F" " '{print $8}'

as awk will take unnecessary more time to execute

thks