gettid(2) -- Linux man page
NAMEgettid - get thread identification
DESCRIPTIONgettid returns the thread ID of the current process. This is equal to the process ID (as returned by getpid(2)), unless the process is part of a thread group (created by specifying the CLONE_THREAD flag to the clone(2) system call). All processes in the same thread group have the same PID, but each one has a unique TID.
RETURN VALUEOn success, returns the thread ID of the current process.
ERRORSThis call is always successful.
CONFORMING TOgettid is Linux specific and should not be used in programs that are intended to be portable.
SEE ALSOgetpid(2), clone(2), fork(2)