eps@toaster.SFSU.EDU (Eric P. Scott) (03/04/91)
In 1.0/1.0a you could read the process table using TBL_PROCINFO; for example, here's a "mini-ps": #include <stdio.h> #include <sys/param.h> #include <sys/table.h> main() { register struct tbl_procinfo *pip; struct tbl_procinfo *pil; int npi; struct tbl_procinfo pi[256]; /* bad assumption! */ npi=table(TBL_PROCINFO, 0, (char *)pi, sizeof pi/sizeof pi[0], sizeof pi[0]); if (npi<=0) { fputs("No processes??\n", stderr); exit(1); } pip=pi; pil= &pi[npi]; fputs(" F UID PID PPID PGRP TTYD COMMAND\n", stdout); do if (pip->pi_status!=PI_EMPTY) { printf("%7x%5d%6u%6u%6u ", pip->pi_flag, pip->pi_uid, pip->pi_pid, pip->pi_ppid, pip->pi_pgrp); if (pip->pi_ttyd==-1) fputs(" ?", stdout); else printf("%3d,%3d", major(pip->pi_ttyd), minor(pip->pi_ttyd)); if (pip->pi_status!=PI_ACTIVE) fputs(" <defunct>", stdout); printf(" %.20s\n", pip->pi_comm); } while (++pip<pil); exit(0); } Which produces output like: F UID PID PPID PGRP TTYD COMMAND 3 0 0 0 0 ? kernel-task 1 0 1 0 0 ? init 1 0 2 0 2 ? mach_init 1 0 55 1 0 ? nmserver 1 0 48 1 0 ? syslogd etc. On 2.0 the table() call returns -1 with errno set to ESRCH. If I "cheat" and look at what was actually returned, I see: F UID PID PPID PGRP TTYD COMMAND 3 0 0 0 0 ? kernel idle 1 0 1 0 0 ? init 1 0 2 0 2 0, 0 mach_init 1 0 3 0 0 ? kern_loader and nothing else. Is this totally broken under 2.0, or is there an API change? (Yes, I know this is undocumented, but I'd rather not have to run set-gid kmem if I can avoid it.) -=EPS=-
eps@toaster.SFSU.EDU (Eric P. Scott) (03/09/91)
Well, no one else has answered this, so I guess I get to follow up to my own post. Apparently TBL_PROCINFO doesn't like empty process slots any more. Under 2.0, you can only request information on multiple processes if they have strictly consecutive pids. Ick. You basically have to do all the stuff in the sample code for processor_set_tasks(), then call unix_pid() on each task port, qsort() those, and do multiple table() calls. It gets even worse if you want it to work on a multiple-CPU machine. Yuck, phooey, bletch. -=EPS=-