Manual Pages for Linux CentOS command on man clock_getcpuclockid
MyWebUniversity

Manual Pages for Linux CentOS command on man clock_getcpuclockid

CLOCKGETCPUCLOCKID(3) Linux Programmer's Manual CLOCKGETCPUCLOCKID(3)

NAME

clockgetcpuclockid - obtain ID of a process CPU-time clock SYNOPSIS

#include int clockgetcpuclockid(pidt pid, clockidt *clockid);

Link with -lrt (only for glibc versions before 2.17). Feature Test Macro Requirements for glibc (see featuretestmacros(7)): clockgetcpuclockid(): XOPENSOURCE >= 600 || POSIXCSOURCE >= 200112L DESCRIPTION

The clockgetcpuclockid() function obtains the ID of the CPU-time clock of the process whose ID is pid, and returns it in the location pointed

to by clockid. If pid is zero, then the clock ID of the CPU-time clock of the calling process is returned. RETURN VALUE On success, clockgetcpuclockid() returns 0; on error, it returns one of the positive error numbers listed in ERRORS. 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 clockgetcpuclockid() function is available in glibc since version 2.2. ATTRIBUTES For an explanation of the terms used in this section, see attributes(7). ┌──────────────────────┬───────────────┬─────────┐ │Interface │ Attribute │ Value │ ├──────────────────────┼───────────────┼─────────┤

│clockgetcpuclockid() │ Thread safety │ MT-Safe │ └──────────────────────┴───────────────┴─────────┘ CONFORMING TO

POSIX.1-2001. NOTES Calling clockgettime(2) with the clock ID obtained by a call to clockgetcpuclockid() with a pid of 0, is the same as using the clock ID CLOCKPROCESSCPUTIMEID. 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 clockgettime(2) 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 Program source

#define XOPENSOURCE 600

#include

#include

#include

#include int main(int argc, char *argv[]) { clockidt clockid; struct timespec ts; if (argc != 2) {

fprintf(stderr, "%s \n", argv[0]); exit(EXITFAILURE); } if (clockgetcpuclockid(atoi(argv[1]), &clockid) != 0) { perror("clockgetcpuclockid"); exit(EXITFAILURE); }

if (clockgettime(clockid, &ts) == -1) { perror("clockgettime"); exit(EXITFAILURE); }

printf("CPU-time clock for PID %s is %ld.%09ld seconds\n", argv[1], (long) ts.tvsec, (long) ts.tvnsec); exit(EXITSUCCESS); } SEE ALSO clockgetres(2), timercreate(2), pthreadgetcpuclockid(3), time(7) COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

Linux 2013-07-04 CLOCKGETCPUCLOCKID(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™