Menu Home

linux c++: 获取线程号

#include <iostream>
#include <sys/types.h>
#include <pthread.h>
#include <sys/syscall.h>

using namespace std;

pid_t gettid() {

    return syscall(SYS_gettid);
}

int main() {

    pid_t t;
    t = gettid();
    cout << "pid_t = " << t << endl;
    return 0;
}

Categories: C/C++

Tagged as:

lnmcc