iOS Developer Library

Developer

Foundation Framework Reference NSProcessInfo Class Reference

Options
Deployment Target:

On This Page
Language:

NSProcessInfo

The NSProcessInfo class provides methods to access information about the current process. Each process has a single, shared NSProcessInfo object, known as process information agent. More...

Inheritance


Conforms To


Import Statement


import Foundation @import Foundation;

Availability


Available in iOS 2.0 and later.
  • Returns the process information agent for the process.

    Declaration

    Swift

    class func processInfo() -> NSProcessInfo

    Objective-C

    + (NSProcessInfo *)processInfo

    Return Value

    Shared process information agent for the process.

    Discussion

    An NSProcessInfo object is created the first time this method is invoked, and that same object is returned on each subsequent invocation.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • arguments arguments Property

    Array of strings with the command-line arguments for the process.

    Declaration

    Swift

    var arguments: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *arguments

    Discussion

    This array contains all the information passed in the argv array, including the executable name in the first element.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The variable names (keys) and their values in the environment from which the process was launched.

    Declaration

    Swift

    var environment: [NSObject : AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSDictionary *environment

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Global unique identifier for the process. (read-only)

    Declaration

    Swift

    var globallyUniqueString: String { get }

    Objective-C

    @property(readonly, copy) NSString *globallyUniqueString

    Discussion

    The global ID for the process includes the host name, process ID, and a time stamp, which ensures that the ID is unique for the network. This property generates a new string each time its getter is invoked, and it uses a counter to guarantee that strings created from the same process are unique.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

    See Also

    processName

  • The identifier of the process (often called process ID).

    Declaration

    Swift

    var processIdentifier: Int32 { get }

    Objective-C

    @property(readonly) int processIdentifier

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

    See Also

    processName

  • The name of the process.

    Declaration

    Swift

    var processName: String

    Objective-C

    @property(copy) NSString *processName

    Discussion

    The process name is used to register application defaults and is used in error messages. It does not uniquely identify the process.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • hostName hostName Property

    The name of the host computer on which the process is executing. (read-only)

    Declaration

    Swift

    var hostName: String { get }

    Objective-C

    @property(readonly, copy) NSString *hostName

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a constant to indicate the operating system on which the process is executing.

    Deprecation Statement

    Use operatingSystemVersion or isOperatingSystemAtLeastVersion: instead

    Declaration

    Swift

    func operatingSystem() -> Int

    Objective-C

    - (NSUInteger)operatingSystem

    Return Value

    Operating system identifier. See Constants for a list of possible values. In OS X, it’s NSMACHOperatingSystem.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 8.0.

  • Returns a string containing the name of the operating system on which the process is executing.

    Deprecation Statement

    Use operatingSystemVersionString instead.

    Declaration

    Swift

    func operatingSystemName() -> String

    Objective-C

    - (NSString *)operatingSystemName

    Return Value

    Operating system name. In OS X, it’s @"NSMACHOperatingSystem"

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 8.0.

  • A string containing the version of the operating system on which the process is executing. (read-only)

    Declaration

    Swift

    var operatingSystemVersionString: String { get }

    Objective-C

    @property(readonly, copy) NSString *operatingSystemVersionString

    Discussion

    The operating system version string is human readable, localized, and is appropriate for displaying to the user. This string is not appropriate for parsing.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The version of the operating system on which the process is executing. (read-only)

    Declaration

    Swift

    var operatingSystemVersion: NSOperatingSystemVersion { get }

    Objective-C

    @property(readonly) NSOperatingSystemVersion operatingSystemVersion

    Import Statement

    import Foundation

    Availability

    Available in iOS 8.0 and later.

  • Returns a Boolean value indicating whether the version of the operating system on which the process is executing is the same or later than the given version.

    Declaration

    Swift

    func isOperatingSystemAtLeastVersion(_ version: NSOperatingSystemVersion) -> Bool

    Objective-C

    - (BOOL)isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)version

    Parameters

    version

    The operating system version to test against.

    Return Value

    YEStrue if the operating system on which the process is executing is the same or later than the given version; otherwise NOfalse.

    Discussion

    This method accounts for major, minor, and update versions of the operating system.

    Import Statement

    import Foundation

    Availability

    Available in iOS 8.0 and later.

  • The number of processing cores available on the computer. (read-only)

    Declaration

    Swift

    var processorCount: Int { get }

    Objective-C

    @property(readonly) NSUInteger processorCount

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The number of active processing cores available on the computer. (read-only)

    Declaration

    Swift

    var activeProcessorCount: Int { get }

    Objective-C

    @property(readonly) NSUInteger activeProcessorCount

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

    See Also

    processorCount

  • The amount of physical memory on the computer in bytes. (read-only)

    Declaration

    Swift

    var physicalMemory: UInt64 { get }

    Objective-C

    @property(readonly) unsigned long long physicalMemory

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The time interval since the computer was restarted.

    Declaration

    Swift

    var systemUptime: NSTimeInterval { get }

    Objective-C

    @property(readonly) NSTimeInterval systemUptime

    Import Statement

    import Foundation

    Availability

    Available in iOS 4.0 and later.

Data Types

  • Operating system version structure used with operatingSystemVersion and isOperatingSystemAtLeastVersion:.

    Declaration

    Swift

    struct NSOperatingSystemVersion { var majorVersion: Int var minorVersion: Int var patchVersion: Int }

    Objective-C

    typedef struct { NSInteger majorVersion; NSInteger minorVersion; NSInteger patchVersion; } NSOperatingSystemVersion;

    Constants

    • majorVersion

      majorVersion

      The major release number, such as 10 in version 10.9.3.

    • minorVersion

      minorVersion

      The minor release number, such as 9 in version 10.9.3.

    • patchVersion

      patchVersion

      The update release number, such as 3 in version 10.9.3.

    Import Statement

    import Foundation

    Availability

    Available in iOS 8.0 and later.

  • Declaration

    Swift

    struct NSActivityOptions : RawOptionSetType { init(_ rawValue: UInt64) init(rawValue rawValue: UInt64) static var IdleDisplaySleepDisabled: NSActivityOptions { get } static var IdleSystemSleepDisabled: NSActivityOptions { get } static var SuddenTerminationDisabled: NSActivityOptions { get } static var AutomaticTerminationDisabled: NSActivityOptions { get } static var UserInitiated: NSActivityOptions { get } static var UserInitiatedAllowingIdleSystemSleep: NSActivityOptions { get } static var Background: NSActivityOptions { get } static var LatencyCritical: NSActivityOptions { get } }

    Objective-C

    typedef enum : uint64_t { NSActivityIdleDisplaySleepDisabled = (1ULL << 40), NSActivityIdleSystemSleepDisabled = (1ULL << 20), NSActivitySuddenTerminationDisabled = (1ULL << 14), NSActivityAutomaticTerminationDisabled = (1ULL << 15), NSActivityUserInitiated = (0x00FFFFFFULL | NSActivityIdleSystemSleepDisabled ), NSActivityUserInitiatedAllowingIdleSystemSleep = (NSActivityUserInitiated & ~NSActivityIdleSystemSleepDisabled ), NSActivityBackground = 0x000000FFULL, NSActivityLatencyCritical = 0xFF00000000ULL, } NSActivityOptions;

    Constants

    • IdleDisplaySleepDisabled

      NSActivityIdleDisplaySleepDisabled

      Flag to require the screen to stay powered on.

      Available in iOS 7.0 and later.

    • IdleSystemSleepDisabled

      NSActivityIdleSystemSleepDisabled

      Flag to prevent idle sleep.

      This is included in NSActivityUserInitiatedAllowingIdleSystemSleep.

      Available in iOS 7.0 and later.

    • SuddenTerminationDisabled

      NSActivitySuddenTerminationDisabled

      Flag to prevent sudden termination.

      This is included in NSActivityUserInitiatedAllowingIdleSystemSleep.

      Available in iOS 7.0 and later.

    • AutomaticTerminationDisabled

      NSActivityAutomaticTerminationDisabled

      Flag to prevent automatic termination.

      This is included in NSActivityUserInitiatedAllowingIdleSystemSleep.

      Available in iOS 7.0 and later.

    • UserInitiated

      NSActivityUserInitiated

      Flag to indicate the app is performing a user-requested action.

      Available in iOS 7.0 and later.

    • UserInitiatedAllowingIdleSystemSleep

      NSActivityUserInitiatedAllowingIdleSystemSleep

      Flag to indicate the app is performing a user-requested action, but that the system can sleep on idle.

      Available in iOS 7.0 and later.

    • Background

      NSActivityBackground

      Flag to indicate the app has initiated some kind of work, but not as the direct result of user request.

      Available in iOS 7.0 and later.

    • LatencyCritical

      NSActivityLatencyCritical

      Flag to indicate the activity requires the highest amount of timer and I/O precision available.

      Available in iOS 7.0 and later.

    Discussion

    To include one of these individual flags in one of the sets, use bitwise OR; for example, during a presentation you might use:

    • NSActivityUserInitiated | NSActivityIdleDisplaySleepDisabled

    To exclude from one of the sets, use bitwise AND with NOT; for example, during a user initiated action that may be safely terminated with no application interaction in case of logout you might use:

    • NSActivityUserInitiated & ~NSActivitySuddenTerminationDisabled

    Import Statement

    import Foundation

    Availability

    Available in iOS 7.0 and later.

  • The following constants are provided by the NSProcessInfo class as return values for operatingSystem.

    Declaration

    Swift

    var NSHPUXOperatingSystem: Int { get } var NSMACHOperatingSystem: Int { get } var NSOSF1OperatingSystem: Int { get } var NSSolarisOperatingSystem: Int { get } var NSSunOSOperatingSystem: Int { get } var NSWindows95OperatingSystem: Int { get } var NSWindowsNTOperatingSystem: Int { get }

    Objective-C

    enum { NSWindowsNTOperatingSystem = 1, NSWindows95OperatingSystem, NSSolarisOperatingSystem, NSHPUXOperatingSystem, NSMACHOperatingSystem, NSSunOSOperatingSystem, NSOSF1OperatingSystem };

    Constants

    • NSHPUXOperatingSystem

      NSHPUXOperatingSystem

      Indicates the HP UX operating system.

      Available in iOS 2.0 and later.

      Deprecated in iOS 8.0.

    • NSMACHOperatingSystem

      NSMACHOperatingSystem

      Indicates the OS X operating system.

      Available in iOS 2.0 and later.

      Deprecated in iOS 8.0.

    • NSOSF1OperatingSystem

      NSOSF1OperatingSystem

      Indicates the OSF/1 operating system.

      Available in iOS 2.0 and later.

      Deprecated in iOS 8.0.

    • NSSolarisOperatingSystem

      NSSolarisOperatingSystem

      Indicates the Solaris operating system.

      Available in iOS 2.0 and later.

      Deprecated in iOS 8.0.

    • NSSunOSOperatingSystem

      NSSunOSOperatingSystem

      Indicates the Sun OS operating system.

      Available in iOS 2.0 and later.

      Deprecated in iOS 8.0.

    • NSWindows95OperatingSystem

      NSWindows95OperatingSystem

      Indicates the Windows 95 operating system.

      Available in iOS 2.0 and later.

      Deprecated in iOS 8.0.

    • NSWindowsNTOperatingSystem

      NSWindowsNTOperatingSystem

      Indicates the Windows NT operating system.

      Available in iOS 2.0 and later.

      Deprecated in iOS 8.0.

    Import Statement