.\" -*- coding: UTF-8 -*- '\" t .\" Copyright 2012, Chandan Apsangi .\" Copyright 2013, Michael Kerrisk .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH pthread_setname_np 3 "8 février 2026" "Pages du manuel de Linux 6.18" .SH NOM pthread_setname_np, pthread_getname_np \- Définir ou obtenir le nom d'un thread .SH BIBLIOTHÈQUE Bibliothèque de threads POSIX (\fIlibpthread\fP,\ \fI\-lpthread\fP) .SH SYNOPSIS .nf \fB#define _GNU_SOURCE\fP /* Consultez feature_test_macros(7) */ \fB#include \fP .P \fBint pthread_setname_np(pthread_t \fP\fIthread\fP\fB, const char *\fP\fIname\fP\fB);\fP \fBint pthread_getname_np(\fPsize_t size; \fB pthread_t \fP\fIthread\fP\fB, char \fP\fIname\fP\fB[\fP\fIsize\fP\fB], size_t \fP\fIsize\fP\fB);\fP .fi .SH DESCRIPTION By default, all the threads created using \fBpthread_create\fP() inherit the program name. The \fBpthread_setname_np\fP() function can be used to set a unique name for a thread, which can be useful for debugging multithreaded applications. The thread name is a meaningful C language string, whose length is restricted to 16 characters, including the terminating null byte (\[aq]\[rs]0\[aq]). The \fIthread\fP argument specifies the thread whose name is to be changed; \fIname\fP specifies the new name. .P 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 \fInom\fP est utilisé pour renvoyer le nom du thread ; \fItaille\fP indique le nombre d'octets disponibles dans \fInom\fP. La longueur du tampon indiqué dans \fInom\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 \fInom\fP dépasse la limite autorisée. .P La fonction \fBpthread_getname_np\fP() peut échouer avec l'erreur suivante : .TP \fBERANGE\fP Le tampon indiqué par \fInom\fP et \fItaille\fP a une taille insuffisante pour contenir le nom du thread. .P Si l'une de ces fonctions ne parvient pas à ouvrir \fI/proc/self/task/\fPtid\fI/comm\fP, alors l'appel peut échouer en retournant l'une des erreurs décrites dans \fBopen\fP(2) .SH ATTRIBUTS Pour une explication des termes utilisés dans cette section, consulter \fBattributes\fP(7). .TS allbox; lbx lb lb l l l. Interface Attribut Valeur T{ .na .nh \fBpthread_setname_np\fP(), \fBpthread_getname_np\fP() T} Sécurité des threads MT\-Safe .TE .SH NORMES GNU ; d'où le suffixe « _np » (non portable) dans leur nom. .SH HISTORIQUE glibc 2.12. .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/\fPtid\fI/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(). .P La session d'interpréteur suivant montre un échantillon d'exécution du programme : .P .in +4n .EX $\fB ./a.out\fP; Created a thread. Default name is: a.out The thread name after setting it is THREADFOO. \f[B]\[ha]Z\fR # Suspend the program [1]+ Stopped ./a.out $ \fBps H \-C a.out \-o \[aq]pid 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" .\" SRC BEGIN (pthread_setname_np.c) \& .EX #define _GNU_SOURCE #include #include #include #include #include #include #include \& #define NAMELEN 16 \& static void * threadfunc(void *parm) { sleep(5); // allow main program to set the thread name 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) errc(EXIT_FAILURE, rc, "pthread_create"); \& rc = pthread_getname_np(thread, thread_name, NAMELEN); if (rc != 0) errc(EXIT_FAILURE, rc, "pthread_getname_np"); \& printf("Created a thread. Default name is: %s\[rs]n", thread_name); rc = pthread_setname_np(thread, (argc > 1) ? argv[1] : "THREADFOO"); if (rc != 0) errc(EXIT_FAILURE, rc, "pthread_setname_np"); \& sleep(2); \& rc = pthread_getname_np(thread, thread_name, NAMELEN); if (rc != 0) errc(EXIT_FAILURE, rc, "pthread_getname_np"); printf("The thread name after setting it is %s.\[rs]n", thread_name); \& rc = pthread_join(thread, NULL); if (rc != 0) errc(EXIT_FAILURE, rc, "pthread_join"); \& printf("Done\[rs]n"); exit(EXIT_SUCCESS); } .EE .\" SRC END .SH "VOIR AUSSI" .ad l .nh \fBprctl\fP(2), \fBpthread_create\fP(3), \fBpthreads\fP(7) .PP .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 , Frédéric Hantrais et Jean-Pierre Giraud . .PP 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. .PP 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 .