当前位置:网站首页>clock_ gettime
clock_ gettime
2022-07-26 04:34:00 【___ Bozi mi pro】
function "clock_gettime" Is based on Linux C Time function of language , It can be used to calculate accuracy and nanoseconds .
externintclock_gettime (clockid_t __clock_id,structtimespec *__tp) __THROW;
__clock_id : Clock type ,posix The standard defines the following four basic types ,Linux The system has other extensions
CLOCK_REALTIME: System real time , It changes with the real time of the system , From UTC1970-1-1 0:0:0 Start timing , In the middle time, if the system time is changed by the user to other , The corresponding time will change accordingly .
CLOCK_MONOTONIC: Start timing from the moment the system starts , Not affected by the change of system time by users
CLOCK_PROCESS_CPUTIME_ID: This process to the current code system CPU Time spent . You need to pay attention to whether the time from the beginning of the process to the current code .
CLOCK_THREAD_CPUTIME_ID: This thread to the current code system CPU Time spent . You need to pay attention to whether the time from the beginning of the thread to the current code .
/* POSIX.1b structure for a time value. This is like a `struct timeval' but
has nanoseconds instead of microseconds. */
struct timespec
{
__time_t tv_sec; /* Seconds. */
__syscall_s long_t tv_nsec; /* Nanoseconds. */
};Sample code :
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
struct timespec time1 = {0};
clock_gettime(CLOCK_REALTIME, &time1);
printf("CLOCK_REALTIME: (%lu, %lu)\n", time1.tv_sec, time1.tv_nsec);
clock_gettime(CLOCK_MONOTONIC, &time1);
printf("CLOCK_MONOTONIC: (%lu, %lu)\n", time1.tv_sec, time1.tv_nsec);
sleep(5);
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
printf("CLOCK_PROCESS_CPUTIME_ID: (%lu, %lu)\n", time1.tv_sec, time1.tv_nsec);
sleep(5);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &time1);
printf("CLOCK_THREAD_CPUTIME_ID: (%lu, %lu)\n", time1.tv_sec, time1.tv_nsec);
printf("now time :%lu\n", time(NULL));
return 0;
}Running results :
CLOCK_REALTIME: (1641541302, 670392667)
CLOCK_MONOTONIC: (280331, 989262689)
CLOCK_PROCESS_CPUTIME_ID: (0, 416834)
CLOCK_THREAD_CPUTIME_ID: (0, 436414)
now time :1641541312边栏推荐
- Network Security Learning - permission promotion 2
- YAPI安装
- [300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (VIII)
- Phaser(一):平台跳跃收集游戏
- The auxiliary role of rational cognitive educational robot in teaching and entertainment
- UE4 通过按键控制物体的旋转
- 再获认可 | 赛宁网安连续上榜《CCSIP 2022中国网络安全产业全景图》
- Solve the error string value: '\xf0\x9f\x98\xad',... 'for column' commentcontent 'at row 1
- UE4 键盘控制开关灯
- ASP. Net core actionfilter filter details
猜你喜欢

性能和成本的综合架构:单元化架构

How does win11 22h2 skip networking and Microsoft account login?

七、RESTful

理性认知教育机器人寓教于乐的辅助作用

数组排序3

Yapi installation

Steam science education endows classroom teaching with creativity

Postman imports curl, exports curl, and exports corresponding language codes

这种是我的vs没连上数据库吗

Dijango learning
随机推荐
【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(八)
UE4 获取玩家控制权的两种方式
数据库启动报:ORA-29702: error occurred in Cluster Group Service
7、 Restful
1. Mx6u system migration-6-uboot graphical configuration
Tutorial on using the one click upgrade function of the rtsp/onvif protocol video platform easynvr service
【UOJ 429】串串划分(Runs)(容斥)+ 有关 Lyndon Tree 及其应用的小小记录
9、 File upload and download
Rotate array minimum number
Dijango learning
【学习笔记】AGC041
2022 a.static query on tree (tree section)
Several methods of realizing high-low byte or high-low word exchange in TIA botu s7-1200
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (VIII)
建设面向青少年的创客教育实验室
数据仓库
Comparison of the relationship between the number of partitions and the number of reducetask in MapReduce
Authentication Encyclopedia (cookies, sessions, tokens, JWT, single sign on), in-depth understanding and understanding of authentication
A series of problems about the number of DP paths
Solve the error string value: '\xf0\x9f\x98\xad',... 'for column' commentcontent 'at row 1