Operating System Interaction
The Foundation framework provides many services through a small set
of classes that allow developers to interact with the underlying
operating system in several ways. NSTask
is an
object-oriented interface to configure and launch a process as a
subprocess of
the current application.
NSProcessInfo
lets an application discover information
about its current process.
Process Info
Example 2-35 shows some of the information you can
obtain by using NSProcessInfo
.
// Get the shared process info object for the current process
NSProcessInfo *proc = [NSProcessInfo processInfo];// The name and PID of the process
NSString *name = [proc processName]; int pid = [proc processIdentifier];// The arguments launched with the process
NSArray *args = [proc arguments];// A dictionary of the environment variables for the process
NSDictionary *env = [proc environment];// The host name for the host running the process
NSString *host = [proc hostName];// The operating system version string
// Note: this string is NOT appropriate for parsing
NSString *ver = [proc operatingSystemVersionString];
Tasks
NSTask
is a class that lets a
program configure, launch, and communicate with another program as a
subprocess. This is something you’ll see every time
you execute an application you work on from within Project Builder.
An NSTask
is launched in a fully configurable execution environment where environment variables, command line options, and other ...
Get Cocoa in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.