Linux获取毫秒级时间
Linux获取毫秒级时间
Moakap
在软件设计中经常会用到关于时间的处理,用来计算语句、函数的执行时间,这时就需要精确到毫秒甚至是微妙的时间。
int gettimeofday(struct
timeval *tv, struct timezone *tz);
int settimeofday(const
struct timeval *tv , const struct timezone *tz);
struct timeval {
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /*
microseconds */
};
struct timezone {
int tz_minuteswest; /* minutes
west of Greenwich
*/
int
tz_dsttime; /* type of DST
correction */
};
下面是个简单的例子,用来统计程序的执行时间:
…
struct timeval
t_start,t_end;
long cost_time = 0;
//get start
time
gettimeofday(&t_start,
NULL);
printf("Start
time: %ld us", t_start.tv_usec);
//some
operation
…
//get end time
gettimeofday(&t_end,
NULL);
printf("End
time: %ld us", t_end.tv_usec);
//calculate
time slot
cost_time =
t_end.tv_usec - t_start.tv_usec;
printf("Cost
time: %ld us", cost_time);
…
输出:
Start time:
438061 us
End time:
459867 us
Cost time:
21806 us
相关文档:
在LINUX的时钟中断中涉及至二个全局变量一个是xtime,它是timeval数据结构变量,另一个则是jiffies,首先看timeval结构
struct timeval
{
time_t tv_sec; /***second***/
susecond_t tv_usec;/***microsecond***/
}
到底microsecond是毫秒还是微秒??
1秒=1000毫秒(3个零),1秒=1000 000微秒(6个零),1秒=1 ......
在linux下安装oracle是件繁琐的事情。具体来讲分为一下几大步:
1.修改系统版本
vi /etc/redhat-release
注释掉第一行,添加一行:redhat-4
2.安装软件包
rpm -Uvh setarch-2*
rpm -Uvh make-3*
rpm -Uvh glibc-2*
rpm -Uvh libaio-0*
rpm -Uvh compat-libstdc++-33-3*
rpm -Uvh compat-gcc-34-3*
rpm -Uvh comp ......
Name
hosts - The static table lookup for host names
Synopsis
/etc/hosts
Description
This manual page describes the format of the /etc/hosts
file. This file is a simple text file that
associates IP addresses with hostnames, one line per IP address. For
each host a single line should be presen ......
按以下步骤来,先写这么多来提醒下自己:
1.熟悉linux的基本环境,熟悉linux的基本命令.
2.熟悉linux的交叉编译环境的的配置.
3.复习基本的C语言知识.
&nbs ......
最近对Linux的线程接口进行了些总结,也参考了网络上兄弟们的一些资料,自己同时也写了些程序进行测试,先把参考的
资料列出来吧
http://blog.mcuol.com/User/liuzhilii521/Article/12738_1.htm
下面是我的一些理解:
pthread_key_create(pthread_key_t *key,void (*destructor)(void*))
destructor这个回调函数在线程 ......