call gettid witin glibc

后端 未结 1 783
梦如初夏
梦如初夏 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 
    #include 
    #include 
    #include 
    
    int main()
    {
        long tid;
    
        tid = syscall(SYS_gettid);
        printf("%ld\n", tid);
        return EXIT_SUCCESS;
    }
    

    0 讨论(0)
提交回复
热议问题