I need to get some information (PID, UID, GID, process name) about running processes on Mac OSX. I tried proc_pidinfo
. For my own processes it works fine. However,
You can use :
int proc_listpids(uint32_t type, uint32_t typeinfo, void *buffer, int buffersize);
combinated to proc_pidinfo to get many others pids informations like :
#include
#include
#include
#include
#include
#include
#include
#include
void procpid(pid_t pid)
{ struct proc_bsdinfo proc;
int st = proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &proc, PROC_PIDTBSDINFO_SIZE);
printf("name: %s\n", proc.pbi_name);
}
void pidlist(void)
{ int bufsize = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0);
pid_t pids[2 * bufsize / sizeof(pid_t)];
bufsize = proc_listpids(PROC_ALL_PIDS, 0, pids, sizeof(pids));
size_t num_pids = bufsize / sizeof(pid_t);
int i = 0;
while (i < num_pids)
{ printf("pid[%d]::%d\n", i, pids[i]);
procpid(pids[i]);
printf("\n-------------------------------\n\n");
i += 1; }}
int main(void)
{ pidlist();
return(42); }