Operating System - HP-UX
1825705 Members
3266 Online
109686 Solutions
New Discussion

how to get ps -ef to grep the PID of a process

 
SOLVED
Go to solution
twtandigi.com.my
Frequent Advisor

how to get ps -ef to grep the PID of a process

hi Guru-s,

Currently i have crontab running, but it seems to not to be able to get the /usr/sbin/named to start.
i have tried to tie it down with the ps -ef | grep named but nothing seems to work.
i have heard that this can be tied with the pid of the process. but i am not sure how to get it to work. have anyone tried it out and how should i code it in the HP-UX 11.

confused...
3 REPLIES 3
Bill Hassell
Honored Contributor

Re: how to get ps -ef to grep the PID of a process

Don't use grep! The man page for ps has exactly what you need. This will give you the pid for named:

NAMEDPID=$(UNIX95=1 ps -C named -o pid tail -1)

If $NAMEDPID has just PID, then named is not running. Otherwise, NAMEDPID has the named process ID.

However, this is way too complicated to locate named since it maintains it's own file with it's pid: /var/run/named.pid (man named)



Bill Hassell, sysadmin
Bill Hassell
Honored Contributor

Re: how to get ps -ef to grep the PID of a process

Oops, the pipe symbol got dropped. Here's the command line again:

NAMEDPID=$(UNIX95=1 ps -C named -o pid | tail -1)

Just a bit explanation. UNIX95 enables special (XPG4) behavior. The -C option is a process name finder and never uses grep. It is an exact match so -C sh will not find ksh (unlike grep). The -o option allows you to customize the ps columns you'd like to see.

Still other options in ps that are often overlooked:

-p
-f
-H (shows process hierarchy-requires UNIX95)


Bill Hassell, sysadmin
Joseph Loo
Honored Contributor
Solution

Re: how to get ps -ef to grep the PID of a process

hi,

as mentioned in earlier post, if named server is not running or configure to run, i.e. NAMED=1, you will not be able to "grep" named.

regards.
what you do not see does not mean you should not believe