Something like this works with most unix'es and Linux that have /proc:
Code:
DIR *procfs;
struct dirent *entry;
procfs = opendir("/proc");
while ( entry = readdir(procfs) ) {
if (!isdigit(entry->d_name[0])) continue;
/* process id is in d_name. Open the file /proc/d_name/stat */
}