Provided by: manpages-fr-dev_4.26.0-1_all bug

NOM

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

BIBLIOTHÈQUE

       Bibliothèque de threads POSIX (libpthread, -lpthread)

SYNOPSIS

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

       int pthread_getcpuclockid(pthread_t thread, clockid_t *clockid);

DESCRIPTION

       La  fonction  pthread_getcpuclockid() récupère l'identifiant d'horloge pour l'horloge de temps processeur
       du thread donné dans thread et le renvoie à l'emplacement vers lequel pointe 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é.

ATTRIBUTS

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

STANDARDS

       POSIX.1-2008.

HISTORIQUE

       glibc 2.2. POSIX.1-2001.

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

       /* Link with "-lrt" */

       #include <errno.h>
       #include <pthread.h>
       #include <stdint.h>
       #include <stdio.h>
       #include <stdlib.h>
       #include <string.h>
       #include <time.h>
       #include <unistd.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(void)
       {
           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 (unsigned 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)

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>,     Frédéric     Hantrais    <fhantrais@gmail.com>    et    Jean-Philippe    MENGUAL
       <jpmengual@debian.org>

       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.

Pages du manuel de Linux 6.9.1                    15 juin 2024                          pthread_getcpuclockid(3)