| CLOCK_GETCPUCLOCKID(3) | Linux Programmer's Manual | CLOCK_GETCPUCLOCKID(3) |
NAME
clock_getcpuclockid - obtain ID of a process CPU-time clock
SYNOPSIS
#include <time.h>
int clock_getcpuclockid(pid_t pid, clockid_t *clock_id);
Link with -lrt.
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
clock_getcpuclockid(): _XOPEN_SOURCE >= 600
DESCRIPTION
The clock_getcpuclockid() obtains the ID of the CPU-time clock of the process whose ID is pid, and returns it in the location pointed to by clock_id. If pid is zero, then the clock ID of the CPU-time clock of the calling process is returned.
RETURN VALUE
On success, clock_getcpuclockid() returns 0; on error, it returns a positive error number.
ERRORS
- ENOSYS
- The kernel does not support obtaining the per-process CPU-time clock of another process, and pid does not specify the calling process.
- EPERM
- The caller does not have permission to access the CPU-time clock of the process specified by pid. (Specified as an optional error in POSIX.1-2001; does not occur on Linux unless the kernel does not support obtaining the per-process CPU-time clock of another process.)
- ESRCH
- There is no process with the ID pid.
VERSIONS
The clock_getcpuclockid() function is available in glibc since version 2.2.
CONFORMING TO
POSIX.1-2001.
NOTES
Calling clock_gettime(3) with the clock ID obtained by a call to clock_getcpuclockid() with a pid of 0, is the same as using the clock ID CLOCK_PROCESS_CPUTIME_ID.
EXAMPLE
The example program below obtains the CPU-time clock ID of the
process whose ID is given on the command line, and then uses
clock_gettime(3) to obtain the time on that clock. An example run is
the following:
$ ./a.out 1 # Show CPU clock of init process
CPU-time clock for PID 1 is 2.213466748 seconds
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
int
main(int argc, char *argv[])
{
clockid_t clockid;
struct timespec ts;
if (argc != 2) {
fprintf(stderr, "%s <process-ID>\n", argv[0]);
exit(EXIT_FAILURE);
}
if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) {
perror("clock_getcpuclockid");
exit(EXIT_FAILURE);
}
if (clock_gettime(clockid, &ts) == -1) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
printf("CPU-time clock for PID %s is %ld.%09ld seconds\n",
argv[1], (long) ts.tv_sec, (long) ts.tv_nsec);
exit(EXIT_SUCCESS);
}
SEE ALSO
COLOPHON
This page is part of release 3.09 of the Linux man-pages project. A description of the project, and information about reporting documentation bugs, can be found at http://www.kernel.org/doc/man-pages/.
| 2008-08-10 | Linux |
Different Versions of this Page:
- Version 6.17 (latest)
- Version 6.16
- Version 6.15
- Version 6.14
- Version 6.13
- Version 6.12
- Version 6.11
- Version 6.10
- Version 6.9.1
- Version 6.9
- Version 6.8
- Version 6.7
- Version 6.06
- Version 6.05.01
- Version 6.05
- Version 6.04
- Version 6.03
- Version 6.02
- Version 6.01
- Version 6.00
- Version 5.13
- Version 5.12
- Version 5.11
- Version 5.10
- Version 5.09
- Version 5.08
- Version 5.07
- Version 5.06
- Version 5.05
- Version 5.04
- Version 5.03
- Version 5.02
- Version 5.01
- Version 5.00
- Version 4.16
- Version 4.15
- Version 4.14
- Version 4.13
- Version 4.12
- Version 4.10
- Version 4.09
- Version 4.08
- Version 4.07
- Version 4.06
- Version 4.05
- Version 4.04
- Version 4.03
- Version 4.02
- Version 4.01
- Version 4.00
- Version 3.83
- Version 3.82
- Version 3.81
- Version 3.80
- Version 3.79
- Version 3.78
- Version 3.77
- Version 3.76
- Version 3.75
- Version 3.74
- Version 3.73
- Version 3.72
- Version 3.71
- Version 3.70
- Version 3.69
- Version 3.68
- Version 3.67
- Version 3.66
- Version 3.65
- Version 3.64
- Version 3.63
- Version 3.62
- Version 3.61
- Version 3.60
- Version 3.59
- Version 3.58
- Version 3.57
- Version 3.56
- Version 3.55
- Version 3.54
- Version 3.53
- Version 3.52
- Version 3.49
- Version 3.48
- Version 3.47
- Version 3.46
- Version 3.45
- Version 3.44
- Version 3.43
- Version 3.42
- Version 3.41
- Version 3.40
- Version 3.39
- Version 3.38
- Version 3.37
- Version 3.36
- Version 3.35
- Version 3.34
- Version 3.33
- Version 3.32
- Version 3.31
- Version 3.30
- Version 3.29
- Version 3.28
- Version 3.27
- Version 3.26
- Version 3.25
- Version 3.24
- Version 3.23
- Version 3.22
- Version 3.21
- Version 3.20
- Version 3.17
- Version 3.16
- Version 3.15
- Version 3.14
- Version 3.13
- Version 3.12
- Version 3.11
- Version 3.10
- Version 3.09
- Version 3.08
- Version 3.07