Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!lll-lcc!rutgers!mit-eddie!husc6!necntc!encore!linus!philabs!micomvax!musocs!mcgill-vision!mouse
From: mouse@mcgill-vision.UUCP (der Mouse)
Newsgroups: comp.unix.wizards,comp.unix.questions
Subject: Re: Access to user process info.
Message-ID: <587@mcgill-vision.UUCP>
Date: Sun, 21-Dec-86 02:04:22 EST
Article-I.D.: mcgill-v.587
Posted: Sun Dec 21 02:04:22 1986
Date-Received: Mon, 22-Dec-86 18:41:45 EST
References: <1327@brl-adm.ARPA> <165@hqda-ai.UUCP> <263@spectrix.UUCP> <99@osupyr.UUCP>
Organization: McGill University, Montreal
Lines: 45
Xref: mnetor comp.unix.wizards:422 comp.unix.questions:433

In article <99@osupyr.UUCP>, dusan@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  and /vmunix and
/dev/kmem, others say that you can't because it varies across machines
and  doesn't have enough info.  Both are right.  This is
normally done in a machine- and system-specific manner using include
files such as  and  (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 , 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 -  and
 
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@harvard.harvard.edu