Linux C 语言时间相关处理

  • time
  • gettimeofday
  • jeffies
  • clock_gettime,多种类型
  • 定时器
  • 信号
  • 条件锁

time()

以下是 man 2 time

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
SYNOPSIS
#include <time.h>

time_t time(time_t *t);

DESCRIPTION
time() returns the time as the number of seconds since the Epoch,
1970-01-01 00:00:00 +0000 (UTC).

If t is non-NULL, the return value is also stored in the memory pointed
to by t.

RETURN VALUE
On success, the value of time in seconds since the Epoch is returned.
On error, ((time_t) -1) is returned, and errno is set appropriately.

ERRORS
EFAULT t points outside your accessible address space.

CONFORMING TO
SVr4, 4.3BSD, C89, C99, POSIX.1-2001. POSIX does not specify any error
conditions.