call gettid witin glibc

后端 未结 1 784
梦如初夏
梦如初夏 2021-01-12 18:17

I am working in glibc and I need to get the id of the current thread. For this i use syscall(SYS_gettid); Issue is, i am forced to include bits/syscall.h

相关标签:
1条回答
  • 2021-01-12 18:39

    gettid() is a system call. As for as I know there is no glibc wrapper for gettid. You need to invoke gettid() using syscall(). The following code works for me.

    #include <sys/syscall.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    int main()
    {
        long tid;
    
        tid = syscall(SYS_gettid);
        printf("%ld\n", tid);
        return EXIT_SUCCESS;
    }
    
    0 讨论(0)
提交回复
热议问题