.\" -*- coding: UTF-8 -*- .\" Copyright (C) 2012 Chandan Apsangi .\" and Copyright (C) 2013 Michael Kerrisk .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH PTHREAD_SETNAME_NP 3 "1 novembre 2020" Linux "Manuel du programmeur Linux" .SH NOM pthread_setname_np, pthread_getname_np \- Définir ou obtenir le nom d'un thread .SH SYNOPSIS .nf \fB#define _GNU_SOURCE\fP /* Consultez feature_test_macros(7) */ \fB#include \fP \fBint pthread_setname_np(pthread_t \fP\fIthread\fP\fB, const char *\fP\fIname\fP\fB);\fP \fBint pthread_getname_np(pthread_t \fP\fIthread\fP\fB,\fP \fB char *\fP\fIname\fP\fB, size_t \fP\fIlen\fP\fB);\fP .fi .PP Compiler et éditer les liens avec \fI\-pthreads\fP. .SH DESCRIPTION Par défaut, tous les threads créés par \fBpthread_create\fP() héritent du nom de programme. La fonction \fBpthread_setname_np\fP() permet d'affecter un nom propre à un thread, ce qui peut être utile pour déboguer une application multithread. Le nom du thread est une chaîne de langage C significative, dont la longueur ne peut dépasser 16\ caractères, caractère nul final (\(aq\e0\(aq) inclus. L'argument \fIthread\fP indique le thread dont le nom doit être changé\ ; le nouveau nom est précisé dans \fIname\fP. .PP La fonction \fBpthread_getname_np\fP() permet de récupérer le nom du thread. L'argument \fIthread\fP indique le thread dont le nom doit être récupéré. Le tampon \fIname\fP est utilisé pour renvoyer le nom du thread\ ; \fIlen\fP indique le nombre d'octets disponibles dans \fIname\fP. La longueur du tampon indiqué dans \fIname\fP doit être d'au moins 16\ caractères. Le nom du thread renvoyé dans le tampon de retour est terminé par caractère nul. .SH "VALEUR RENVOYÉE" En cas de succès, ces fonctions renvoient \fB0\fP\ ; en cas d'erreur, elles renvoient un code d'erreur non nul. .SH ERREURS La fonction \fBpthread_setname_np\fP() peut échouer avec l'erreur suivante\ : .TP \fBERANGE\fP La longueur de la chaîne vers laquelle pointe \fIname\fP dépasse la limite autorisée. .PP La fonction \fBpthread_getname_np\fP() peut échouer avec l'erreur suivante\ : .TP \fBERANGE\fP Le tampon indiqué par \fIname\fP et \fIlen\fP a une taille insuffisante pour contenir le nom du thread. .PP Si l'une de ces fonctions ne parvient pas à ouvrir \fI/proc/self/task/[tid]/comm\fP, alors l'appel peut échouer en retournant l'une des erreurs décrites dans \fBopen\fP(2) .SH VERSIONS Ces fonctions ont été introduites dans la glibc dans sa version\ 2.12. .SH ATTRIBUTS Pour une explication des termes utilisés dans cette section, consulter \fBattributes\fP(7). .TS allbox; lbw21 lb lb l l l. Interface Attribut Valeur T{ \fBpthread_setname_np\fP(), \fBpthread_getname_np\fP() T} Sécurité des threads MT\-Safe .TE .sp 1 .SH CONFORMITÉ Ces fonctions sont des extensions GNU non standard\ ; d'où le suffixe «\ _np\ » (non portable) dans leur nom. .SH NOTES \fBpthread_setname_np\fP() écrit en interne dans le fichier \fIcomm\fP du thread (dans le système de fichiers \fI/proc\fP)\ : \fI/proc/self/task/[tid]/comm\fP. \fBpthread_getname_np\fP() récupère le nom du thread à ce même endroit. .SH EXEMPLES Le programme ci\-dessous illustre l'utilisation de \fBpthread_setname_np\fP() et de \fBpthread_getname_np\fP(). .PP La session d'interpréteur suivant montre un échantillon d'exécution du programme\ : .PP .in +4n .EX $\fB ./a.out\fP Created a thread. Default name is: a.out The thread name after setting it is THREADFOO. \fB\(haZ\fP # Suspend the program [1]+ Stopped ./a.out $ \fBps H \-C a.out \-o \(aqpid tid cmd comm\(aq\fP PID TID CMD COMMAND 5990 5990 ./a.out a.out 5990 5991 ./a.out THREADFOO $ \fBcat /proc/5990/task/5990/comm\fP a.out $ \fBcat /proc/5990/task/5991/comm\fP THREADFOO .EE .in .SS "Source du programme" \& .EX #define _GNU_SOURCE #include #include #include #include #include #include #define NAMELEN 16 #define errExitEN(en, msg) \e do { errno = en; perror(msg); \e exit(EXIT_FAILURE); } while (0) static void * threadfunc(void *parm) { sleep(5); // permet au programme principal de définir // le nom du thread return NULL; } int main(int argc, char **argv) { pthread_t thread; int rc; char thread_name[NAMELEN]; rc = pthread_create(&thread, NULL, threadfunc, NULL); if (rc != 0) errExitEN(rc, "pthread_create"); rc = pthread_getname_np(thread, thread_name, NAMELEN); if (rc != 0) errExitEN(rc, "pthread_getname_np"); printf("Thread créé. Le nom par défaut est\ : %s\en", thread_name); rc = pthread_setname_np(thread, (argc > 1) ? argv[1] : "THREADFOO"); if (rc != 0) errExitEN(rc, "pthread_setname_np"); sleep(2); rc = pthread_getname_np(thread, thread_name, (argc > 2) ? atoi(argv[1]) : NAMELEN); if (rc != 0) errExitEN(rc, "pthread_getname_np"); printf("Le nom du thread après nommage est %s.\en", thread_name); rc = pthread_join(thread, NULL); if (rc != 0) errExitEN(rc, "pthread_join"); printf("Terminé\en"); exit(EXIT_SUCCESS); } .EE .SH "VOIR AUSSI" .ad l .nh \fBprctl\fP(2), \fBpthread_create\fP(3), \fBpthreads\fP(7) .SH COLOPHON Cette page fait partie de la publication\ 5.10 du projet \fIman\-pages\fP 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/. .SH TRADUCTION La traduction française de cette page de manuel a été créée par Christophe Blaess , Stéphan Rafin , Thierry Vignaud , François Micaux, Alain Portal , Jean-Philippe Guérard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas François , Florentin Duneau , Simon Paillard , Denis Barbier , David Prévot et Frédéric Hantrais . Cette traduction est une documentation libre ; veuillez vous reporter à la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 .UE 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 à .MT debian-l10n-french@lists.debian.org .ME .