[comp.unix.questions] How do I get what users are doing?

ccastdf@prism.gatech.EDU (Dave) (11/08/90)

How do I (from C) get the information on what a user is doing.  I have
seen the output from a w (who is online, and what they are doing), but
I can't figure out where it is coming from.

Thanks in advance.

David Frascone
-- 
David Frascone 
Georgia Institute of Technology, Atlanta Georgia, 30332
uucp:	  ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!ccastdf
Internet: ccastdf@prism.gatech.edu

cpcahil@virtech.uucp (Conor P. Cahill) (11/08/90)

In article <16642@hydra.gatech.EDU> ccastdf@prism.gatech.EDU (Dave) writes:
>How do I (from C) get the information on what a user is doing.  I have
>seen the output from a w (who is online, and what they are doing), but
>I can't figure out where it is coming from.

do a popen("ps"...) or a popen("w"...)


-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 

subbarao@phoenix.Princeton.EDU (Kartik Subbarao) (11/09/90)

In article <1990Nov08.131534.10938@virtech.uucp> cpcahil@virtech.UUCP (Conor P. Cahill) writes:
>In article <16642@hydra.gatech.EDU> ccastdf@prism.gatech.EDU (Dave) writes:
>>How do I (from C) get the information on what a user is doing.  I have
>>seen the output from a w (who is online, and what they are doing), but
>>I can't figure out where it is coming from.
>
>do a popen("ps"...) or a popen("w"...)

That's probably the simplest way to do things, but at least in the case of "w" we can be a bit
more informative. w finds out who is on from reading /etc/utmp (the format of /etc/utmp and 
/etc/wtmp is described in utmp(5). In order to find out what processes are running, it either
calls ps or is already setgid kmem so it can peek at /dev/kmem. Then it does something to find
out the most "interesting" process for each user and displays it. 

So, to basically answer your question, if you want to find out solely who is on from a C program,
you can use the utmp interface, but if you want processes, I guess a popen to ps might not 
be a bad idea.

	
				-Kartik


 


(I need a new .signature -- any suggestions?)
subbarao@{phoenix or gauguin}.Princeton.EDU -|Internet
kartik@silvertone.Princeton.EDU (NeXT mail)       -|	
SUBBARAO@PUCC.BITNET			          - Bitnet

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (11/09/90)

In article <3933@idunno.Princeton.EDU> subbarao@phoenix.Princeton.EDU (Kartik Subbarao) writes:
  [ w ]
> In order to find out what processes are running, it either
> calls ps or is already setgid kmem so it can peek at /dev/kmem.

I haven't seen a version that calls ps. Note that /dev/kmem used to be
readable on most systems (and still is on many), so system-status
programs didn't have to be setuid or setgid.

> Then it does something to find
> out the most "interesting" process for each user and displays it. 

Usually w pretends that processes don't wrap around, and takes a System
V view of the world.

The former means that it takes the highest-numbered process as the
latest process invoked on the terminal.

The latter means that it checks first only for processes not ignoring
interrupts, since that (usually) characterizes foreground processes
under System V. Only if it doesn't find a foreground process does it
look for background processes on the terminal. Under BSD, foreground
processes are distinguished by their process groups, though this would
require w to open the terminal and figure out the foreground process
group.

> (I need a new .signature -- any suggestions?)

How 'bout ``It's your fault that I post articles with 100 columns''?

---Dan