日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

linux 中 timeval结构体

發布時間:2023/12/10 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux 中 timeval结构体 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

網上很多人寫到,timeval結構解釋錯誤

*******************************************************************

問題如下:
在debian linux的man頁中對gettimeofday函數的說明中,有這樣一個說明:

DESCRIPTION
??? The functions gettimeofday and settimeofday can get and set the time as
??? well as a timezone. The tv argument is a timeval struct, as specified
??? in <sys/time.h>:

??? struct timeval {
????????? time_t?????? tv_sec;???? /* seconds */
????????? suseconds_t?? tv_usec; /* microseconds */
??? };

其中對tv_usec的說明為時間的毫秒部分。 而在實際中,該函數以及Linux內核返回的timeval
類型的時間值,tv_usec代表的是微秒精度(10的-6次方秒)。

********************************************************************

我很無語,只能說寫這話的人英語很水,microsecond 是微秒的意思,簡寫為usec

毫秒的英語單詞是millisecond,簡寫為msec

#include <stdio.h>
#include <sys/time.h>
#include <time.h>

int main(int argc,char * argv[])
{

??? struct timeval tv;
??? while(1)
? {
????????? gettimeofday(&tv,NULL);
????????? printf("time %u:%u\n",tv.tv_sec,tv.tv_usec);
????????? sleep(2);
? ?? }
??? return 0;
}

總結

以上是生活随笔為你收集整理的linux 中 timeval结构体的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。