Popular Posts

Friday, November 5, 2010

Get thread Id in Linux

Pthread library provides the call pthread_self to get task id but this id is not the same as linux provided thread id, Linux view all the threads as LWP(light weight process) and identify using thread id, to get the linux thread id we need to use syscall system call, glibc doesn't provide the gettid function, so we define our own.

pid_t gettid (void)
{
        return syscall(__NR_gettid);
}

No comments:

Post a Comment