O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Example 2-35. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required