[comp.unix.wizards] C version of ps: From whence doeth the info cometh?

angst%csilvax@hub.ucsb.edu (Dave Stein) (12/12/87)

In article <150@coplex.UUCP>, jim@coplex.UUCP (Jim Sewell) writes...

>I would like to write a program allowing a system administrator to watch what
>his people are doing on his machine in real time.  It would be a full screen,
>self updating ps of sorts, with updates being made when either:
>       1. A new process pops up
>or	2. A process changes what it is doing

>My question is "Where does UN*X store the information ps makes available, and 
>how do I access it?"  I am working with System V Plexus and IBM AT (Microport)

I don't think it's available on Sys V, but there is a program called "top"
which is similar to what you want.  I've used it on Sun 3.X, and on some
Berkeley machines.  If you could get source for it, it would be very helpful.

As for where ps gets its information, it reads /dev/kmem (kernel memory),
/dev/mem (physical memory), and /dev/swap (swap device).  I used to work
at a place where my job was porting kernel utilities like ps, vmstat, and
top, and I've rewritten ps more than once.  If you are no familiar with it,
I would *greatly* suggest you get a copy of the source and study it closely.
It is not trivial.  You need to be familiar with the process table (the
large array of processes that the kernel keeps), and u-areas (per-process
information) and the like.

Good luck!  Feel free to respond via email if you have more questions.

Dave Stein						    "Life's a clambake."
ARPA: angst%csilvax@hub.ucsb.edu	      Disclaimer: college students don't
UUCP: ...ucbvax!hub!csilvax!angst			  need no disclaimers!