It is very common to require a proccess listing… I dont believe there is a portable way to do this. (glib seems to try to address this problem but it goes the hard way). Probably the most portable way to get a process list is to parse the output of the `ps’ program.
libproclist will run ps with the apropriate arguments and parse its output to get the process listing.
It seems to work for: Linux, IRIX, Solaris, AIX and OpenBSD.
This will *NOT* work for FreeBSD since the ps command does *NOT* return the effective uid and gid of a process.
Usage
The installation is as simple as `configure’, `make’ and `make install’.
The interface of the library is:
struct pl_procinfo
{
pid_t pid;
pid_t ppid;
uid_t euid;
gid_t egid;
char *tty;
char *cmd;
};
struct pl_procinfo **pl_proclist;
int pl_proclist_count;
/*
Get the process list.
Return:
-1: Internal error
0: Error executing ps
>0: Number of processes
*/
int pl_get_proclist();
Just call pl_get_proclist() and it will allocate the pl_proclist table which will contain pl_proclist_count elements. Each element is a process.
Downloads
License
libproclist is licensed under the GPLv2