#include <stdio.h> 
#include <stdlib.h> 
#include <unistd.h> 
#include <time.h> 
int get_sys_uptime(struct timeval *tv_p); 
int main(int argc, char *argv[]) 
{ 
int nRet; 
struct timeval tvTm; 
nRet = get_sys_uptime(&tvTm); 
if( nRet != 0 ){ 
printf("ERROR_FAIL get_sys_uptime nRet:%d\n", nRet); 
return (-1); 
} 
printf("get_sys_uptime nRet:%d tv_sec:%ld tv_usec:%ld \n", nRet, tvTm.tv_sec, tvTm.tv_usec); 
return 0; 
} 
int get_sys_uptime(struct timeval *tv_p) 
{ 
int nRet; 
struct timespec tsp; 
nRet = clock_gettime(CLOCK_MONOTONIC, &tsp); 
if( nRet != 0 ){ 
printf("ERROR_FAIL clock_gettime nRet:%d\n", nRet); 
return (-1); 
} 
tv_p->tv_sec = tsp.tv_sec; 
tv_p->tv_usec = tsp.tv_nsec / 1000; 
return 0; 
} 
실행결과  
./a.out 
get_sys_uptime nRet:0 tv_sec:2354 tv_usec:333965 
struct timespec { 
time_t    tv_sec;      /* seconds */ 
long      tv_nsec;     /* nanoseconds */ 
}; 
#include <time.h> 
int clock_gettime(clockid_t clk_id, struct timespec *tp);
CLOCK_REALTIME 
시스템 전역의 실제 시간입니다. 
CLOCK_REALTIME_COARSE 
시스템 전역의 실제시간인데, CLOCK_REALTIME 보다 실행시간이 많이 빠릅니다. 
정확도가 떨어지는 대신 매우 빠른 function call 을 하고싶다면 이 아규먼트를 사용하면 됩니다. 
CLOCK_MONOTONIC 
단조 시계로 특정시간부터 흐른 시간을 측정합니다. (일반적으로 부팅이후 시간) 
시스템 관리자는 이 값을 초기화 할수 있습니다.
clock_gettime() 이 성공하면 0을 리턴하고, 실패하면 -1을 리턴합니다. (errno 값이 셋팅되어집니다.) 
에러값  
EFAULT 
tp 주소가 접근가능한 주소 공간 밖을 가르키고 있는경우. 
EINVAL 
clk_id 값이 이 시스템에서 지원하지 않는 값일 경우. 
EPERM 
clock_settime() 에서 클럭을 설정한 권한이 없는 경우. 










