Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!mintaka!bloom-beacon!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.wizards Subject: Re: How to find process name in c? Message-ID: <1990Jul16.013512.8056@athena.mit.edu> Date: 16 Jul 90 01:35:12 GMT References: <570001@carter.BCASDL.BOEING.COM> Sender: daemon@athena.mit.edu (Mr Background) Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Organization: Massachusetts Institute of Technology Lines: 22 In article <570001@carter.BCASDL.BOEING.COM>, lyn@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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8495 Home: 617-782-0710