我试图在内核模块中获得进程启动时间。
我得到了proc结构指针,并从proc获得了字段p_mstart ()
typedef struct proc {
.....
/*
* Microstate accounting, resource usage, and real-time profiling
*/
hrtime_t p_mstart; /* hi-res process start time */这把号码: 1976026375725303还给我
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在文档中写道:
The gethrtime() function returns the current high-resolution real time. Time is expressed as nanoseconds since some arbitrary time in the past.在他们写的“Solaris内部”一书中:
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天。
发布于 2017-06-26 08:50:03
根据谷歌集团收到的答案: comp.unix.solaris。
而不是去proc -> p_mstart
我要去拿
iterated_process_ptr ->p_user.u_start 这给我带来了与用户空间相同的结构(timestruc_t)。
typedef struct psinfo {
psinfo ->pr_start; /* process start time, from the epoch */发布于 2017-06-26 10:43:33
数字1976026375725303一点意义都没有。
是的,确实如此。根据你引用的文件:
时间表示为纳秒,因为在过去的一些任意时间。
因此,可以使用该值来计算进程开始的时间:
hrtime_t howLongAgo = gethrtime() - p->p_mstart;这将产生一个以纳秒为单位的值,用于处理开始的时间。
请注意,生成的值是准确的--来自iterated_process_ptr ->p_user.u_start的值受系统时钟更改的影响,因此您不能说,“该进程已运行了3小时、15分钟和3秒”,除非您还知道系统时钟没有以任何方式被重置或修改。
描述
gethrtime()函数返回当前的高分辨率实时.时间表示为自过去某些任意时间以来的纳秒;它与一天中的时间没有任何关联,因此不受adjtime(2)或settimeofday(3C)的重置或漂移的影响。高精度定时器非常适合于性能测量任务,在那里需要廉价、准确的间隔计时。 返回值gethrtime()总是实时返回当前的高分辨率.没有错误条件。 ..。 Notes 虽然高分辨率时间的单位总是相同的(纳秒),实际的分辨率是硬件依赖的。保证时间是单调的(不向后,不定期包装)和线性(不像一天中的时间那样,偶尔加速或减速以进行调整),但不一定是唯一的:两个足够近的调用可能返回相同的值。 用于此函数的时间基与用于gethrtime(3C)的时间基相同。这两个函数返回的值都可以交织起来,以便进行比较。
https://stackoverflow.com/questions/44755358
复制相似问题