A class for reporting Unix process statistics.
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.
allProcesses |
+ (NSArray *)allProcesses;
Returns an array of all processes.
annotatedCommand |
- (NSString *)annotatedCommand;
Returns a composite string consisting of the command name and its annotation
annotation |
- (NSString *)annotation;
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;
Returns an array containing the command line arguments called to execute the process. This method is not perfectly reliable.
basePriority |
- (int)basePriority;
Returns the base priority.
children |
- (NSArray *)children;
Returns an array containing the process's children, if any.
command |
- (NSString *)command;
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;
Returns the current process.
environment |
- (NSDictionary *)environment;
Returns a dictionary containing the environment variables of the process. This method is not perfectly reliable.
initWithProcessIdentifier: |
- (id)initWithProcessIdentifier:(int)pid;
Initializes the receiver with the given process identifier. Returns nil if no such process exists.
parent |
- (AGProcess *)parent;
Returns the parent process.
parentProcessIdentifier |
- (int)parentProcessIdentifier;
Returns the parent process identifier.
percentCPUUsage |
- (double)percentCPUUsage;
Returns the current CPU usage in the range 0.0 - 1.0.
percentMemoryUsage |
- (double)percentMemoryUsage;
Returns resident memory usage as a fraction of the host's physical memory in the range 0.0 - 1.0.
priority |
- (int)priority;
Returns the current priority.
processesForCommand: |
+ (NSArray *)processesForCommand:(NSString *)comm;
Returns an array of all processes for the given command.
processesForProcessGroup: |
+ (NSArray *)processesForProcessGroup:(int)pgid;
Returns an array of all processes in the given process group.
processesForRealUser: |
+ (NSArray *)processesForRealUser:(int)ruid;
Returns an array of all processes for the given real user.
processesForTerminal: |
+ (NSArray *)processesForTerminal:(int)tdev;
Returns an array of all processes running on the given terminal. Takes a terminal device number.
processesForUser: |
+ (NSArray *)processesForUser:(int)uid;
Returns an array of all processes for the given user.
processForCommand: |
+ (AGProcess *)processForCommand:(NSString *)comm;
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;
Returns the process for the given process identifier, or nil if no such process exists.
processGroup |
- (int)processGroup;
Returns the process group.
processIdentifier |
- (int)processIdentifier;
Returns the process identifier.
realUserIdentifier |
- (int)realUserIdentifier;
Returns the real user identifier.
residentMemorySize |
- (unsigned)residentMemorySize;
Returns the resident memory size in bytes.
siblings |
- (NSArray *)siblings;
Returns an array containing the process's siblings, if any.
state |
- (AGProcessState)state;
Returns the current state. Possible values are defined by AGProcessState.
systemCPUTime |
- (double)systemCPUTime;
Returns the accumulated system CPU time in seconds.
terminal |
- (int)terminal;
Returns the terminal device number.
terminalProcessGroup |
- (int)terminalProcessGroup;
Returns the terminal process group.
threadCount |
- (int)threadCount;
Returns the number of threads.
totalCPUTime |
- (double)totalCPUTime;
Returns the accumulated CPU time in seconds.
userCPUTime |
- (double)userCPUTime;
Returns the accumulated user CPU time in seconds.
userIdentifier |
- (int)userIdentifier;
Returns the user identifier.
userProcesses |
+ (NSArray *)userProcesses;
Returns an array of all processes running for the current user.
virtualMemorySize |
- (unsigned)virtualMemorySize;
Returns the virtual memory size in bytes.
(Last Updated June 05, 2005)