使用 C/C++ 在 OSX 中获取进程创建日期时间 [英] Get process creation date-time in OSX with C / C++

查看:95
本文介绍了使用 C/C++ 在 OSX 中获取进程创建日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个进程ID,使用C/C ++查找该进程的创建日期时间的最佳方法是什么?

Given a process id, what is the best way to find the process's creation date-time using C/C++ ?

推荐答案

我建议您查看 ps 源代码(尤其是 libtop.c ).

I'd suggest looking at the top and ps source code (in particular, libtop.c).

认为以下呼叫应该是您所需要的:

I think the following call should be what you need:

int proc_pidbsdinfo(proc_t p, struct proc_bsdinfo *pbsd, int zombie);

来自< sys/proc_info.h> :

struct proc_bsdinfo {
...
    struct timeval      pbi_start;
...
}

不幸的是,没有用于过程检查的公共接口,因此调用不仅依赖于版本,而且在将来的发行版中可能会更改.

Unfortunately there is no public interface for process inspection so the calls are not only version-dependant but also likely to change in future releases.

这篇关于使用 C/C++ 在 OSX 中获取进程创建日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆