next up previous contents index
Next: The OSFriends Interface Up: The OS Interface: Processes Previous: Terminating Processes

Examining Processes

  This subsection describes the procedures for enumerating processes and for obtaining information about processes.

         

TYPE
  ProcessState = (PSRunning, PSStopped, PSTerminating);

     

          A process is always in one of three ProcessStates as seen by the operating system. It is running if it has been started, has not yet terminated, and is not currently stopped. It is stopped if it received a stop signal (SigStop, SigTStp, SigTTIn, or SigTTOu) and hasn't yet received the continue signal (SigCont) or a terminating signal. Finally, it is terminating if it has terminated normally or abnormally and its parent has not yet called WaitForChild specifying its process identifier (see Section 5.4, page [*]). (A terminating process is sometimes called a zombie.)

       

TYPE
  DebugState = (DSRunning, DSStopped, DSTrapped);

      A process is always in one of three DebugStates as seen by the debugger. It is running if the debugger hasn't stopped it at the request of the user and if it hasn't spontaneously stopped because of a trap. It is stopped if the debugger has stopped it at the request of the user--for example, typing Control-C to the TeleDebug command. It is trapped if a thread within the process has caused a trap that is handled by the debugger.

 

TYPE
  SignalStates = ARRAY Signal OF BITS 8 FOR SignalState;

The type SignalStates represents the set of signal states for a process.

   

TYPE
  RWho = (Self, Children);

TYPE
  ProcessInfo = RECORD

    pid: PID;
    pgrp: PGRP;
    ppid: PID;

    effUser, realUser: Text.T;

    ctlTty: Text.T;
    windowSystem: Text.T;

    space: NubTypes.Space;

    numThreads: CARDINAL;

    processState: ProcessState;
    debugState: DebugState;
    debuggerConnected: BOOLEAN;

    signalStates: SignalStates;

    command: PathName;

    mappedBytes, residentBytes: CARDINAL;

    rUsage: ARRAY RWho OF RUsage;

  END; (* ProcessInfo *)

A ProcessInfo record packages the information available about a file via the GetProcessInfo procedure.

        The pid and pgrp fields give the process identifier and process group identifier. The ppid field gives the process identifier of the parent process; if the process is an orphan, ppid is one.

    The effUser and realUser fields give the effective and real user names on whose behalf the process is executing.

      The ctlTty field gives an identification of the control terminal of the process. The windowSystem field identifies the Trestle instance (see Trestle.RPCInit) used for emulated terminals and typescripts created by this process.

    The space field gives the address space number, of interest only for low-level debugging.

The numThreads field tells how many threads of control are executing within the process. For a standard Ultrix application running on Taos, it will equal one; for a Topaz application it will always be greater than one.

    The processState field tells whether the process is currently running, stopped, or terminating, as seen by the operating system. The debugState field tells whether the process is running, stopped, or trapped, as seen by the debugger. The debuggerConnected field tells whether there is currently a TeleDebug session in existence for the process.

  The signalStates field tells whether the process is currently handling, ignoring, or defaulting each of the 31 kinds of signals.

  The command field gives the path name given to StartProcess, StartProcessSearch, or the execve kernel call to load the process.

The mappedBytes and residentBytes fields represent the number of bytes within the address space of the process that are currently mapped and currently resident, respectively. The resident number changes with swapping; the mapped number changes only in response to actions of that process.

The rUsage field summarizes CPU time used by this process (Self) and by all its terminated descendants (Children). (See the discussion of RUsage on page [*].)

 

PROCEDURE GetProcessInfo(
    pid: PID;
    VAR (* OUT *) processInfo: ProcessInfo;
    getUser: BOOLEAN := TRUE)
  RAISES {Error}; (* BadPIDEC *)

GetProcessInfo returns information about the specified process. It returns information about the calling process if pid is equal to NullPID; it raises BadPIDEC if pid is not equal to NullPID or the process identifier of any existing process. (Once WaitForChild is called for a terminating process, the process ceases to exist as far as GetProcessInfo is concerned.)

GetProcessInfo fills in the effUser and realUser fields only if getUser is TRUE.

Taos note: The mappedBytes is currently estimated by adding the allocated lengths of the high and low segments; residentBytes is set to zero.

  Ultrix note: GetProcessInfo only works when pid is equal to NullPID. When getUser is TRUE, the /etc/passwd file must be read. The space, ctlTty, and command field are not filled in. The residentBytes field is actually a maximum of the number of bytes. The mappedBytes field includes both shared and unshared memory.

 

PROCEDURE NextProcess(pid: PID): PID RAISES {};

    NextProcess returns the next in-use process identifier larger than the one it is given. To enumerate all the existing processes (using the same definition of existence as does GetProcessInfo): start by passing NullPID to NextProcess, repeatedly call NextProcess with its result from the previous call, and stop when NextProcess returns NullPID.

Ultrix note: NextProcess always returns NullPID.

Taos note: NextProcess returns process identifiers for some `system processes' for which complete information via GetProcessInfo is not available:

PID Command Other interesting fields
1 Init rUsage[Children]
2 Nub numThreads, mappedBytes,
    residentBytes (someday)
3 Taos space, numThreads, mappedBytes,
    residentBytes, rUsage

 

PROCEDURE GetPassword(): Text.T RAISES {Error};

  GetPassword returns the password (in clear text) of the calling process if the caller is the super-user; otherwise GetPassword raises NotSuperUserEC. The password is needed for doing authenticated RPC.

      Ultrix note: GetPassword returns the value of the PASSWORD environment variable if it is set, otherwise it reads the file /.ffpw (readable only by user firefly) and returns its contents.

Taos note: Until general authenticated RPC is available, GetPassword does not require the caller to be the super-user.

END OS.


next up previous contents index
Next: The OSFriends Interface Up: The OS Interface: Processes Previous: Terminating Processes
Paul McJones
8/28/1997