Home > pthread setname np not > pthread_setname_np error

Pthread_setname_np Error

char *name); int pthread_getname_np(pthread_t *thread, const char *name, size_t len); Compile and link with -pthread. 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 set thread name linux a thread, which can be useful for debugging multithreaded applications. The thread name pthread_setname_np not found is a meaningful C language string, whose length is restricted to 16 characters, including the terminating null byte. The thread argument implicit declaration of function ‘pthread_setname_np’ specifies the thread whose name is to be changed; name specifies the new name. The pthread_getname_np() function can be used to retrieve the name of the thread. The thread argument specifies the thread pthread_getname_np whose name is to be retrieved. The buffer name is used to return the thread name; len specifies the number of bytes available in name. The buffer specified by name should be at least 16 characters in length. The returned thread name in the output buffer will be null terminated. Return Value On success, these functions return 0; on error, they return a nonzero error number. Errors

Pthread_getname_np Example

The pthread_setname_np() function can fail with the following error: ERANGE The length of the string specified pointed to by name exceeds the allowed limit. The pthread_getname_np() function can fail with the following error: ERANGE The buffer specified by name and len is too small to hold the thread name. If either of these functions fails to open /proc/self/task/[tid]/comm, then the call may fail with one of the errors described in open(2). Versions These functions first appeared in glibc in version 2.12. Conforming To These functions are nonstandard GNU extensions. Notes pthread_setname_np() internally writes to the thread specific comm file under /proc filesystem: /proc/self/task/[tid]/comm. pthread_getname_np() retrieves it from the same location. Example The program below demonstrates the use of pthread_setname_np() and pthread_getname_np(). The following shell session shows a sample run of the program: $ ./a.out Created a thread. Default name is: a.out The thread name after setting it is THREADFOO. ^Z # Suspend the program [1]+ Stopped ./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 Program source #define _GNU_SOURCE #include #include #include #include

here for a quick overview of the site Help Center Detailed answers to any


questions you might have Meta Discuss the workings and policies pthread_setname_np not working of this site About Us Learn more about Stack Overflow the company Business Learn more about std::thread set name hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow https://linux.die.net/man/3/pthread_setname_np is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why pthread_getname_np() fails in the thread in Linux? up vote 0 down vote favorite This is the snippet of the code. I am able to set the name of thread. http://stackoverflow.com/questions/20975829/why-pthread-getname-np-fails-in-the-thread-in-linux However, I get an error while retrieving the name of the thread. Please help. void *Thread_Function_A(void *thread_arg) { char buf[7]; int rc; pthread_t self; self = pthread_self (); rc = pthread_getname_np(self, buf,7); if ( rc != 0 ) cout<<"Failed getting the name"<

or a NULL-terminated string that specifies the new name. The maximum length is http://www.qnx.com/developers/docs/6.5.0SP1.update/com.qnx.doc.neutrino_lib_ref/p/pthread_setname_np.html _NTO_THREAD_NAME_MAX (defined in ). Library: libc Use the -l c option to qcc to link against this library. This library is usually included automatically. Description: (QNX Neutrino Core OS 6.3.2 or later) The pthread_setname_np() function sets the name of the specified thread to newname. If newname is pthread_setname_np not NULL, the function deletes any name already assigned to the thread. The "np" in the function's name stands for "non-POSIX." If a thread is setting its own name, pthread_setname_np() uses ThreadCtl(). If a thread is setting another thread's name, pthread_setname_np() needs read/write access to the /proc/pid/as entry for set thread name the process. Only one program can have write access to the a process's entry in the /proc filesystem at a time, so if another program (such as a debugger) already has write access to it, pthread_setname_np() fails with an error of EBUSY. For this reason, it's better to have a thread set its own name than have it set by another thread. Returns: EOK Success. E2BIG The name is too long. EBUSY As described above, you're trying to name a thread other than the calling thread, and another program already has write access to /proc/pid/as. EPERM You don't have the appropriate permissions to set the name. Classification: QNX Neutrino Safety: Cancellation point Yes Interrupt handler No Signal handler Yes Thread Yes See also: pthread_getname_np(), ThreadCtl() "Controlling processes via the /proc filesystem" in the Processes chapter of the QNX Neutrino Programmer's Guide


Related content

No related pages.