【问题标题】:ubuntu cannot find "gettid" function?ubuntu 找不到“gettid”功能?
【发布时间】:2017-05-23 20:31:39
【问题描述】:

我有一个非常小的程序来测试线程相关的东西:

#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;
}

在 vim 编辑器中,我专注于 'gettid' 和 Shift-K,gettid 的手册页说它在 sys/types 中。没问题,编译的时候报错:

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 上使用新的 gcc 版本。如何解决?

【问题讨论】:

标签: c++ linux compilation pthreads posix


【解决方案1】:

使用:pid_t tid = syscall(SYS_gettid); 因为这不能直接调用。

【讨论】:

    猜你喜欢
    • 2020-03-31
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多