Access to user process info.

der Mouse mouse at mcgill-vision.UUCP
Sun Dec 21 17:04:22 AEST 1986


In article <99 at osupyr.UUCP>, dusan at osupyr.UUCP (Dusan Nedeljkovic) writes:
> Briefly:  I need to get access to information about a certain (or
> more generally, ALL) processes that are active and bound to a
> terminal.

I would recommend creating a pipe and forking ps.

> I guess, what I'm really asking is how the unix utility "w" gets its
> information from the system about active processes.

You mention that some people say to use <sys/user.h> and /vmunix and
/dev/kmem, others say that you can't because it varies across machines
and <sys/user.h> doesn't have enough info.  Both are right.  This is
normally done in a machine- and system-specific manner using include
files such as <sys/user.h> and <sys/proc.h> (and others, depending on
the system).

> 	  To refresh your memory, I've included some sample "w" output:
> 	User     tty       login@  idle   JCPU   PCPU  what
> 	dusan    ttyi02    7:24pm         1:06     28  w
> 	alden    ttyi03    5:29pm     2   7:03     22  emacs /etc/termcap
> 	gae      ttyi17    7:45pm            8      8  rn
> 	  How does "w" get all this useful info?  I can't imagine that
> 	  it doesn't use <sys/user.h>, etc.

I can't speak for a Pyramid, but on a 4/[23] VAX, it gets

User, tty, and login@ from /etc/utmp
Idle time by groveling through the tty driver structures via /dev/kmem
 and the appropriate include files (I think)
JCPU and PCPU from the user and proc structs - <sys/user.h> and
 <sys/proc.h>
what from the process' argv[] vector - it's stored in the process'
 address space, which w knows how to fetch from /dev/mem or /dev/drum
 as necessary (more include files)

Really, forking ps is most likely the simplest, easiest, least buggy
solution (if your ps can be made to produce the information you want).

					der Mouse

USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!mcgill-vision!mouse
     think!mosart!mcgill-vision!mouse
Europe: mcvax!decvax!utcsri!mcgill-vision!mouse
ARPAnet: think!mosart!mcgill-vision!mouse at harvard.harvard.edu



More information about the Comp.unix.questions mailing list