#include clock_t times(struct tms *buf);
|
clock_t就是返回的ticks的值,在一般的linux定义中,它是long的typedef。
unsigned long ticks = (unsigned long) times( NULL ); |
ticks的时间精度,如下方法:
unsigned long HZ = sysconf( _SC_CLK_TCK ); |
它返回每秒中的ticks个数。
其中_SC_CLK_TCK在文件 unistd.h中定义,通常,这个值是100,也就是说10ms一个tick,时钟精度就到10ms,如果需要更高精度的,大概就是jiffi?
linux中rfc1213系统时间更新节点ticks:
/* snmpget time ticks ,add rfc1213*/
pal_time_t nsm_get_sys_up_time_ticks()
{
pal_time_t sysUpTime_u = 0;
struct sysinfo info;
struct pal_timeval tv;
unsigned long time;
if(sysinfo(&info) < 0)
return 0;
time = (pal_time_t)info.uptime;/*系统更新时间单位S*/
pal_time_tzcurrent(&tv, NULL);
sysUpTime_u = (pal_time_t)tv.tv_usec; /*当前系统运行时间单位ms*/
time = (pal_time_t)((time-1)*100 + (sysUpTime_u/10000));
return time;
}