【发布时间】:2017-06-26 08:06:23
【问题描述】:
我正在尝试在内核模块中获取进程启动时间。
我得到proc struct pointer,并从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 Internals 一书中写道:
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,000 然后除以 3600 以获得小时数,我得到 528 小时 22 天,但我的正常运行时间是 5 天..
【问题讨论】:
标签: c time solaris unix-timestamp high-resolution-clock