Chinaunix

标题: ubuntu找不到gettid函数? [打印本页]

作者: asker160    时间: 2017-01-09 22:38
标题: ubuntu找不到gettid函数?
我有一个非常小的程序来测试pthread基本功能:gettid:
  1. #include<unistd.h>
  2. #include<sys/types.h>
  3. #include<stdio.h>
  4. int main()
  5. {
  6.   pid_t pid=getpid();
  7.   pid_t tid=gettid();
  8.   printf("%d,%d\n",pid,tid);
  9.   return 0;
  10. }
复制代码
我在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


作者: MMMIX    时间: 2017-01-10 19:39
回复 1# asker160

你没看到 gettid(2) 里面有说
Note: There is no glibc wrapper for this system call; see NOTES.


作者: CrazyBoy_P    时间: 2017-01-11 09:58
应该用 tid = syscall(SYS_gettid);




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2