1CLOCK_GETCPUCLOCKID(3)     Linux Programmer's Manual    CLOCK_GETCPUCLOCKID(3)
2
3
4

NAME

6       clock_getcpuclockid - obtain ID of a process CPU-time clock
7

SYNOPSIS

9       #include <time.h>
10
11       int clock_getcpuclockid(pid_t pid, clockid_t *clock_id);
12
13       Link with -lrt (only for glibc versions before 2.17).
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       clock_getcpuclockid():
18           _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L
19

DESCRIPTION

21       The clock_getcpuclockid() function obtains the ID of the CPU-time clock
22       of the process whose ID is pid, and returns it in the location  pointed
23       to  by  clock_id.   If  pid  is zero, then the clock ID of the CPU-time
24       clock of the calling process is returned.
25

RETURN VALUE

27       On success, clock_getcpuclockid() returns 0; on error, it  returns  one
28       of the positive error numbers listed in ERRORS.
29

ERRORS

31       ENOSYS The  kernel  does not support obtaining the per-process CPU-time
32              clock of another process, and pid does not specify  the  calling
33              process.
34
35       EPERM  The caller does not have permission to access the CPU-time clock
36              of the process specified by  pid.   (Specified  as  an  optional
37              error in POSIX.1-2001; does not occur on Linux unless the kernel
38              does not support obtaining the  per-process  CPU-time  clock  of
39              another process.)
40
41       ESRCH  There is no process with the ID pid.
42

VERSIONS

44       The  clock_getcpuclockid() function is available in glibc since version
45       2.2.
46

ATTRIBUTES

48   Multithreading (see pthreads(7))
49       The clock_getcpuclockid() function is thread-safe.
50

CONFORMING TO

52       POSIX.1-2001.
53

NOTES

55       Calling clock_gettime(2) with the  clock  ID  obtained  by  a  call  to
56       clock_getcpuclockid()  with  a pid of 0, is the same as using the clock
57       ID CLOCK_PROCESS_CPUTIME_ID.
58

EXAMPLE

60       The example program below obtains the CPU-time clock ID of the  process
61       whose  ID  is given on the command line, and then uses clock_gettime(2)
62       to obtain the time on that clock.  An example run is the following:
63
64           $ ./a.out 1                 # Show CPU clock of init process
65           CPU-time clock for PID 1 is 2.213466748 seconds
66
67   Program source
68
69       #define _XOPEN_SOURCE 600
70       #include <stdio.h>
71       #include <unistd.h>
72       #include <stdlib.h>
73       #include <time.h>
74
75       int
76       main(int argc, char *argv[])
77       {
78           clockid_t clockid;
79           struct timespec ts;
80
81           if (argc != 2) {
82               fprintf(stderr, "%s <process-ID>\n", argv[0]);
83            exit(EXIT_FAILURE);
84           }
85
86           if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) {
87            perror("clock_getcpuclockid");
88            exit(EXIT_FAILURE);
89           }
90
91           if (clock_gettime(clockid, &ts) == -1) {
92            perror("clock_gettime");
93            exit(EXIT_FAILURE);
94           }
95
96           printf("CPU-time clock for PID %s is %ld.%09ld seconds\n",
97                argv[1], (long) ts.tv_sec, (long) ts.tv_nsec);
98           exit(EXIT_SUCCESS);
99       }
100

SEE ALSO

102       clock_getres(2), timer_create(2), pthread_getcpuclockid(3), time(7)
103

COLOPHON

105       This page is part of release 3.53 of the Linux  man-pages  project.   A
106       description  of  the project, and information about reporting bugs, can
107       be found at http://www.kernel.org/doc/man-pages/.
108
109
110
111Linux                             2013-07-04            CLOCK_GETCPUCLOCKID(3)
Impressum