Provided by: manpages-fr-dev_4.13-4_all bug

NOM

       pthread_getcpuclockid - Récupérer l'identifiant d'horloge de temps CPU d'un thread

SYNOPSIS

       #include <pthread.h>
       #include <time.h>

       int pthread_getcpuclockid(pthread_t thread, clockid_t *clockid);

       Compiler et éditer les liens avec -pthreads.

DESCRIPTION

       The  pthread_getcpuclockid()   function  obtains  the  ID of the CPU-time clock of the thread whose ID is
       given in thread, and returns it in the location pointed to by clockid.

VALEUR RENVOYÉE

       En cas de réussite, cette fonction renvoie 0 ; en cas d'erreur, elle renvoie un numéro d'erreur non nul.

ERREURS

       ENOENT Les horloges de temps CPU par thread ne sont pas pris en charge par le système.

       ESRCH  Aucun fil d’exécution avec pour identifiant thread n'a pu être trouvé.

VERSIONS

       Cette fonction est disponible dans la glibc depuis la version 2.2.

ATTRIBUTS

       Pour une explication des termes utilisés dans cette section, consulter attributes(7).
       ┌─────────────────────────┬──────────────────────┬─────────┐
       │ InterfaceAttributValeur  │
       ├─────────────────────────┼──────────────────────┼─────────┤
       │ pthread_getcpuclockid() │ Sécurité des threads │ MT-Safe │
       └─────────────────────────┴──────────────────────┴─────────┘

CONFORMITÉ

       POSIX.1-2001, POSIX.1-2008.

NOTES

       Quand thread se rapporte au thread appelant, cette fonction renvoie un identifiant qui  indique  la  même
       horloge  que  celle  manipulée  par  clock_gettime(2)  et  clock_settime(2)  avec l'identifiant d'horloge
       CLOCK_THREAD_CPUTIME_ID.

EXEMPLES

       Le programme ci-dessous crée un thread puis utilise clock_gettime(2) pour récupérer le temps CPU total du
       processus et le temps CPU utilisé par chacun des deux threads. La  session  suivante  montre  un  exemple
       d'exécution :

           $ ./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

   Source du programme

       /* Effectuez l'édition des liens avec l'option "-lrt" */

       #include <time.h>
       #include <stdio.h>
       #include <stdint.h>
       #include <stdlib.h>
       #include <unistd.h>
       #include <pthread.h>
       #include <string.h>
       #include <errno.h>

       #define handle_error(msg) \
               do { perror(msg); exit(EXIT_FAILURE); } while (0)

       #define handle_error_en(en, msg) \
               do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)

       static void *
       thread_start(void *arg)
       {
           printf("Subthread starting infinite loop\n");
           for (;;)
               continue;
       }

       static void
       pclock(char *msg, clockid_t cid)
       {
           struct timespec ts;

           printf("%s", msg);
           if (clock_gettime(cid, &ts) == -1)
               handle_error("clock_gettime");
           printf("%4jd.%03ld\n", (intmax_t) ts.tv_sec, ts.tv_nsec / 1000000);
       }

       int
       main(int argc, char *argv[])
       {
           pthread_t thread;
           clockid_t cid;
           int s;

           s = pthread_create(&thread, NULL, thread_start, NULL);
           if (s != 0)
               handle_error_en(s, "pthread_create");

           printf("Main thread sleeping\n");
           sleep(1);

           printf("Main thread consuming some CPU time...\n");
           for (int j = 0; j < 2000000; j++)
               getppid();

           pclock("Process total CPU time: ", CLOCK_PROCESS_CPUTIME_ID);

           s = pthread_getcpuclockid(pthread_self(), &cid);
           if (s != 0)
               handle_error_en(s, "pthread_getcpuclockid");
           pclock("Main thread CPU time:   ", cid);

           /* The preceding 4 lines of code could have been replaced by:
              pclock("Main thread CPU time:   ", CLOCK_THREAD_CPUTIME_ID); */

           s = pthread_getcpuclockid(thread, &cid);
           if (s != 0)
               handle_error_en(s, "pthread_getcpuclockid");
           pclock("Subthread CPU time: 1    ", cid);

           exit(EXIT_SUCCESS);         /* Terminates both threads */
       }

VOIR AUSSI

       clock_gettime(2),    clock_settime(2),    timer_create(2),    clock_getcpuclockid(3),    pthread_self(3),
       pthreads(7), time(7)

COLOPHON

       Cette page fait partie de la publication 5.10 du projet man-pages Linux. Une description du projet et des
       instructions pour signaler des anomalies et la dernière version de cette page  peuvent  être  trouvées  à
       l'adresse https://www.kernel.org/doc/man-pages/.

TRADUCTION

       La   traduction   française   de   cette   page   de   manuel   a   été   créée   par  Christophe  Blaess
       <https://www.blaess.fr/christophe/>,   Stéphan   Rafin   <stephan.rafin@laposte.net>,   Thierry   Vignaud
       <tvignaud@mandriva.com>,  François  Micaux,  Alain Portal <aportal@univ-montp2.fr>, Jean-Philippe Guérard
       <fevrier@tigreraye.org>,   Jean-Luc   Coulon   (f5ibh)   <jean-luc.coulon@wanadoo.fr>,   Julien   Cristau
       <jcristau@debian.org>,      Thomas      Huriaux      <thomas.huriaux@gmail.com>,     Nicolas     François
       <nicolas.francois@centraliens.net>,    Florentin    Duneau    <fduneau@gmail.com>,     Simon     Paillard
       <simon.paillard@resel.enst-bretagne.fr>,     Denis    Barbier    <barbier@debian.org>,    David    Prévot
       <david@tilapin.org> et Frédéric Hantrais <fhantrais@gmail.com>

       Cette traduction est une documentation libre ; veuillez vous  reporter  à  la  GNU General Public License
       version 3 concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE.

       Si  vous  découvrez  un  bogue  dans la traduction de cette page de manuel, veuillez envoyer un message à
       debian-l10n-french@lists.debian.org.

Linux                                            1 novembre 2020                        PTHREAD_GETCPUCLOCKID(3)