UIDevice Category For Processes
来源:互联网 发布:java infinity 编辑:程序博客网 时间:2024/05/18 03:50
// .h @interface UIDevice (ProcessesAdditions)- (NSArray *)runningProcesses;@end // .m#import <sys/sysctl.h> @implementation UIDevice (ProcessesAdditions) - (NSArray *)runningProcesses { int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};size_t miblen = 4;size_t size;int st = sysctl(mib, miblen, NULL, &size, NULL, 0);struct kinfo_proc * process = NULL;struct kinfo_proc * newprocess = NULL; do { size += size / 10; newprocess = realloc(process, size); if (!newprocess){ if (process){ free(process); } return nil; } process = newprocess; st = sysctl(mib, miblen, process, &size, NULL, 0); } while (st == -1 && errno == ENOMEM);if (st == 0){if (size % sizeof(struct kinfo_proc) == 0){int nprocess = size / sizeof(struct kinfo_proc);if (nprocess){NSMutableArray * array = [[NSMutableArray alloc] init];for (int i = nprocess - 1; i >= 0; i--){NSString * processID = [[NSString alloc] initWithFormat:@"%d", process[i].kp_proc.p_pid];NSString * processName = [[NSString alloc] initWithFormat:@"%s", process[i].kp_proc.p_comm];NSDictionary * dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:processID, processName, nil] forKeys:[NSArray arrayWithObjects:@"ProcessID", @"ProcessName", nil]];[processID release];[processName release];[array addObject:dict];[dict release];}free(process);return [array autorelease];}}}return nil;} @end // Example usage.NSArray * processes = [[UIDevice currentDevice] runningProcesses];for (NSDictionary * dict in processes){NSLog(@"%@ - %@", [dict objectForKey:@"ProcessID"], [dict objectForKey:@"ProcessName"]);}
A UIDevice category for getting the running processes on an iOS device.
Based on something floating about on the web by Landon Fuller.
Cleaned it up a bit and changed so it returns an NSArray of NSDictionary[s].
文章转自:http://zurb.com/forrst/posts/UIDevice_Category_For_Processes-h1H
0 0
- UIDevice Category For Processes
- UIDevice Category For Processes
- iOS获得系统的进程UIDevice Category For Processes.
- iPhone开发之-iPhone category for processes
- UIDevice的一些实用的Category
- Gaussian Processes for Regression
- UIDevice
- UIDevice
- UIDevice
- UIDevice
- UIDevice-with-UniqueIdentifier-for-iOS-5
- Processes
- Processes
- Notes for Advanced Linux Programming - 3. Processes
- Number of Processes(Workers) for Concurrent Manager
- Seminar《Diffusion Processes for Retrieval Revisited》
- Finddll.c - searches are running processes For module occurrency
- CMM in Practice: Processes for Executing Software Projects at Infosys
- 在jstl标签中forEach标签遍历Map
- 【codeforces】Codeforces Round #291 (Div. 2) 题解
- 小马哥---高仿苹果5S 6572芯片 拆机图H5s型号 版本多
- Photoshop入门教程(四):混合模式
- 第一泡吧
- UIDevice Category For Processes
- [计算几何]poj 2308 Toys
- The web project path
- [LeetCode]Max Points on a Line
- 【java编程】Collections工具类之复写Fill实现部分替换
- Scala类型 6:复合类型 & with关键字
- rm 命令
- Self-aware value network in the context of i4.0 工业4.0背景下,具有感知能力的价值网络
- Linux 学习笔记(二)Linux vi以及vim命令详解