在linux中没有像获取进程ID的方法(getpid()),所以我们需要自己定义,需要调用syscall(),因此要包含头文件syscall.h,具体的方法如下:
#include <sys/syscall.h>
#define gettid() syscall(__NR_gettid)
然后我们就可以用宏gettid()获取线程的ID。
#include <sys/syscall.h>
#define gettid() syscall(__NR_gettid)
然后我们就可以用宏gettid()获取线程的ID。