pthread_getname_np()--Get Thread Name
Syntax
#include <pthread.h> int pthread_getname_np(pthread_t thread, char *name);Service Program Name: QP0WPTHR
Default Public Authority: *USE
Threadsafe: Yes
Signal Safe: Yes
The pthread_getname_np() function retrieves the name of the thread. The buffer specified by name must be at least 16 characters in length. The returned thread name will be null terminated in the output buffer.
By default, each thread is unnamed. If the pthread_setname_np() function has not been used to set the name of the specified thread, a null string is retrieved into name.
Note: This function is not portable.
Parameters
- thread
- (Input) Pthread handle to the target thread
- name
- (Output) Address of a 16-byte character buffer to receive the thread name
Authorities and Locks
None.
Return Value
- 0
- pthread_getname_np() was successful.
- value
- pthread_getname_np() was not successful. value is set to indicate the error condition.
Error Conditions
If pthread_getname_np() was not successful, the error condition returned usually indicates one of the following errors. Under some conditions, the value returned could indicate an error other than those listed here.
- [EINVAL]
The value specified for the argument is not correct. Either the thread parameter is not a valid thread handle or name is not a valid pointer.
Usage Notes
- No CCSID conversion is performed when storing or displaying the name.
Related Information
- The <pthread.h> header file. See Header files for Pthread functions.
- pthread_setname_np()--set Thread Name
Example
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
#define _MULTI_THREADED #include <pthread.h> #include <stdio.h> #include <string.h> #include <unistd.h> void *threadfunc(void *parm) { printf("In the thread.\n"); sleep(45); // allow main program to set the thread name return NULL; } int main(int argc, char **argv) { pthread_t thread; int rc=0; char theName[16]; memset(theName, 0x00, sizeof(theName)); printf("Create thread using the default attributes\n"); rc = pthread_create(&thread, NULL, threadfunc, NULL); if(0 == rc) { rc = pthread_setname_np(thread, "THREADNAMEISTOOLONG"); sleep(10); if(0 == rc) { rc = pthread_getname_np(thread, theName); if(0 == rc) { printf("The thread name is %s.\n", theName); } } rc = pthread_join(thread, NULL); } if(0 != rc) { printf("An error occurred - %d\n", rc); } printf("Main completed\n"); return(rc); }Example Output:
Create thread using the default attributes The thread name is THREADNAMEISTOO. In the thread. Main completed
API introduced: IBM® i 7.1
[ Back to top | Pthread APIs | APIs by category ]