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 processNSProcessInfo *proc = [NSProcessInfo processInfo];// The name and PID of the processNSString *name = [proc processName]; int pid = [proc processIdentifier];// The arguments launched with the processNSArray *args = [proc arguments];// A dictionary of the environment variables for the processNSDictionary *env = [proc environment];// The host name for the host running the processNSString *host = [proc hostName];// The operating system version string// Note: this string is NOT appropriate for parsingNSString *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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access