struct proc中starttime和solaris中struct psinfo_t的比较
comparison between starttime in struct proc and struct psinfo_t in solaris
在 Solaris 中,
我需要从内核 space 和用户 space.
获取进程启动时间
我找到给定进程的 2 个开始时间,它们不相等!
一个位于 proc struct (link is old but the struct almost identical) and one is on ps_info struct.
在执行期间,在内核 space 中,如果我使用
struct proc* iterated_process_ptr = curproc;
我得到以下结构:
typedef struct proc {
/*
* Microstate accounting, resource usage, and real-time profiling
*/
hrtime_t p_mstart; /* hi-res process start time */
如果我从用户 space 中填充 psinfo_t 结构如下:
char psfile[64];
psinfo_t psinfo;
sprintf(psfile, "/proc/ProcessID/psinfo");
if ((fd = open(psfile, O_RDONLY)) >= 0)
if (read(fd, &psinfo, sizeof(psinfo_t)) != -1)
struct psinfo 已填充,看起来像:
typedef struct psinfo {
timestruc_t pr_start; /* process start time, from the epoch */
2个开始时间有什么区别?
如果我对同一个进程执行此操作,则值不同,这意味着高分辨率进程开始时间与进程纪元开始时间不同。
什么是高分辨率进程启动?
谢谢
fork()
系统调用下结构is filled in here in OpenSolaris (see line 1008)的p_mstart
字段:
/*
* Make proc entry for child process
*/
mutex_init(&cp->p_splock, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&cp->p_crlock, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&cp->p_pflock, NULL, MUTEX_DEFAULT, NULL);
#if defined(__x86)
mutex_init(&cp->p_ldtlock, NULL, MUTEX_DEFAULT, NULL);
#endif
mutex_init(&cp->p_maplock, NULL, MUTEX_DEFAULT, NULL);
cp->p_stat = SIDL;
cp->p_mstart = gethrtime();
cp->p_as = &kas;
Per the man page for gethrtime()
:
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
因此,p_mstart
字段填充了一个时间,通过与当前调用的 return 值的差异,该时间可用于确定进程开始前的确切纳秒数到 gethrtime()
:
hrtime_t duration = gethrtime - p->p_mstart;
在 Solaris 中,
我需要从内核 space 和用户 space.
获取进程启动时间
我找到给定进程的 2 个开始时间,它们不相等!
一个位于 proc struct (link is old but the struct almost identical) and one is on ps_info struct.
在执行期间,在内核 space 中,如果我使用
struct proc* iterated_process_ptr = curproc;
我得到以下结构:
typedef struct proc {
/*
* Microstate accounting, resource usage, and real-time profiling
*/
hrtime_t p_mstart; /* hi-res process start time */
如果我从用户 space 中填充 psinfo_t 结构如下:
char psfile[64];
psinfo_t psinfo;
sprintf(psfile, "/proc/ProcessID/psinfo");
if ((fd = open(psfile, O_RDONLY)) >= 0)
if (read(fd, &psinfo, sizeof(psinfo_t)) != -1)
struct psinfo 已填充,看起来像:
typedef struct psinfo {
timestruc_t pr_start; /* process start time, from the epoch */
2个开始时间有什么区别?
如果我对同一个进程执行此操作,则值不同,这意味着高分辨率进程开始时间与进程纪元开始时间不同。
什么是高分辨率进程启动?
谢谢
fork()
系统调用下结构is filled in here in OpenSolaris (see line 1008)的p_mstart
字段:
/*
* Make proc entry for child process
*/
mutex_init(&cp->p_splock, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&cp->p_crlock, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&cp->p_pflock, NULL, MUTEX_DEFAULT, NULL);
#if defined(__x86)
mutex_init(&cp->p_ldtlock, NULL, MUTEX_DEFAULT, NULL);
#endif
mutex_init(&cp->p_maplock, NULL, MUTEX_DEFAULT, NULL);
cp->p_stat = SIDL;
cp->p_mstart = gethrtime();
cp->p_as = &kas;
Per the man page for gethrtime()
:
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
因此,p_mstart
字段填充了一个时间,通过与当前调用的 return 值的差异,该时间可用于确定进程开始前的确切纳秒数到 gethrtime()
:
hrtime_t duration = gethrtime - p->p_mstart;