How to find process name in c?

Conor P. Cahill cpcahil at virtech.uucp
Sun Jul 15 11:59:57 AEST 1990


In article <200001 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.


An easy way to see if a particular executable is running is to try
to open the file with write permissions.  If you get the errno ETXTBSY,
the executable is being run.

If you don't know the full pathname to the executable, or if you need
additional information (other than the fact that the program is running, like
who is running it or how much cpu it is using, etc) you need to run 
ps and parse the output (or replicate the ps code in your program).

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 



More information about the Comp.unix.questions mailing list