当前位置:网站首页>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边栏推荐
- How does win11 change the power mode? Win11 method of changing power mode
- 2022 Henan Mengxin League game (3): Henan University L - synthetic game
- 2022 Henan Mengxin League game (3): Henan University J - magic number
- egg-sequelize JS编写
- Codeforces Round #807 (Div. 2)
- UE4 通过按键控制物体的旋转
- Network Security Learning - permission promotion 2
- 自动化测试框架该如何搭建?
- UE4 keyboard control switch light
- 2022 Hangdian multi school DOS card (line segment tree)
猜你喜欢

Acwing_ 12. Find a specific solution for the knapsack problem_ dp

Sangi diagram of machine learning (for user behavior analysis)

人脸数据库收集总结

Scroll view pull-down refresh and pull-up load (bottom)

Unable to find sygwin.s file during vscode debugging

UE4 获取玩家控制权的两种方式

Integrated architecture of performance and cost: modular architecture

ASP. Net core actionfilter filter details

What are the consequences and problems of computer system restoration

一个sql server查询截止某个日期最新的记录
随机推荐
UE4 获取玩家控制权的两种方式
2022 Henan Mengxin League game (3): Henan University B - reverse pair count
Credit card fraud detection based on machine learning
2022 Henan Mengxin League game (3): Henan University a - corn cannon
MySQL的优化分析及效率执行
YAPI安装
Embedded practice -- CPU utilization statistics based on rt1170 FreeRTOS (24)
egg-ts-sequelize-CLI
九、文件上传和下载
Weights & Biases (二)
How does win11 22h2 skip networking and Microsoft account login?
10、 Interceptor
Page pull-up refresh and pull-down loading
An SQL server queries the latest records as of a certain date
MapReduce中分区数与ReduceTask个数关系比较
ES6模块化+CommonJS
软考回顾及计划
Several methods of realizing high-low byte or high-low word exchange in TIA botu s7-1200
data warehouse
1. If function of Excel