iOS 9已下的获取APP进程信息
- (NSDictionary *)getAppInfo:(NSString *)exec withBundleID:(NSString *)bundle
{
if ([exec isKindOfClass:[NSTimer class]])
{
exec = [(NSTimer *)exec userInfo];
}
NSDictionary * ret = nil; int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, };
u_int miblen = ;
size_t size = ;
int st = ;
struct kinfo_proc * process = NULL;
struct kinfo_proc * newprocess = NULL; sysctl(mib, miblen, NULL, &size, NULL, ); do
{
size += size / ;
newprocess = realloc(process, size);
if (!newprocess)
{
if (process)
{
free(process);
}
return ret;
}
process = newprocess;
st = sysctl(mib, miblen, process, &size, NULL, );
}
while (st == - && errno == ENOMEM);
if (st == )
{
if (size % sizeof(struct kinfo_proc) == )
{
unsigned long nprocess = size / sizeof(struct kinfo_proc);
if (nprocess)
{
for (long i = nprocess - ; i >= ; i --)
{
NSString * procExecName = [NSString stringWithCString:process[i].kp_proc.p_comm encoding:NSUTF8StringEncoding];
NSString * procBundleId = bundle;
long timeInterval = process[i].kp_proc.p_un.__p_starttime.tv_sec; // !!!:时间转化
NSDateFormatter * format = [[NSDateFormatter alloc] init];
[format setDateStyle:NSDateFormatterMediumStyle];
[format setTimeStyle:NSDateFormatterShortStyle];
[format setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS'Z'"];
NSTimeZone * timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[format setTimeZone:timeZone]; NSDate * oldTime = [NSDate dateWithTimeIntervalSince1970:timeInterval];
NSDate * nowTime = [NSDate date];
NSString * procSTime = [format stringFromDate:oldTime];
NSString * procETime = [format stringFromDate:nowTime]; int t = [nowTime timeIntervalSince1970] - timeInterval;
NSString * procUTime = [[NSNumber numberWithInt:t] stringValue];
// bundleid, execName, stime, etime,utime
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
[dic setObject:procExecName forKey:@"KPROCEXECNAME"];
[dic setValue:procBundleId forKey:@"KPROBUNDLEID"];
[dic setValue:procSTime forKey:@"KPROCSTIME"];
[dic setValue:procETime forKey:@"kPROCETIME"];
[dic setValue:procUTime forKey:@"KPROCUTIME"]; ret = [NSDictionary dictionaryWithDictionary:dic];
} free(process); return ret;
}
}
} free(process);
return ret;
}
需要的头文件为:
#import <sys/sysctl.h>
iOS 9已下的获取APP进程信息的更多相关文章
- C# Process获取当前进程信息
1.获取当前进程信息整理 Process.GetCurrentProcess(),返回当前程序的进程对象. Process cur = Process.GetCurrentProcess(); //当 ...
- 获取app崩溃信息的途径 iOS
获取崩溃日志的几种方法: 1.当用户抱怨闪退时,你可以要求他让设备与iTunes同步,设备与电脑上的iTunes Store同步后,会将崩溃日志保存在电脑上(路径:Mac OS X:~/Library ...
- 获取windows进程信息及CListCtrl控件(List Control)练习
环境:VS2010/MFC/对话框 效果图: 目录: 1. 关于windows进程信息获取 2. CListCtrl的使用 ------------------------------------ ...
- iOS 获取app进程被杀死事件
程序被用户双击上滑杀死后,就对app做一些特殊的处理 下面的方法可以获取到用户双击上滑杀死的事件 - (void)applicationDidEnterBackground:(UIApplicatio ...
- iOS 获取APP相关信息 私有API
/* Generated by RuntimeBrowser Image: /System/Library/Frameworks/MobileCoreServices.framework/Mobile ...
- cordova获取app版本信息插件的使用:cordova-plugin-app-version
1. 添加插件: cordova plugin add cordova-plugin-app-version 2. 调用方法: //获取当前文件的版本号: document.addEventListe ...
- 获取app安装信息私有api
@class LSApplicationProxy, NSArray, NSDictionary, NSProgress, NSString, NSURL, NSUUID; @interface LS ...
- python调用win32com.client的GetObject查找进程信息及服务信息
为何不用wmi呢?因为执行很慢,为啥不用winreg?因为winreg在批量获取及遍历服务方面很不方便,于是采用这方法 该方法同命令行下的wmic执行 获取服务信息 #coding=utf8 from ...
- jps不显示java进程信息
本来想自己整理,发现已经有前人整理,并且完美解决了我的问题,故转载,感谢分享 转自:http://trinea.iteye.com/blog/1196400 对于jps较熟悉可以直接查看第二部分的分析 ...
随机推荐
- Drupal 有用的模块
投票模块drigg https://www.drupal.org/project/drigg
- awk 统计
命令太多,记不住,组合起来用一把…..示例文件: 1 2 3 4 5 6 7 8 9 10 11 [root@lovedan test]# cat a.txt hello good world hel ...
- 支持C++11标准
设置CB下的GCC. Settings->Compiler->Compiler Settings勾选Have g++ follow the C++11 ISO C++ language s ...
- javascript好文---深入理解定位父级offsetParent及偏移大小
前面的话 偏移量(offset dimension)是javascript中的一个重要的概念.涉及到偏移量的主要是offsetLeft.offsetTop.offsetHeight.offsetWid ...
- mac mysql忘记密码解决办法
http://www.jb51.net/article/87580.htm http://blog.csdn.net/soft2buy/article/details/50223373
- 【转】css浮动元素的知识
原文: http://www.cnblogs.com/xuyao100/p/8940958.html ------------------------------------------------- ...
- Redis及其Sentinel配置项详细说明
Redis及其Sentinel配置项详细说明 http://lixiaohui.iteye.com/blog/2315516
- linux中ERROR: The partition with /var/lib/mysql is too full!解决的方法
今天在ubuntu上遇见这个问题.应该是我的第一分区太小了. 解决的方法: bey0nd@wzw:/var$ cd /var bey0nd@wzw:/var$ rm -rf log 我们删除日志文件 ...
- hibernate的注解装配
1.多对多,(中间表不用映射) @ManyToMany @JoinTable(name = "中间表名", joinColumns = { @JoinColumn(name = & ...
- react 自定义 百度地图(BMap)组件
1.html 页面引入 相关js public/index.html <!DOCTYPE html> <html lang="en"> <head&g ...