245 lines
6.5 KiB
HTML
245 lines
6.5 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of CLOCK_GETCPUCLOCKID</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>CLOCK_GETCPUCLOCKID</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
clock_getcpuclockid - obtain ID of a process CPU-time clock
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/time.h">time.h</A>></B>
|
|
|
|
<PRE>
|
|
|
|
<B>int clock_getcpuclockid(pid_t </B><I>pid</I><B>, clockid_t *</B><I>clock_id</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
Link with <I>-lrt</I> (only for glibc versions before 2.17).
|
|
<P>
|
|
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
<B>clock_getcpuclockid</B>():
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
_POSIX_C_SOURCE >= 200112L
|
|
</DL>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>clock_getcpuclockid</B>()
|
|
|
|
function obtains the ID of the CPU-time clock of the process whose ID is
|
|
<I>pid</I>,
|
|
|
|
and returns it in the location pointed to by
|
|
<I>clock_id</I>.
|
|
|
|
If
|
|
<I>pid</I>
|
|
|
|
is zero, then the clock ID of the CPU-time clock
|
|
of the calling process is returned.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success,
|
|
<B>clock_getcpuclockid</B>()
|
|
|
|
returns 0;
|
|
on error, it returns one of the positive error numbers listed in ERRORS.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="2"><B>ENOSYS</B>
|
|
|
|
<DD>
|
|
The kernel does not support obtaining the per-process
|
|
CPU-time clock of another process, and
|
|
<I>pid</I>
|
|
|
|
does not specify the calling process.
|
|
<DT id="3"><B>EPERM</B>
|
|
|
|
<DD>
|
|
The caller does not have permission to access
|
|
the CPU-time clock of the process specified by
|
|
<I>pid</I>.
|
|
|
|
(Specified 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.)
|
|
<DT id="4"><B>ESRCH</B>
|
|
|
|
<DD>
|
|
There is no process with the ID
|
|
<I>pid</I>.
|
|
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
The
|
|
<B>clock_getcpuclockid</B>()
|
|
|
|
function is available in glibc since version 2.2.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>clock_getcpuclockid</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
Calling
|
|
<B><A HREF="/cgi-bin/man/man2html?2+clock_gettime">clock_gettime</A></B>(2)
|
|
|
|
with the clock ID obtained by a call to
|
|
<B>clock_getcpuclockid</B>()
|
|
|
|
with a
|
|
<I>pid</I>
|
|
|
|
of 0,
|
|
is the same as using the clock ID
|
|
<B>CLOCK_PROCESS_CPUTIME_ID</B>.
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
The example program below obtains the
|
|
CPU-time clock ID of the process whose ID is given on the command line,
|
|
and then uses
|
|
<B><A HREF="/cgi-bin/man/man2html?2+clock_gettime">clock_gettime</A></B>(2)
|
|
|
|
to obtain the time on that clock.
|
|
An example run is the following:
|
|
<P>
|
|
|
|
|
|
|
|
$<B> ./a.out 1</B> # Show CPU clock of init process
|
|
|
|
CPU-time clock for PID 1 is 2.213466748 seconds
|
|
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H3>Program source</H3>
|
|
|
|
|
|
|
|
#define _XOPEN_SOURCE 600
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/time.h">time.h</A>>
|
|
<P>
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
<BR> clockid_t clockid;
|
|
<BR> struct timespec ts;
|
|
<P>
|
|
<BR> if (argc != 2) {
|
|
<BR> fprintf(stderr, "%s <process-ID>\n", argv[0]);
|
|
<BR> exit(EXIT_FAILURE);
|
|
<BR> }
|
|
<P>
|
|
<BR> if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) {
|
|
<BR> perror("clock_getcpuclockid");
|
|
<BR> exit(EXIT_FAILURE);
|
|
<BR> }
|
|
<P>
|
|
<BR> if (clock_gettime(clockid, &ts) == -1) {
|
|
<BR> perror("clock_gettime");
|
|
<BR> exit(EXIT_FAILURE);
|
|
<BR> }
|
|
<P>
|
|
<BR> printf("CPU-time clock for PID %s is %ld.%09ld seconds\n",
|
|
<BR> argv[1], (long) ts.tv_sec, (long) ts.tv_nsec);
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+clock_getres">clock_getres</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+timer_create">timer_create</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_getcpuclockid">pthread_getcpuclockid</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+time">time</A></B>(7)
|
|
|
|
<A NAME="lbAN"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="5"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="6"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="7"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="8"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="9"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="10"><A HREF="#lbAG">VERSIONS</A><DD>
|
|
<DT id="11"><A HREF="#lbAH">ATTRIBUTES</A><DD>
|
|
<DT id="12"><A HREF="#lbAI">CONFORMING TO</A><DD>
|
|
<DT id="13"><A HREF="#lbAJ">NOTES</A><DD>
|
|
<DT id="14"><A HREF="#lbAK">EXAMPLE</A><DD>
|
|
<DL>
|
|
<DT id="15"><A HREF="#lbAL">Program source</A><DD>
|
|
</DL>
|
|
<DT id="16"><A HREF="#lbAM">SEE ALSO</A><DD>
|
|
<DT id="17"><A HREF="#lbAN">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:37 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|