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 *processInfo = [NSProcessInfo processInfo]; NSDictionary *memoryInfo = [processInfo physicalMemory]; double totalMemory = [[memoryInfo objectForKey:NSProcessInfoPhysicalMemoryFree] ...
NSProcessInfo *processInfo = [NSProcessInfo processInfo]; NSDictionary *powerSourceInfo = [processInfo powerSourceInformation]; for (NSString *key in powerSourceInfo) { NSDictionary *sourceDict = ...
NSProcessInfo *processInfo = [NSProcessInfo processInfo]; NSUInteger totalMemory = processInfo.physicalMemory; NSUInteger usedMemory = processInfo.usedMemory; NSLog(@"总内存:%.2f GB", (double)total...
通过`[NSProcessInfo processInfo].physicalMemory`可得到总内存,而`[NSProcessInfo processInfo].usedMemory`则返回已使用的内存。请注意,这些值是以字节为单位的,通常需要转换为更易读的形式,如MB或GB。 4. *...
在iOS中,有多种实现多线程的方法,包括NSThread、NSOperationQueue、GCD(Grand Central Dispatch)以及NSProcessInfo的能源效率API。这些技术各有优缺点,但都允许开发者在应用中同时执行多个任务,以提高性能。 ...
NSProcessInfo *processInfo = [NSProcessInfo processInfo]; NSDictionary *physicalMemory = [processInfo physicalMemory]; double totalMemory = [physicalMemory[@"total"] doubleValue] / (1024.0 * 1024.0); ...
另外,`NSProcessInfo`的`physicalMemory`属性可以获取到设备的物理内存总量,但并不能直接得到当前可用的内存。 为了更准确地获取剩余内存,可以尝试使用`mach_vm_region_info`这样的内核任务API,但这同样属于...
但可以通过`NSProcessInfo`的`physicalMemory`属性获取应用程序可用的物理内存,这可以间接反映设备的总内存大小。 - 内存使用情况:可以监控`NSProcessInfo`的`usedMemory`属性来了解应用程序自身的内存占用。 4....
- 另一种方法是利用`NSProcessInfo`类,虽然它主要提供进程级别的信息,但`NSProcessInfo.processInfo.memoryInfo`可以提供当前进程的内存使用概况,包括驻留内存、虚拟内存等。 3. **性能优化与调试**: - 了解...
通过`NSProcessInfo`类的`disableAutomaticTermination:`方法和`EnergySaver`服务,可以防止系统进入待机模式。 在Android系统上,可以编程获取`PowerManager`对象,调用`newWakeLock()`方法创建一个唤醒锁,然后...
- 获取Mac地址:尽管在iOS 7之后,苹果出于隐私考虑,默认情况下不提供设备的物理MAC地址,但可以通过系统提供的`NSProcessInfo`类获取一个设备唯一标识符,即"私有MAC地址",用于内部网络通信。 2. **网络状态...
对于开发者来说,可以使用Apple的Foundation框架中的`NSProcessInfo`类或Objective-C的`SystemConfiguration`框架来获取MAC地址。 描述中提到的“简单加密”,可能是指对MAC地址进行某种形式的哈希或编码,以便...
但可以使用`NSProcessInfo`的`physicalMemory`属性获取设备的物理内存信息,间接了解设备的一些硬件特性。 3. **IP地址**: IP地址是互联网协议地址,用于标识设备在网络中的位置。在iOS中,可以通过`CTBonjour`或者...
4. **系统调用与API**:为了监控和控制CPU使用,开发者可能使用了Mac OS提供的系统调用(如`kern_return_t task_info()`)或公开API(如`NSProcessInfo`类)来获取和设置进程的资源限制。 5. **权限管理**:由于...
为了监控iOS设备的当前可用内存,开发者可以使用Apple提供的Core Services框架中的`NSProcessInfo`类。这个类提供了关于当前进程及其环境的信息,包括内存使用情况。例如,通过`processInfo.memoryStatus`属性,我们...
2. `Foundation`: Swift的基础框架,包含了许多与系统交互的类,如`NSProcessInfo`可以获取操作系统信息。 3. `IOKit`: 用于硬件访问的C语言框架,可能会在更底层的系统信息获取中发挥作用。 了解Archey的工作原理...
Swift中的NSProcessInfo类可以帮助我们获取当前运行的进程信息,而注入代码到其他应用则涉及到了动态库注入技术,这在iOS开发中是一项挑战,需要深入理解iOS沙盒机制和进程间通信。 二、修改微信运动步数 微信运动...
在iOS中,使用`NSProcessInfo.processInfo().isProtectedDataAvailable`检查数据保护状态,并使用`NSAppTransportSecurity`处理网络请求的安全策略。 6. **手表连接管理**:在`WKSession`的帮助下,我们可以管理...
NSProcessInfo.processInfo().environment["com.apple.developer.icloud-container-identifiers"] : nil { if userInfo != nil { // 处理截屏事件,例如显示提示信息 print("截屏事件发生") } } } deinit ...
client = SwiftMQTTClient(clientId: NSProcessInfo().globallyUniqueString, account: SwiftMQTTAccount(username: "tripleCC", password: "cg"), keepalive: 90) 设置连接地址与端口 client?.connectToHost(...