]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/clock_getcpuclockid.3
man*/: ffix (un-bracket tables)
[thirdparty/man-pages.git] / man3 / clock_getcpuclockid.3
1 '\" t
2 .\" Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH clock_getcpuclockid 3 (date) "Linux man-pages (unreleased)"
8 .SH NAME
9 clock_getcpuclockid \- obtain ID of a process CPU-time clock
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ", " \-lc ),
13 since glibc 2.17
14 .PP
15 Before glibc 2.17,
16 Real-time library
17 .RI ( librt ", " \-lrt )
18 .SH SYNOPSIS
19 .B #include <time.h>
20 .nf
21 .PP
22 .BI "int clock_getcpuclockid(pid_t " pid ", clockid_t *" clockid );
23 .fi
24 .PP
25 .ad l
26 .RS -4
27 Feature Test Macro Requirements for glibc (see
28 .BR feature_test_macros (7)):
29 .RE
30 .PP
31 .BR clock_getcpuclockid ():
32 .nf
33 _POSIX_C_SOURCE >= 200112L
34 .fi
35 .SH DESCRIPTION
36 The
37 .BR clock_getcpuclockid ()
38 function obtains the ID of the CPU-time clock of the process whose ID is
39 .IR pid ,
40 and returns it in the location pointed to by
41 .IR clockid .
42 If
43 .I pid
44 is zero, then the clock ID of the CPU-time clock
45 of the calling process is returned.
46 .SH RETURN VALUE
47 On success,
48 .BR clock_getcpuclockid ()
49 returns 0;
50 on error, it returns one of the positive error numbers listed in ERRORS.
51 .SH ERRORS
52 .TP
53 .B ENOSYS
54 The kernel does not support obtaining the per-process
55 CPU-time clock of another process, and
56 .I pid
57 does not specify the calling process.
58 .TP
59 .B EPERM
60 The caller does not have permission to access
61 the CPU-time clock of the process specified by
62 .IR pid .
63 (Specified in POSIX.1-2001;
64 does not occur on Linux unless the kernel does not support
65 obtaining the per-process CPU-time clock of another process.)
66 .TP
67 .B ESRCH
68 There is no process with the ID
69 .IR pid .
70 .SH ATTRIBUTES
71 For an explanation of the terms used in this section, see
72 .BR attributes (7).
73 .TS
74 allbox;
75 lbx lb lb
76 l l l.
77 Interface Attribute Value
78 T{
79 .na
80 .nh
81 .BR clock_getcpuclockid ()
82 T} Thread safety MT-Safe
83 .TE
84 .sp 1
85 .SH STANDARDS
86 POSIX.1-2008.
87 .SH HISTORY
88 glibc 2.2.
89 POSIX.1-2001.
90 .SH NOTES
91 Calling
92 .BR clock_gettime (2)
93 with the clock ID obtained by a call to
94 .BR clock_getcpuclockid ()
95 with a
96 .I pid
97 of 0,
98 is the same as using the clock ID
99 .BR CLOCK_PROCESS_CPUTIME_ID .
100 .SH EXAMPLES
101 The example program below obtains the
102 CPU-time clock ID of the process whose ID is given on the command line,
103 and then uses
104 .BR clock_gettime (2)
105 to obtain the time on that clock.
106 An example run is the following:
107 .PP
108 .in +4n
109 .EX
110 .RB "$" " ./a.out 1" " # Show CPU clock of init process"
111 CPU\-time clock for PID 1 is 2.213466748 seconds
112 .EE
113 .in
114 .SS Program source
115 \&
116 .\" SRC BEGIN (clock_getcpuclockid.c)
117 .EX
118 #define _XOPEN_SOURCE 600
119 #include <stdint.h>
120 #include <stdio.h>
121 #include <stdlib.h>
122 #include <time.h>
123 #include <unistd.h>
124 \&
125 int
126 main(int argc, char *argv[])
127 {
128 clockid_t clockid;
129 struct timespec ts;
130 \&
131 if (argc != 2) {
132 fprintf(stderr, "%s <process\-ID>\en", argv[0]);
133 exit(EXIT_FAILURE);
134 }
135 \&
136 if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) {
137 perror("clock_getcpuclockid");
138 exit(EXIT_FAILURE);
139 }
140 \&
141 if (clock_gettime(clockid, &ts) == \-1) {
142 perror("clock_gettime");
143 exit(EXIT_FAILURE);
144 }
145 \&
146 printf("CPU\-time clock for PID %s is %jd.%09ld seconds\en",
147 argv[1], (intmax_t) ts.tv_sec, ts.tv_nsec);
148 exit(EXIT_SUCCESS);
149 }
150 .EE
151 .\" SRC END
152 .SH SEE ALSO
153 .BR clock_getres (2),
154 .BR timer_create (2),
155 .BR pthread_getcpuclockid (3),
156 .BR time (7)