Use pthread_self(3C) to get the thread identifier of the calling thread.
pthread_t pthread_self(void);
#include <pthread.h> pthread_t tid; tid = pthread_self();
pthread_self() returns the thread identifier of the calling thread.