The method for obtaining the thread id in linux-Linux general technology-Linux programming and kernel information. The following is a detailed description. I used the second method, which is very convenient:
# Define gettid () syscall (_ NR_gettid)
Gettid ()
After linux2.4, linux uses NPTL as its own thread library. to be compatible with the POSIX standard, there are two domain tgids and tid in the kernel task. The former is the process id, the latter is the thread id. I know three methods to obtain the thread id in linux. Of course, the three methods here refer to user-state programs. Otherwise, unless you write your own kernel module, all are implemented by calling the system call number 224 (version 2.6 ).
First: gettid (), man gettid, you can see how to use gettid.
Define _ syscall0 (pid_t, gettid) before use)
_ Syscall0 is a macro (because of the different parameters, there are _ syscall1, _ syscall2. ..), which is defined as follows: