[comp.unix.wizards] pid from process name

blum@drutx.ATT.COM (Mark Blumhardt) (07/14/89)

I saw this very question about a month ago, but never saw an answer...

Given a process name, how can I find its process id?   It just isn't
obvious to me, other than a system call to grep thru the output of ps,
which I don't want to do.

Mark

tchrist@convex.UUCP (Tom Christiansen) (07/15/89)

In article <11723@drutx.ATT.COM> blum@drutx.ATT.COM (Mark Blumhardt) writes:
>Given a process name, how can I find its process id?   It just isn't
>obvious to me, other than a system call to grep thru the output of ps,
>which I don't want to do.

What is a "process name"?  You mean u.u_comm (basically *argv)?  That's 
hardy unique.  If you have control over the process you're interested in 
have it write its pid somewhere.  Otherwise you're going to have to 
do the 'ps|grep' thing unless you're up to a kernel dive, in which of 
course all things are possible but not all are expedient. :-)

--tom

wietse@wzv.win.tue.nl (Wietse Z. Venema) (07/16/89)

blum@drutx.ATT.COM (Mark Blumhardt) writes:

>Given a process name, how can I find its process id?   It just isn't
>obvious to me, other than a system call to grep thru the output of ps,
>which I don't want to do.

open("/dev/kmem","r") ... :-)