- (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进程信息的更多相关文章

  1. C# Process获取当前进程信息

    1.获取当前进程信息整理 Process.GetCurrentProcess(),返回当前程序的进程对象. Process cur = Process.GetCurrentProcess(); //当 ...

  2. 获取app崩溃信息的途径 iOS

    获取崩溃日志的几种方法: 1.当用户抱怨闪退时,你可以要求他让设备与iTunes同步,设备与电脑上的iTunes Store同步后,会将崩溃日志保存在电脑上(路径:Mac OS X:~/Library ...

  3. 获取windows进程信息及CListCtrl控件(List Control)练习

    环境:VS2010/MFC/对话框 效果图: 目录: 1.  关于windows进程信息获取 2.  CListCtrl的使用 ------------------------------------ ...

  4. iOS 获取app进程被杀死事件

    程序被用户双击上滑杀死后,就对app做一些特殊的处理 下面的方法可以获取到用户双击上滑杀死的事件 - (void)applicationDidEnterBackground:(UIApplicatio ...

  5. iOS 获取APP相关信息 私有API

    /* Generated by RuntimeBrowser Image: /System/Library/Frameworks/MobileCoreServices.framework/Mobile ...

  6. cordova获取app版本信息插件的使用:cordova-plugin-app-version

    1. 添加插件: cordova plugin add cordova-plugin-app-version 2. 调用方法: //获取当前文件的版本号: document.addEventListe ...

  7. 获取app安装信息私有api

    @class LSApplicationProxy, NSArray, NSDictionary, NSProgress, NSString, NSURL, NSUUID; @interface LS ...

  8. python调用win32com.client的GetObject查找进程信息及服务信息

    为何不用wmi呢?因为执行很慢,为啥不用winreg?因为winreg在批量获取及遍历服务方面很不方便,于是采用这方法 该方法同命令行下的wmic执行 获取服务信息 #coding=utf8 from ...

  9. jps不显示java进程信息

    本来想自己整理,发现已经有前人整理,并且完美解决了我的问题,故转载,感谢分享 转自:http://trinea.iteye.com/blog/1196400 对于jps较熟悉可以直接查看第二部分的分析 ...

随机推荐

  1. String()和.toString()的区别

    一.相同点:都可以转为字符串类型: 二.不同点: 1..toString() :null.toString()和undefined.toString() 程序报错误; 2..toString(): . ...

  2. ML | PCA

    what's xxx PCA principal components analysis is for dimensionality reduction. 主要是通过对协方差矩阵Covariance ...

  3. luogu P1310 表达式的值

    题目描述 对于1 位二进制变量定义两种运算: 运算的优先级是: 先计算括号内的,再计算括号外的. “× ”运算优先于“⊕”运算,即计算表达式时,先计算× 运算,再计算⊕运算.例如:计算表达式A⊕B × ...

  4. 【APIO2016】Gap

    题目描述 有 $N$ 个严格递增的非负整数 $a_1, a_2, \dots, a_N$($0 \leq a_1 < a_2 < \cdots < a_N \leq 10^{18}$ ...

  5. 浅析PropertySource 基本使用

    目录 一.PropertySource 简介 二.@PropertySource与Environment读取配置文件 三.@PropertySource与@Value读取配置文件 四.@Propert ...

  6. Don't Panic! KRACK 没你想象的那么糟

    上海交通大学密码与计算机安全实验室(LoCCS)软件安全小组(GoSSIP)版权所有,转载请与作者取得联系! 著名的计算机学术安全会议CCS在2017年录用了一篇名为Key Reinstallatio ...

  7. netd ResponseCode

    100 Requestion action was initiated; expect another reply before proceeding with a new command. 200 ...

  8. C# 将链表存入二进制文件及读取二进制文件得到链表示例

    // 将tasks保存到二进制文件中 public Boolean saveToFile(String file) { try { ) { // 没任务就不存 return false; } if ( ...

  9. Android二维码工具zxing使用

    二维码在我们生活中随处可见.在我眼里简直能够用"泛滥"来形容啦.那怎样在我们Android项目中扫描识别二维码或生成二维码图片呢? 我们通常使用的开源框架是zxing.在githu ...

  10. 百度地图SDK调试SDKInitializer.initialize(getApplicationContext())错误

    首先描写叙述下问题出现的原因.開始的时候写了一个百度地图SDK的demo来试功能,由于最開始用的是Eclipse自带的AVD来调试,一切正常. 都能够正常验证,可是由于受不了重复的重新启动AVD设备, ...