iOS获得系统的进程UIDevice Category For Processes.
来源:互联网 发布:php问卷调查系统源码 编辑:程序博客网 时间:2024/06/08 04:46
// .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].
- iOS获得系统的进程UIDevice Category For Processes.
- UIDevice Category For Processes
- UIDevice Category For Processes
- 获取iOS系统版本 --- UIDevice的使用
- 获取iOS系统版本 --- UIDevice的使用
- 获取iOS系统版本 --- UIDevice的使用
- UIDevice的一些实用的Category
- iOS的UIDevice
- iOS UIDevice的使用
- iPhone开发之-iPhone category for processes
- UIDevice-with-UniqueIdentifier-for-iOS-5
- iOS UIDevice保存的信息
- iOS UIDevice 的基本数据
- IOS获取设备系统信息(UIDevice,NSLocale)
- iOS 通过UIDevice 获取系统相关属性
- iOS-UIDevice
- UIDevice获取iOS有用的信息
- iOS [[UIDevice currentDevice] systemName]的返回值
- c#WINFORM中如何为动态生成的按钮加背景图片
- tar exclude的应用
- CRM八面体:客户关系管理成功案例1 荷兰皇家航空 KLM Royal Dutch Airlines
- Silverlight内存泄露工具
- 关于XCode编译完App之后生成的dSYM文件
- iOS获得系统的进程UIDevice Category For Processes.
- winform中怎么动态修改窗体的大小
- 日志的处理
- StoryBoard
- ubuntu 9.04 download address
- kindeditor4.1.4 asp.net C# 配置及相关使用技巧 附带读取txt文本方法
- C#CookieHelper--C#操作Cookie的帮助类
- navicat 结合快捷键
- 在sqlserver中如何从字符串中提取数字,英文,中文,过滤重复字符