Manual Pages for Linux CentOS command on man pthread_getcpuclockid
MyWebUniversity

Manual Pages for Linux CentOS command on man pthread_getcpuclockid

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

NAME

pthreadgetcpuclockid - retrieve ID of a thread's CPU time clock SYNOPSIS

#include

#include int pthreadgetcpuclockid(pthreadt thread, clockidt *clockid);

Compile and link with -pthread. DESCRIPTION The pthreadgetcpuclockid() function returns the clock ID for the CPU time clock of the thread thread. RETURN VALUE On success, this function returns 0; on error, it returns a nonzero error number. ERRORS

ENOENT Per-thread CPU time clocks are not supported by the system. ESRCH No thread with the ID thread could be found. VERSIONS This 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 │ ├────────────────────────┼───────────────┼─────────┤

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

POSIX.1-2001. NOTES When thread refers to the calling thread, this function returns an identifier that refers to the same clock manipulated by clockget‐ time(2) and clocksettime(2) when given the clock ID CLOCKTHREADCPUTIMEID. EXAMPLE The program below creates a thread and then uses clockgettime(2) to

retrieve the total process CPU time, and the per-thread CPU time con‐ sumed by the two threads. The following shell session shows an example run:

$ ./a.out Main thread sleeping Subthread starting infinite loop Main thread consuming some CPU time... Process total CPU time: 1.368 Main thread CPU time: 0.376 Subthread CPU time: 0.992 Program source

/* Link with "-lrt" */

#include

#include

#include

#include

#include

#include

#include

#define handleerror(msg) \ do { perror(msg); exit(EXITFAILURE); } while (0)

#define handleerroren(en, msg) \ do { errno = en; perror(msg); exit(EXITFAILURE); } while (0) static void * threadstart(void *arg) { printf("Subthread starting infinite loop\n"); for (;;) continue; } static void pclock(char *msg, clockidt cid) { struct timespec ts;

printf("%s", msg);

if (clockgettime(cid, &ts) == -1) handleerror("clockgettime");

printf("%4ld.%03ld\n", ts.tvsec, ts.tvnsec / 1000000); } int main(int argc, char *argv[]) { pthreadt thread; clockidt cid; int j, s; s = pthreadcreate(&thread, NULL, threadstart, NULL); if (s != 0) handleerroren(s, "pthreadcreate"); printf("Main thread sleeping\n"); sleep(1); printf("Main thread consuming some CPU time...\n"); for (j = 0; j < 2000000; j++) getppid(); pclock("Process total CPU time: ", CLOCKPROCESSCPUTIMEID); s = pthreadgetcpuclockid(pthreadself(), &cid); if (s != 0) handleerroren(s, "pthreadgetcpuclockid"); pclock("Main thread CPU time: ", cid); /* The preceding 4 lines of code could have been replaced by: pclock("Main thread CPU time: ", CLOCKTHREADCPUTIMEID); */ s = pthreadgetcpuclockid(thread, &cid); if (s != 0) handleerroren(s, "pthreadgetcpuclockid"); pclock("Subthread CPU time: 1 ", cid); exit(EXITSUCCESS); /* Terminates both threads */ } SEE ALSO clockgettime(2), clocksettime(2), timercreate(2), clockgetcpu‐ clockid(3), pthreadself(3), pthreads(7), 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 2009-02-08 PTHREADGETCPUCLOCKID(3)




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