Linux System Programming note 11 ——Time
来源:互联网 发布:网络会员制营销意义 编辑:程序博客网 时间:2024/06/10 20:10
Wall time(or real time)
Process time
Monotonic time
1. Breaking Down Time
struct tm{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
#ifdef _BSD_SOURCE
long tm_gmtoff;
const char *tm_zone;
#endif
};
2. POSIX Clocks
CLOCK_REALTIME
CLOCK_MONOTONIC
CLOCK_MONOTONIC_RAW
CLOCK_PROCESS_CPUTIME_ID
CLOCK_THREAD_CPUTIME_ID
3. Time Source Resolution
#include <time.h>
int clock_getres(clockid_t clock_id, struct timespec *res);
4. Getting the Current Time of Day
#include <time.h>
time_t time(time *t); //返回自epoch以来的秒数
5. A Better Interface
int gettimeofday(struct timeval *tv, struct timezone *tz);
6. An Advanced Interface
#include <time.h>
int clock_gettime(clockid_t clock_id, struct timespec *ts);
7. Getting the Process Time
#include <sys/time.h>
struct tms {
clock_t tms_utime;
clock_t tms_stime;
clock_t tms_cutime;
clock_t tms_cstime;
};
clock_t times(struct tms *buf);
8. Setting the Current Time of Day
#define _SVID_SOURCE
#include <time.h>
int stime(time_t *t);
9. Setting Time with Precision
#include <sys/time.h>
int settimeofday(const struct timeval *tv,
const struct timezone *tz);
10. An Advanced Interface for Setting the Time
#include <time.h>
int clock_settime(clockid_t clock_id, const struct timespec *ts);
11. Playing with Time
#include <time.h>
char *asctime(const struct tm *tm); //不是线程安全的
char *asctime_r(const struct tm *tm, char *buf); // 线程安全的
#include <time.h>
time_t mktime(struct tm *tm);
#include <time.h>
char *ctime(const time_t *timep);
char *ctime_r(const time_t *timep, char *buf);
gmtime() converts the given time_t to a tm structure,
#include <time.h>
struct tm * gmtime(const time_t *timep);
struct tm *gmtime_r(const time_t *timep, struct tm *result);
#include <time.h>
struct tm *localtime(const time_t *timep);
struct tm *localtime_r(const time_t *timep, struct tm *result);
#include <time.h>
double difftime(time_t time1, time_t time2);
12. Timers
12.1 Simple Alarm
#include <unistd.h>
unsigned int alarm(unsigned int seconds);
12.2 Interval Timers
#include <sys/time.h>
int getitimer(int which, struct itimerval *value);
int setitimer(int which, struct itimerval *value, struct itimerval *ovaule);
struct itimerval {
struct timeval it_interval;
struct timeval it_value;
};
13. Advanced Timers
timer_create()
timer_settime()
timer_delete()
0 0
- Linux System Programming note 11 ——Time
- Linux System Programming note 2 ——File I/O
- Linux System Programming note 5—— Process Management
- Linux System Programming note 6—— Adcanced Process Management
- Linux System Programming note 7 —— Threading
- Linux System Programming note 9 ——Memory Management
- Linux System Programming note 10 —— Signal
- Linux System Programming note 1
- Linux System Programming note 4 —— Advanced File I/O
- Linux System Programming note 8 ——File and Directory Management
- Linux System Programming note3 —— Buffered I/O
- 书评:Linux System Programming
- Linux system programming
- Linux System Programming -- Appendix
- Linux time system
- Time with Time-zone Programming on Linux
- Linux System Programming:Memory Management
- Linux programming and system knowledge
- 写一个函数能够返回模块的帮助文档
- Linux环境编程之同步(一):互斥锁
- 修改oracle 的undo_retention
- NoSQL数据库的35个应用场景
- 任正非:为什么要自我批判?
- Linux System Programming note 11 ——Time
- jQuery判断点击事件是否在目标区域
- Jsp遍历后台传过来的List
- cat
- 提取遥感影像有效区域
- Android 客户端数据和服务器端的同步
- 滑动条/块响应消息WM_HSCROLL导致OnHScroll函数执行了两次的问题
- Java 单例模式(2种)
- 去除Excel单元格中的换行(亲自实践)