Getting process info in a program

Hi,
I am wondering if there is a way to find out in a C software program if a particular process is running without having to write a file. In the past, I have been using the system command to execute a pgrep and output the info to a file. Then the C program reads the file to make the determination, and the file is deleted.

I have a request from my customer to find out this same info in the C program without writing a file. HP-UX has a pstat_getproc utility that would work, but this is not supported in most Unix variants. Is there some other way for a software program to detect if another process is running?

Thanks,
Herb Miller

Most flavors of UNIX support process accounting on some level, but each of them implement it a little differently. Both AIX and Solaris have process structs available in the /usr/include/sys/proc.h files. You may have to do a bit of digging to find a method to give you back exactly what you want, but that's a place to start.

The only exception to this is Linux, which doesn't have the process accounting libraries that most of the other UNIXs have. Process accounting in Linux is done through the /proc filesystem, which are nominally a set of files updated with the necessary process info in real time. If you're looking to accomplish this on Linux, you'll need to do some digging to find out what's relevant. Of course, if you're just looking for basic info, you can have your program run the 'ps' command and parse the output.

Hope that helps.