Man page - pthread_setname_np(3)

Packages contains this manual

Available languages:

en fr ja ru ro

Manual

pthread_setname_np

NOM
BIBLIOTHÈQUE
SYNOPSIS
DESCRIPTION
VALEUR RENVOYÉE
ERREURS
ATTRIBUTS
STANDARDS
HISTORIQUE
NOTES
EXEMPLES
Source du programme
VOIR AUSSI
TRADUCTION

NOM

pthread_setname_np, pthread_getname_np - DĂ©finir ou obtenir le nom d’un thread

BIBLIOTHÈQUE

BibliothĂšque de threads POSIX ( libpthread , -lpthread )

SYNOPSIS

#define _GNU_SOURCE /* Consultez feature_test_macros(7) */
#include <pthread.h>

int pthread_setname_np(pthread_t thread , const char * nom );
int pthread_getname_np(pthread_t
thread , char nom [. taille ], size_t taille );

DESCRIPTION

By default, all the threads created using pthread_create () inherit the program name. The pthread_setname_np () 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 ('\0'). The thread argument specifies the thread whose name is to be changed; name specifies the new name.

La fonction pthread_getname_np () permet de rĂ©cupĂ©rer le nom du thread. L’argument thread indique le thread dont le nom doit ĂȘtre rĂ©cupĂ©rĂ©. Le tampon nom est utilisĂ© pour renvoyer le nom du thread ; taille indique le nombre d’octets disponibles dans nom . La longueur du tampon indiquĂ© dans nom doit ĂȘtre d’au moins 16 caractĂšres. Le nom du thread renvoyĂ© dans le tampon de retour est terminĂ© par caractĂšre nul.

VALEUR RENVOYÉE

En cas de succùs, ces fonctions renvoient 0 ; en cas d’erreur, elles renvoient un code d’erreur non nul.

ERREURS

La fonction pthread_setname_np () peut Ă©chouer avec l’erreur suivante :

ERANGE

La longueur de la chaßne vers laquelle pointe nom dépasse la limite autorisée.

La fonction pthread_getname_np () peut Ă©chouer avec l’erreur suivante :

ERANGE

Le tampon indiqué par nom et taille a une taille insuffisante pour contenir le nom du thread.

Si l’une de ces fonctions ne parvient pas Ă  ouvrir /proc/self/task/ tid /comm , alors l’appel peut Ă©chouer en retournant l’une des erreurs dĂ©crites dans open (2)

ATTRIBUTS

Pour une explication des termes utilisés dans cette section, consulter attributes (7).

Image grohtml-3881633-1.png

STANDARDS

GNU ; d’oĂč le suffixe « _np » (non portable) dans leur nom.

HISTORIQUE

glibc 2.12.

NOTES

pthread_setname_np () Ă©crit en interne dans le fichier comm du thread (dans le systĂšme de fichiers /proc ) : /proc/self/task/ tid /comm . pthread_getname_np () rĂ©cupĂšre le nom du thread Ă  ce mĂȘme endroit.

EXEMPLES

Le programme ci-dessous illustre l’utilisation de pthread_setname_np () et de pthread_getname_np ().

La session d’interprĂ©teur suivant montre un Ă©chantillon d’exĂ©cution du programme :

$ ./a.out
Thread créé. Le nom par défaut est : a.out
Le nom du thread aprĂšs nommage est THREADFOO.
^Z
# Suspendre l’exĂ©cution du programme
[1]+ Stoppé ./a.out
$ ps H -C a.out -o ’pid tid cmd comm’
PID TID CMD COMMAND
5990 5990 ./a.out a.out
5990 5991 ./a.out THREADFOO
$ cat /proc/5990/task/5990/comm
a.out
$ cat /proc/5990/task/5991/comm
THREADFOO

Source du programme

#define _GNU_SOURCE
#include <err.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#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\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.\n", thread_name);
rc = pthread_join(thread, NULL);
if (rc != 0)
errc(EXIT_FAILURE, rc, "pthread_join");
printf("Done\n");
exit(EXIT_SUCCESS);
}

VOIR AUSSI

prctl (2), pthread_create (3), pthreads (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-Pierre Giraud <jean-pierregiraud@neuf.fr>

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 .