在内核模块 solaris 中获取进程启动时间
get process start time in kernel module solaris
我正在尝试在内核模块中获取进程启动时间。
我得到 proc struct pointer,并从过程中获取字段 p_mstart ()
typedef struct proc {
.....
/*
* Microstate accounting, resource usage, and real-time profiling
*/
hrtime_t p_mstart; /* hi-res process start time */
这个return我的号码: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 天..
基于 google 组收到的回答:comp.unix.solaris。
而不是去处理 -> p_mstart
我需要服用
iterated_process_ptr ->p_user.u_start
这给我带来了与用户空间相同的结构 (timestruc_t)
typedef struct psinfo {
psinfo ->pr_start; /* process start time, from the epoch */
数字1976026375725303根本没有意义
是的。根据您引用的文档:
Time is expressed as nanoseconds since some arbitrary time in the
past.
因此,该值可用于计算进程开始的时间:
hrtime_t howLongAgo = gethrtime() - p->p_mstart;
这会产生一个以纳秒为单位的值,表示进程开始前的时间。
请注意,生成的值是准确的 - 来自 iterated_process_ptr ->p_user.u_start
的值受系统时钟变化的影响,所以你不能说,"This process has been running for 3 hours, 15 minutes, and 3 seconds" 除非你也知道系统时钟没有'没有以任何方式重置或修改。
根据 Solaris 11 gethrtime.9F man page:
Description
The gethrtime()
function returns the current high-resolution real
time. Time is expressed as nanoseconds since some arbitrary time in
the past; it is not correlated in any way to the time of day, and
thus is not subject to resetting or drifting by way of adjtime(2)
or
settimeofday(3C)
. The hi-res timer is ideally suited to performance
measurement tasks, where cheap, accurate interval timing is required.
Return Values
gethrtime()
always returns the current high-resolution real time.
There are no error conditions.
...
Notes
Although the units of hi-res time are always the same (nanoseconds),
the actual resolution is hardware dependent. Hi-res time is guaranteed
to be monotonic (it does not go backward, it does not periodically
wrap) and linear (it does not occasionally speed up or slow down for
adjustment, as the time of day can), but not necessarily unique: two
sufficiently proximate calls might return the same value.
The time base used for this function is the same as that for
gethrtime(3C)
. Values returned by both of these functions can be
interleaved for comparison purposes.
我正在尝试在内核模块中获取进程启动时间。
我得到 proc struct pointer,并从过程中获取字段 p_mstart ()
typedef struct proc {
.....
/*
* Microstate accounting, resource usage, and real-time profiling
*/
hrtime_t p_mstart; /* hi-res process start time */
这个return我的号码: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 天..
基于 google 组收到的回答:comp.unix.solaris。
而不是去处理 -> p_mstart
我需要服用
iterated_process_ptr ->p_user.u_start
这给我带来了与用户空间相同的结构 (timestruc_t)
typedef struct psinfo {
psinfo ->pr_start; /* process start time, from the epoch */
数字1976026375725303根本没有意义
是的。根据您引用的文档:
Time is expressed as nanoseconds since some arbitrary time in the past.
因此,该值可用于计算进程开始的时间:
hrtime_t howLongAgo = gethrtime() - p->p_mstart;
这会产生一个以纳秒为单位的值,表示进程开始前的时间。
请注意,生成的值是准确的 - 来自 iterated_process_ptr ->p_user.u_start
的值受系统时钟变化的影响,所以你不能说,"This process has been running for 3 hours, 15 minutes, and 3 seconds" 除非你也知道系统时钟没有'没有以任何方式重置或修改。
根据 Solaris 11 gethrtime.9F man page:
Description
The
gethrtime()
function returns the current high-resolution real time. Time is expressed as nanoseconds since some arbitrary time in the past; it is not correlated in any way to the time of day, and thus is not subject to resetting or drifting by way ofadjtime(2)
orsettimeofday(3C)
. The hi-res timer is ideally suited to performance measurement tasks, where cheap, accurate interval timing is required.Return Values
gethrtime()
always returns the current high-resolution real time. There are no error conditions....
Notes
Although the units of hi-res time are always the same (nanoseconds), the actual resolution is hardware dependent. Hi-res time is guaranteed to be monotonic (it does not go backward, it does not periodically wrap) and linear (it does not occasionally speed up or slow down for adjustment, as the time of day can), but not necessarily unique: two sufficiently proximate calls might return the same value.
The time base used for this function is the same as that for
gethrtime(3C)
. Values returned by both of these functions can be interleaved for comparison purposes.