AGProcess


Abstract

A class for reporting Unix process statistics.

Discussion

AGProcess is a class for reporting Unix process statistics. It is similar to NSProcessInfo except that it provides more information, and can represent any process, not just the current process. Additionally it provides methods for sending signals to processes.

Instances are created with -initWithProcessIdentifier: or +processForProcessIdentifier:, but several convenience methods exist for obtaining instances based on other information, the most useful being +currentProcess, +allProcesses, and +userProcess.

The level of information an AGProcess can return depends on the user's permission. In general, a user can obtain general information like the arguments or process ID for any process, but can only obtain CPU and memory usage statistics for their own processes, unless they are root. Also, no information is available after the process has exited except the process ID and the state (AGProcessStateZombie or AGProcessStateExited). Methods which return a numerical value will return AGProcessValueUnknown if the statistic can't be obtained.



Methods

+allProcesses
-annotatedCommand
-annotation
-arguments
-basePriority
-children
-command
+currentProcess
-environment
-initWithProcessIdentifier:
-parent
-parentProcessIdentifier
-percentCPUUsage
-percentMemoryUsage
-priority
+processesForCommand:
+processesForProcessGroup:
+processesForRealUser:
+processesForTerminal:
+processesForUser:
+processForCommand:
+processForProcessIdentifier:
-processGroup
-processIdentifier
-realUserIdentifier
-residentMemorySize
-siblings
-state
-systemCPUTime
-terminal
-terminalProcessGroup
-threadCount
-totalCPUTime
-userCPUTime
-userIdentifier
+userProcesses
-virtualMemorySize

allProcesses


+ (NSArray *)allProcesses;
Discussion

Returns an array of all processes.


annotatedCommand


- (NSString *)annotatedCommand;
Discussion

Returns a composite string consisting of the command name and its annotation


annotation


- (NSString *)annotation;
Discussion

Returns an annotation that can be used to distinguish multiple instances of a process name. The current implementation does this by examining the command line arguments for "DashboardClient" and "java" processes. If there is no annotation, the method returns nil.


arguments


- (NSArray *)arguments;
Discussion

Returns an array containing the command line arguments called to execute the process. This method is not perfectly reliable.


basePriority


- (int)basePriority;
Discussion

Returns the base priority.


children


- (NSArray *)children;
Discussion

Returns an array containing the process's children, if any.


command


- (NSString *)command;
Discussion

Attempts to return the command that was called to execute the process. If that fails, attempts to return the accounting name. If that fails, returns an empty string.


currentProcess


+ (AGProcess *)currentProcess;
Discussion

Returns the current process.


environment


- (NSDictionary *)environment;
Discussion

Returns a dictionary containing the environment variables of the process. This method is not perfectly reliable.


initWithProcessIdentifier:


- (id)initWithProcessIdentifier:(int)pid;
Discussion

Initializes the receiver with the given process identifier. Returns nil if no such process exists.


parent


- (AGProcess *)parent;
Discussion

Returns the parent process.


parentProcessIdentifier


- (int)parentProcessIdentifier;
Discussion

Returns the parent process identifier.


percentCPUUsage


- (double)percentCPUUsage;
Discussion

Returns the current CPU usage in the range 0.0 - 1.0.


percentMemoryUsage


- (double)percentMemoryUsage;
Discussion

Returns resident memory usage as a fraction of the host's physical memory in the range 0.0 - 1.0.


priority


- (int)priority;
Discussion

Returns the current priority.


processesForCommand:


+ (NSArray *)processesForCommand:(NSString *)comm;
Discussion

Returns an array of all processes for the given command.


processesForProcessGroup:


+ (NSArray *)processesForProcessGroup:(int)pgid;
Discussion

Returns an array of all processes in the given process group.


processesForRealUser:


+ (NSArray *)processesForRealUser:(int)ruid;
Discussion

Returns an array of all processes for the given real user.


processesForTerminal:


+ (NSArray *)processesForTerminal:(int)tdev;
Discussion

Returns an array of all processes running on the given terminal. Takes a terminal device number.


processesForUser:


+ (NSArray *)processesForUser:(int)uid;
Discussion

Returns an array of all processes for the given user.


processForCommand:


+ (AGProcess *)processForCommand:(NSString *)comm;
Discussion

Returns the process for the given command, or nil if no such process exists. If there is more than one process with the same command, there is no guarantee which will be returned.


processForProcessIdentifier:


+ (AGProcess *)processForProcessIdentifier:(int)pid;
Discussion

Returns the process for the given process identifier, or nil if no such process exists.


processGroup


- (int)processGroup;
Discussion

Returns the process group.


processIdentifier


- (int)processIdentifier;
Discussion

Returns the process identifier.


realUserIdentifier


- (int)realUserIdentifier;
Discussion

Returns the real user identifier.


residentMemorySize


- (unsigned)residentMemorySize;
Discussion

Returns the resident memory size in bytes.


siblings


- (NSArray *)siblings;
Discussion

Returns an array containing the process's siblings, if any.


state


- (AGProcessState)state;
Discussion

Returns the current state. Possible values are defined by AGProcessState.


systemCPUTime


- (double)systemCPUTime;
Discussion

Returns the accumulated system CPU time in seconds.


terminal


- (int)terminal;
Discussion

Returns the terminal device number.


terminalProcessGroup


- (int)terminalProcessGroup;
Discussion

Returns the terminal process group.


threadCount


- (int)threadCount;
Discussion

Returns the number of threads.


totalCPUTime


- (double)totalCPUTime;
Discussion

Returns the accumulated CPU time in seconds.


userCPUTime


- (double)userCPUTime;
Discussion

Returns the accumulated user CPU time in seconds.


userIdentifier


- (int)userIdentifier;
Discussion

Returns the user identifier.


userProcesses


+ (NSArray *)userProcesses;
Discussion

Returns an array of all processes running for the current user.


virtualMemorySize


- (unsigned)virtualMemorySize;
Discussion

Returns the virtual memory size in bytes.

(Last Updated June 05, 2005)