- (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. CSS-文本(中,英)

    1.缩进文本:text-indent 2.水平对齐:text-align:  left/center/right/justify(实现两端对齐文本效果) 3.字间隔:word-spacing(可以改变 ...

  2. PAT甲级练习题1001、1002

    1001 A+B Format (20 分)   Calculate a+b and output the sum in standard format -- that is, the digits ...

  3. ssm框架 spring的主配置文件 spring-mvc主配置文件 web.xml配置文件(基础的配置文件)

    1.spring主配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...

  4. Druid连接池工具类

    package cn.zmh.PingCe; import com.alibaba.druid.pool.DruidDataSourceFactory; import javax.sql.DataSo ...

  5. commons-lang3-RandomUtils

    随机工具类   RandomUtils nextBoolean() 返回一个随机boolean值 nextBytes(int count) 返回一个指定大小的随机byte数组 nextDouble() ...

  6. Play框架连接Mysql遇到的一些问题

    最近,在基于Play框架的项目中需要连接Mysql数据库.在这个过程中遇到了一些问题.在此,把它记录下来. 首先,Play框架和Mysql连接有两种方式,这两种方式都是在application.con ...

  7. Windows系统文件详解【大全】

    这是网络上转载的一篇文章,找不到原创的出处了--详细的介绍了WINDOWS系统文件的用途,我想各位保存一份以后说不定会有用吧,呵呵..这里按A到Z为大家分好类了,查询的话可以按键盘的Ctrl+F进行搜 ...

  8. Java中char转为16进制

    Java中char转为16进制 char a = '0'; String hexStr = Integer.toHexString(a); System.out.println(hexStr);

  9. C#中如何让ListView控件点击选中整行

    将Listview控件的FullRowSelect属性置为True,当然Listview的View属性应该是Details. 2017年6月25日17:15:55

  10. 关于 AlphaGo 论文的阅读笔记

    这是Deepmind 公司在2016年1月28日Nature 杂志发表论文 <Mastering the game of Go with deep neural networks and tre ...