NSProcessInfo

 

NSProcessInfo对象是用来获取进程的相关信息,包括进程的参数、PID、进程所在的系统的主机名、操作系统名、操作系统版本等等。(UIDevice获设备信息)

 

    @autoreleasepool {
        //创建一个NSProcessInfo对象,表示当前进程
        NSProcessInfo *processInfo = [NSProcessInfo processInfo];
        
        //获取运行该进程的参数
        NSArray *arr = [processInfo arguments];
        NSLog(@"运行该程序的参数为:%@", arr);
        //获取该进程的进程标示符
        NSLog(@"该程序的进程标示符(PID)为:%d", [processInfo processIdentifier]);
        //获取该进程的进程名
        NSLog(@"该程序的进程名为:%@", [processInfo processName]);
        //设置该进程的新进程名
        [processInfo setProcessName:@"test"];
        NSLog(@"该程序的新进程名为:%@", [processInfo processName]);
        
        //获取运行该进程的系统的环境变量
        NSLog(@"运行该进程的系统的所有环境变量为:%@", [processInfo environment]);
        //获取运行该进程的主机名
        NSLog(@"运行该进程的主机名为:%@", [processInfo hostName]);
        //获取运行该进程的操作系统
        NSLog(@"运行该进程所在的操作系统为:%ld", [processInfo operatingSystem]);
        //获取运行该进程的操作系统的版本
        NSLog(@"运行该进程所在的操作系统名为:%@", [processInfo operatingSystemName]);
        //获取运行该进程的操作系统的版本
        NSLog(@"运行该进程所在的操作系统的版本为:%@", [processInfo operatingSystemVersionString]);
        
        //获取运行该进程的系统的物理内存
        NSLog(@"运行该进程的系统的物理内存为:%lld", [processInfo physicalMemory]);
        //获取运行该进程的系统的处理器数量
        NSLog(@"运行该进程的系统的处理器数量为:%ld", [processInfo processorCount]);
        //获取运行该进程的系统的处于激活状态的处理器数量
        NSLog(@"运行该进程的系统的处于激活状态的处理器数量为:%ld", [processInfo activeProcessorCount]);
        //获取运行该进程的系统已运行的时间
        NSLog(@"运行该进程的系统的已运行时间为:%f", [processInfo systemUptime]);
    }

 

 

2015-12-17 13:32:27.993 PhotoData[1769:88186] 运行该程序的参数为:(

    "/Users/ouka/Library/Developer/CoreSimulator/Devices/8286C39C-1B24-4854-AF48-CA68A6B0D182/data/Containers/Bundle/Application/98DE2D88-1AFB-4BFE-B7F3-BABC6E895073/PhotoData.app/PhotoData"

)

2015-12-17 13:32:27.993 PhotoData[1769:88186] 该程序的进程标示符(PID)为:1769

2015-12-17 13:32:27.993 PhotoData[1769:88186] 该程序的进程名为:PhotoData

2015-12-17 13:32:27.994 PhotoData[1769:88186] 该程序的新进程名为:test

2015-12-17 13:32:27.995 PhotoData[1769:88186] 运行该进程的系统的所有环境变量为:{

    "CFFIXED_USER_HOME" = "/Users/ouka/Library/Developer/CoreSimulator/Devices/8286C39C-1B24-4854-AF48-CA68A6B0D182/data/Containers/Data/Application/3BF58ECF-089F-4502-9033-7D9395B0E33A";

    "CFLOG_FORCE_STDERR" = YES;

    CLASSIC = 2;

    "CUPS_SERVER" = "/private/tmp/com.apple.launchd.PTj87fzPPz/Listeners";

    "DYLD_FALLBACK_FRAMEWORK_PATH" = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks";

    "DYLD_FALLBACK_LIBRARY_PATH" = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib";

    "DYLD_FRAMEWORK_PATH" = "/Users/ouka/Library/Developer/Xcode/DerivedData/PhotoData-fwnrcsmyuqwojoatgebsyefqxkkw/Build/Products/Debug-iphonesimulator";

    "DYLD_LIBRARY_PATH" = "/Users/ouka/Library/Developer/Xcode/DerivedData/PhotoData-fwnrcsmyuqwojoatgebsyefqxkkw/Build/Products/Debug-iphonesimulator:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/system/introspection";

    "DYLD_ROOT_PATH" = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk";

    "DYLD_SHARED_REGION" = avoid;

    FBSClientLogging = 0;

    HOME = "/Users/ouka/Library/Developer/CoreSimulator/Devices/8286C39C-1B24-4854-AF48-CA68A6B0D182/data/Containers/Data/Application/3BF58ECF-089F-4502-9033-7D9395B0E33A";

    "IOS_SIMULATOR_SYSLOG_SOCKET" = "/private/tmp/com.apple.CoreSimulator.SimDevice.8286C39C-1B24-4854-AF48-CA68A6B0D182.launchd_sim/syslogsock";

    "IPHONE_SHARED_RESOURCES_DIRECTORY" = "/Users/ouka/Library/Developer/CoreSimulator/Devices/8286C39C-1B24-4854-AF48-CA68A6B0D182/data";

    "IPHONE_SIMULATOR_CLASS" = N71;

    "IPHONE_SIMULATOR_DEVICE" = iPhone;

    "IPHONE_SIMULATOR_ROOT" = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk";

    "IPHONE_TVOUT_EXTENDED_PROPERTIES" = "/Users/ouka/Library/Developer/CoreSimulator/Devices/8286C39C-1B24-4854-AF48-CA68A6B0D182/data/Library/Application Support/iPhone Simulator/com.apple.iphonesimulator/extended_display.plist";

    NSUnbufferedIO = YES;

    PATH = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/sbin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/sbin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/local/bin";

    "SIMULATOR_CAPABILITIES" = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/CoreSimulator/Profiles/DeviceTypes/iPhone 6s.simdevicetype/Contents/Resources/capabilities.plist";

    "SIMULATOR_DEVICE_NAME" = iPhone4Simulator;

    "SIMULATOR_EXTENDED_DISPLAY_PROPERTIES" = "/Users/ouka/Library/Developer/CoreSimulator/Devices/8286C39C-1B24-4854-AF48-CA68A6B0D182/data/Library/Application Support/iPhone Simulator/com.apple.iphonesimulator/extended_display.plist";

    "SIMULATOR_HOST_HOME" = "/Users/ouka";

    "SIMULATOR_LEGACY_ASSET_SUFFIX" = iphone;

    "SIMULATOR_LOG_ROOT" = "/Users/ouka/Library/Logs/CoreSimulator/8286C39C-1B24-4854-AF48-CA68A6B0D182";

    "SIMULATOR_MAINSCREEN_HEIGHT" = 1334;

    "SIMULATOR_MAINSCREEN_PITCH" = "326.000000";

    "SIMULATOR_MAINSCREEN_SCALE" = "2.000000";

    "SIMULATOR_MAINSCREEN_WIDTH" = 750;

    "SIMULATOR_MEMORY_WARNINGS" = "/Users/ouka/Library/Developer/CoreSimulator/Devices/8286C39C-1B24-4854-AF48-CA68A6B0D182/data/var/run/memory_warning_simulation";

    "SIMULATOR_MODEL_IDENTIFIER" = "iPhone8,1";

    "SIMULATOR_PLATFORM_RUNTIME_OVERLAY_ROOT" = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/CoreSimulator/RuntimeOverlay";

    "SIMULATOR_ROOT" = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk";

    "SIMULATOR_RUNTIME_BUILD_VERSION" = 13C75;

    "SIMULATOR_RUNTIME_VERSION" = "9.2";

    "SIMULATOR_SHARED_RESOURCES_DIRECTORY" = "/Users/ouka/Library/Developer/CoreSimulator/Devices/8286C39C-1B24-4854-AF48-CA68A6B0D182/data";

    "SIMULATOR_UDID" = "8286C39C-1B24-4854-AF48-CA68A6B0D182";

    "SIMULATOR_VERSION_INFO" = "CoreSimulator 201.3 - Device: iPhone 6s - Runtime: iOS 9.2 (13C75) - DeviceType: iPhone 6s";

    "TESTMANAGERD_SIM_SOCK" = "/private/tmp/com.apple.launchd.Hd9yxjdGfC/com.apple.testmanagerd.unix-domain.socket";

    TMPDIR = "/Users/ouka/Library/Developer/CoreSimulator/Devices/8286C39C-1B24-4854-AF48-CA68A6B0D182/data/Containers/Data/Application/3BF58ECF-089F-4502-9033-7D9395B0E33A/tmp";

    "XPC_FLAGS" = 0x0;

    "XPC_SERVICE_NAME" = "UIKitApplication:io.objc.PhotoData[0x24c7]";

    "XPC_SIMULATOR_LAUNCHD_NAME" = "com.apple.CoreSimulator.SimDevice.8286C39C-1B24-4854-AF48-CA68A6B0D182.launchd_sim";

    "__XCODE_BUILT_PRODUCTS_DIR_PATHS" = "/Users/ouka/Library/Developer/Xcode/DerivedData/PhotoData-fwnrcsmyuqwojoatgebsyefqxkkw/Build/Products/Debug-iphonesimulator";

    "__XPC_DYLD_FRAMEWORK_PATH" = "/Users/ouka/Library/Developer/Xcode/DerivedData/PhotoData-fwnrcsmyuqwojoatgebsyefqxkkw/Build/Products/Debug-iphonesimulator";

    "__XPC_DYLD_LIBRARY_PATH" = "/Users/ouka/Library/Developer/Xcode/DerivedData/PhotoData-fwnrcsmyuqwojoatgebsyefqxkkw/Build/Products/Debug-iphonesimulator";

}

2015-12-17 13:32:28.377 PhotoData[1769:88186] 运行该进程的主机名为:cactus.local

2015-12-17 13:32:28.377 PhotoData[1769:88186] 运行该进程所在的操作系统为:5

2015-12-17 13:32:28.378 PhotoData[1769:88186] 运行该进程所在的操作系统名为:NSMACHOperatingSystem

2015-12-17 13:32:28.382 PhotoData[1769:88186] 运行该进程所在的操作系统的版本为:Version 9.2 (Build 13C75)

2015-12-17 13:32:28.382 PhotoData[1769:88186] 运行该进程的系统的物理内存为:8589934592

2015-12-17 13:32:28.383 PhotoData[1769:88186] 运行该进程的系统的处理器数量为:4

2015-12-17 13:32:28.383 PhotoData[1769:88186] 运行该进程的系统的处于激活状态的处理器数量为:4

2015-12-17 13:32:28.384 PhotoData[1769:88186] 运行该进程的系统的已运行时间为:12109.074797

 

你可能感兴趣的:(NSProcessInfo)