今天测试我的扫描器,通过一些资源查看工具之能够看到每个线程的TID,但是不是通过pthread_self得到的线程ID,想通过类似getpid的函数来获得tid,于是写了一个gettid。
由于gettid是Linux特有的系统调用,不是POSIX标准的,因此Glibc没有提供对应的封装函数,只能够使用syscall实现。
#include <sys/types.h>
#include <unistd.h>
#include <sys/syscall.h> /* For SYS_xxx definitions */
pid_t gettid()
{
return syscall(SYS_gettid);
} |