title: How to get the SPID in linux 2.6 from C++
body: <p>I have a question: Is there some way to the SPID in linux 2.6 from a C++ application?  When I do a "ps -amT" I can see the threads in the process:</p>
  
  <pre><code>root@10.67.100.2:~# ps -amT
    PID  SPID TTY          TIME CMD
   1120     - pts/1    00:00:20 sncmdd
      -  1120 -        00:00:00 -
      -  1125 -        00:00:00 -
      -  1126 -        00:00:00 -
      -  1128 -        00:00:00 -
      -  1129 -        00:00:09 -
      -  1130 -        00:00:00 -
      -  1131 -        00:00:09 -
   1122     - pts/1    00:00:00 snstatusdemuxd
      -  1122 -        00:00:00 -
      -  1127 -        00:00:00 -
      -  1132 -        00:00:00 -
      -  1133 -        00:00:00 -
  </code></pre>
  
  <p>And then in the filesystem I can see the threads:</p>
  
  <pre><code>root@10.67.100.2:~# ls /proc/1120/task/
  1120  1125  1126  1128  1129  1130  1131
  </code></pre>
  
  <p>So is there some way I can get the SPID from my application so I can somehow identify what my SPID is in each running thread?</p>
  
  <p>Thanks!</p>
  
  <p>/Mike</p>
  
  <p>Edit: I should add that the PID returned from getpid() is the same in each thread.</p>
  
  <p>When I add this code to my threads:</p>
  
  <pre><code>// Log thread information to syslog
  syslog(LOG_NOTICE, "ibnhwsuperv: gettid()= %ld,  pthread_self()=%ld", (long int)syscall(224), pthread_self());
  </code></pre>
  
  <p>I get this result:</p>
  
  <pre><code>Jan  1 01:24:13 10 ibnhwsupervd[1303]: ibnhwsuperv: gettid()= -1,  pthread_self()=839027488
  </code></pre>
  
  <p>Neither of which look like the SPID given by ps or in the proc filesystem.</p>
  
  <p>Also, note that <a href="http://ubuntuforums.org/showthread.php?t=345317" rel="nofollow noreferrer">gettid does not return the SPID</a>.</p>