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较熟悉可以直接查看第二部分的分析 ...
随机推荐
- AC日记——【模板】线段树 1 洛谷 P3372
题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数加上x 2.求出某区间每一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个 ...
- git移除上一次的commit中误添加的文件
在使用git进行版本管理时,往往会出现一些误操作,比如将一些不加上传的文件放到了暂存区,即上传到了上一次commit中 比如: commit c134ab90ca7c4daf8bfa22e3ad706 ...
- 用线段树写Dijkstar
如题 noip前就想用线段树优化Dijkstar 写那啥,感觉挺好玩的 写了个线段树优化的Dijkstar #include<cstdio> #include<cstring> ...
- [转] 常用SQL查询语句
sunada 的原文地址 常用SQL查询语句 一.简单查询语句 1. 查看表结构 SQL>DESC emp; 2. 查询所有列 SQL>SELECT * FROM emp; 3. 查询指 ...
- Android gradle 相关配置
有时候我们需要重命名输出apk文件名,在Android studio 3.0以前我们是这样写的: applicationVariants.all { variant -> variant.out ...
- 使用find命令查找Linux中的隐藏文件的方法
我们可以在Linux 或者 Unix 系统上使用 find 命令去查询所有(全部)隐藏文件 基本语法如下: 复制代码 代码如下: [root@dabu.info ~]#find /要查找的文/件/夹/ ...
- 采用scp命令在Linux系统之间copy文件
不同的Linux之间copy文件常用有3种方法,第一种就是ftp,也就是其中一台Linux安装ftp Server,这样可以另外一台使用ftp的client程序来进行文件的copy.第二种方法就是采用 ...
- Redis Sentinel 情况下bind地址设置
Redis Sentinel 情况下bind地址设置 1个master,2个slave,3个sentinel的情况下,注意bind地址的时候不要写0.0.0.0,会导致绑定多个地址, 然后sentin ...
- [C++11]_[0基础]_[左值引用声明和右值引用声明]
场景: 在 remove_reference 结构体中能看到右值引用的身影 &&, 那么这里的右值引用究竟有什么用呢? 常常也发现int& 和int&& 这两种 ...
- AngularJS的简单表单验证
代码下载:https://files.cnblogs.com/files/xiandedanteng/angularjsCheckSimpleForm.rar 代码: <!DOCTYPE HTM ...