Find the answer to your Linux question:
Results 1 to 3 of 3
What is the quickest way to get the thread id(tid) of the current thread in linux? Specifically I use fedora 13. ...and I am talking about inside a C++ program....
  1. #1
    Just Joined!
    Join Date
    May 2010
    Posts
    28

    Quickest way to get thread id(tid?)?

    What is the quickest way to get the thread id(tid) of the current thread in linux?

    Specifically I use fedora 13. ...and I am talking about inside a C++ program.

  2. #2
    Linux Newbie
    Join Date
    Mar 2010
    Posts
    121
    There is a system call for this, but not a library call, so you have to use the syscall() interface to invoke the gettid() system call:

    • #define _GNU_SOURCE
    • #include unistd.h, sys/syscall.h and sys/types.h
    • Call `syscall(SYS_gettid)', which returns a value of type pid_t

  3. #3
    Linux Newbie
    Join Date
    Apr 2007
    Posts
    119
    pthread_self() will return the thread id of the calling thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...