RDProcess is an Objective-C class that's an improved version of NSProcessInformation and NSRunningApplication: it gives you as many information about any running process in your system as it even possible to collect.
My favorite thing about RDProcesss is that it handle Sandbox-related information: it can check if a process is even sandboxed, search for the its containter path, etc.
RDProcesss's built on top of Launch Services, AppKit and some old-school POSIX things.
The library has only one class: RDProcess which implements the methods listed below:
- (instancetype)initWithPID: (pid_t)aPid;
Initializes a process with a PID, and collects the following information about it:
- PID value
- Process name (using either
LunchServicesAPI orargv[0]-based technique) - Bundle ID (if the process is a bundled application, this value will be
nilotherwise) - An executable path (using either
LaunchServicesAPI orproc_pidpath(), oragrv[0]-based technique)
-
+ (NSArray *)allProcessesWithBundleID: (NSString *)bundleID;
Returns an array of all launched processes with a specifed Bundle ID; each item is initialized using-initWithPID: -
+ (void)enumerateProcessesWithBundleID: (NSString *)bundleID usingBlock: (RDProcessEnumerator)block;Iterates a list of launched processes with a specifed Bundle ID using a block;RDProcessEnumeratortype's definition is folowing:typedef void (^RDProcessEnumerator)(id process, NSString *bundleID, BOOL *stop);
-
+ (instancetype)youngestProcessWithBundleID: (NSString *)bundleID
Returns the most recently launched process with a Bundle ID. -
+ (instancetype)oldestProcessWithBundleID: (NSString *)bundleID;
Returns the most oldest process with a Bundle ID.
- (BOOL)setProcessName: (NSString *)new_proc_name;
This method sets a new value forLaunchServices' «Display Name» key of the process.
Note that some utils like
psortoprather depend on anargv[0]value than on the «Display Name», so the process name may remain unchanged there.
-
- (pid_t)pid;
Just a PID of the process. This value if fetched fromLaunchServicedatabase each time you call this method. -
- (NSString *)processName;
A name of the process (using eitherLaunchServicesAPI orargv[0]-based value).
Note, that this method won't return
nilvalue, but a result value may be invalid in any other way, so it's up to you to verify it.
This should only happen for processes that weren't launched viaLaunch Servicesand have a curruptedargvarray.
-
- (NSString *)bundleID
A Bundle ID of the process (ornilfor non-bundled applications). -
- (NSURL *)bundleURL
An URL of the process' bundle (ornilfor non-bundled applications). -
- (NSString *)bundlePath
A path of the process' bundle (ornilfor non-bundled applications). -
- (NSURL *)executableURL
An URL of the process' main executable file. -
- (NSString *)executablePath;
A path of the process' main executable file.
-
- (uid_t)ownerUserID;An ID (UID) of a user who owns this process. -
- (NSString *)ownerUserName
A «short» name of the user who owns this process. -
- (NSString *)ownerFullUserName;
A full name of the user who owns this process. -
- (NSDictionary *)ownerGroups;
A list of which the owner user is member of. The result dictionary has the following format: keys are groupd IDs, values are groups names.
- (BOOL)isSandboxedByOSX;
Checks if the the process was launched inside the Sandbox environment, i.e. it's sandboxed by OS X.
Note: this method returns
YESfor any process with invalid PID, so you should also check if-sandboxContainerPathisn'tnil.
-
- (NSString *)sandboxContainerPath;
A path of the process' sandbox container directory (ornilif it's not sanboxed). -
- (NSURL *)sandboxContainerURL;
An URL of the process's sandbox containter directory (ornilof it's not sandboxed). -
- (BOOL)canWriteToFileAtPath: (NSString *)file_path;
- (BOOL)canWriteToFileAtURL: (NSURL *)file_url;
Checks if the process can write to a specified file. -
- (BOOL)canReadFileAtPath: (NSString *)file_path;
- (BOOL)canReadFileAtURL: (NSURL *)file_url;
Checks if the process can read a specifed file.
Until the current user is a member of procmod group, these methods will work only for processes owned by this user (for other's processes they just return nil).
-
- (NSArray *)launchArguments;
An Objective-C representaion of the process'argvarray. -
- (NSDictionary *)environmentVariables;
A dictionary containing all the environment variables.
Note: all values are percent escaped.
- Check if process was sandboxed by user
- Enable\Disable sandbox for the process
- Description of the process' executable architecture (smth like "Intel (64-bit)")
- Check for 64 bit
- CPU usage information
- Memory usage information
- Threads information (active, idle, count)
If you found any bug(s) or something, please open an issue or a pull request — I'd appreciate your help! (^,,^)
Dmitry Rodionov, 2014
i.am.rodionovd@gmail.com