반응형
#include <stdio.h>
#include <unistd.h>
#include <sys/times.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h>
int main() {
int i;
time_t t;
struct tms mytms;
clock_t t1, t2;
if((t1 = times(&mytms)) == -1){
perror("times 1");
exit(1);
}
for(i = 0; i< 99999999; i++)
time(&t);
if((t2 = times(&mytms)) == -1){
perror("times 2");
exit(1);
}
printf("Real time : %.1f sec\n", (double)(t2- t1)/ CLK_TCK);
printf("User time : %.1f sec\n", (double)mytms.tms_utime / CLK_TCK);
printf("System time : %.1f sec\n", (double)mytms.tms_stime/ CLK_TCK);
return 0;
}
--output--
Real time : 5.3 sec
User time : 5.2 sec
System time : 0.0 sec
반응형
'TIL > os' 카테고리의 다른 글
exec를 이용하여 fork 후 자식 프로세스는 다른 프로그램 실행하기 (0) | 2022.10.03 |
---|---|
자식 프로세스 fork 하기 (0) | 2022.10.03 |
C언어 - 현재 시간을 변환하여 읽기 (0) | 2022.10.03 |
[Docker] 라이프 사이클 (0) | 2022.09.18 |
Operating System은 무엇인가 (0) | 2022.09.16 |