How to find process name in c?

Jonathan I. Kamens jik at athena.mit.edu
Mon Jul 16 11:35:12 AEST 1990


In article <570001 at carter.BCASDL.BOEING.COM>,
lyn at carter.BCASDL.BOEING.COM (     Lyn Stewart      ) writes:
|> Has anyone got a method for finding out if a process is running short of
|> "ps -ef | grep processname" in a pipe.  There must be a better way from
|> within a c program.

  The subject of your message says one thing, but the contents say
another.  Do you want to find the name of a process, or find out whether
or not a particular process ID is still running?

  If the former, than running ps inside a popen is probably the best way
to go about doing it.  If the latter, then you can use the kill()
function and send signal 0 to the process whose status you want to
discover.  If the process exists and is owned by you (or you are root),
the kill() will return without error.  If it exists and is owned by
someone else and you are not root, it will return with EPERM.  If it
does not exist, it will return with ESRCH.

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710



More information about the Comp.unix.wizards mailing list