1844559 Members
3534 Online
110233 Solutions
New Discussion

PID to find a process ?

 
SOLVED
Go to solution
Sammy_2
Super Advisor

PID to find a process ?

Hi All,
How would I find a process name if I know the PID ? Also, How can I find if a PID has any children or (if it is a child) if which process is the parent.

Thanks Unix Admins
good judgement comes from experience and experience comes from bad judgement.
5 REPLIES 5
Jeff Schussele
Honored Contributor
Solution

Re: PID to find a process ?

Hi Ribus,

Do the following
#ps -ef | grep xxxx
where xxxx is the PID. Should list that process as well as any process it's the parent of.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
A. Clay Stephenson
Acclaimed Contributor

Re: PID to find a process ?

Since all processes (except init) have a parent they are by definition child processes.

To find the data you are looking for, do this:
ps -p PID -l.

Man ps for more options and details.
If it ain't broke, I can fix that.
Sandip Ghosh
Honored Contributor

Re: PID to find a process ?

do ps -ef|grep
then do ps -fu

Sandip
Good Luck!!!
James R. Ferguson
Acclaimed Contributor

Re: PID to find a process ?

Hi:

# ps -ef|awk '$2==X||$3==X {print $0}' X=

...will give you process name of the , and whether this pid is a parent ($2) or a child ($3).

Regards!

...JRF...
Bill Hassell
Honored Contributor

Re: PID to find a process ?

REALLY IMPORTANT: ps and grep will make *lots* of mistakes. Unix 101 classes seem to always tell new students to use:

ps -ef | grep something

but there are BIG problems with this. Suppose you want to find a process with a PID=123 and you use:

ps -ef | grep 123

and you'll get the process, plus any child processes where 123 is the parent, and also PID numbers like: 1234 11234 and you'll also get processes that happen to have 123 in their command line line (like grep 123)

So avoid like the plague the temptation to use grep. Instead, ask ps to get you the exact process name given a PID:

ps -fp PID

Never fails (unless the process is gone).

You need to search by process name? How about finding all sh processes? grep will fail misearably:

ps -ef | grep sh

Let's ask ps to search for exact process name matches:

UNIX95= ps -f -C sh

Notice: no ksh or csh or any other strings.



Bill Hassell, sysadmin