首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在内核模块solaris中获取进程启动时间

在内核模块solaris中获取进程启动时间
EN

Stack Overflow用户
提问于 2017-06-26 08:06:23
回答 2查看 432关注 0票数 2

我试图在内核模块中获得进程启动时间。

我得到了proc结构指针,并从proc获得了字段p_mstart ()

代码语言:javascript
复制
typedef struct  proc {
.....
/*
* Microstate accounting, resource usage, and real-time profiling
*/
hrtime_t p_mstart;      /* hi-res process start time */

这把号码: 1976026375725303还给我

代码语言:javascript
复制
struct proc* iterated_process_ptr = curproc
LOG("***KERNEL***: PID=%d, StartTime=%lld",iterated_process_ptr->p_pidp->pid_id, iterated_process_ptr->p_mstart);

这个号码是多少?solaris在文档中写道:

代码语言:javascript
复制
The gethrtime() function returns the current high-resolution real time. Time is expressed as nanoseconds since some arbitrary time in the past.

在他们写的“Solaris内部”一书中:

代码语言:javascript
复制
Within the process, the operating system maintains a high-resolution teimstamp that marks process start and terminate times, A p_mstart field, the process start time, is set in the kernel fork() code when the process is created.... it return 64-bit value expressed in nanosecond

数字1976026375725303一点意义都没有。

如果我除以1,000,000,然后再除以3600,为了得到时间,我可以得到528小时22天,但我的正常运行时间是5天。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-26 08:50:03

根据谷歌集团收到的答案: comp.unix.solaris。

而不是去proc -> p_mstart

我要去拿

代码语言:javascript
复制
iterated_process_ptr ->p_user.u_start  

这给我带来了与用户空间相同的结构(timestruc_t)。

代码语言:javascript
复制
typedef struct psinfo {  

psinfo ->pr_start;  /* process start time, from the epoch */
票数 1
EN

Stack Overflow用户

发布于 2017-06-26 10:43:33

数字1976026375725303一点意义都没有。

是的,确实如此。根据你引用的文件:

时间表示为纳秒,因为在过去的一些任意时间。

因此,可以使用该值来计算进程开始的时间:

代码语言:javascript
复制
hrtime_t howLongAgo = gethrtime() - p->p_mstart;

这将产生一个以纳秒为单位的值,用于处理开始的时间。

请注意,生成的值是准确的--来自iterated_process_ptr ->p_user.u_start的值受系统时钟更改的影响,因此您不能说,“该进程已运行了3小时、15分钟和3秒”,除非您还知道系统时钟没有以任何方式被重置或修改。

根据Solaris 11 getertime.9F手册页

描述 gethrtime()函数返回当前的高分辨率实时.时间表示为自过去某些任意时间以来的纳秒;它与一天中的时间没有任何关联,因此不受adjtime(2)settimeofday(3C)的重置或漂移的影响。高精度定时器非常适合于性能测量任务,在那里需要廉价、准确的间隔计时。 返回值 gethrtime()总是实时返回当前的高分辨率.没有错误条件。 ..。 Notes 虽然高分辨率时间的单位总是相同的(纳秒),实际的分辨率是硬件依赖的。保证时间是单调的(不向后,不定期包装)和线性(不像一天中的时间那样,偶尔加速或减速以进行调整),但不一定是唯一的:两个足够近的调用可能返回相同的值。 用于此函数的时间基与用于gethrtime(3C)的时间基相同。这两个函数返回的值都可以交织起来,以便进行比较。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44755358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档