ubuntu找不到gettid函数?
我有一个非常小的程序来测试pthread基本功能:gettid:#include<unistd.h>
#include<sys/types.h>
#include<stdio.h>
int main()
{
pid_t pid=getpid();
pid_t tid=gettid();
printf("%d,%d\n",pid,tid);
return 0;
}我在vi里面,光标定位gettid按下Shift-K都可以看到man里面说,gettid包含于sys/types.h
但是我一编译这个文件,g++就报错:
g++ mythread.cpp
mythread.cpp: In function ‘int main()’:
mythread.cpp:7:22: error: ‘gettid’ was not declared in this scope
pid_t tid=gettid();
^
这个到底是怎么回事呢?
我在ubuntu1604
回复 1# asker160
你没看到 gettid(2) 里面有说
Note: There is no glibc wrapper for this system call; see NOTES.
应该用 tid = syscall(SYS_gettid);
页:
[1]