Use pthread_self() to get the ID of the calling thread.
Prototype: pthread_t pthread_self(void);
#include <pthread.h> pthread_t tid; tid = pthread_self();
Returns the ID of the calling thread.