title: Linux process ID and thread ID
body: <p>Suppose we have many user processes running on Linux. Each process has many threads running.</p>
  
  <p>I can get process ID by calling <code>getpid()</code>, the return value of which is an integer. </p>
  
  <p>I can get thread ID by calling <code>pthread_self()</code>, the return value of which is an opaque type called <code>pthread_t</code>. </p>
  
  <p>Now I need to store the process ID (an int, typically 4 bytes) and the thread ID (<code>pthread_t</code>, need to figure out how many bytes) in shared memory so that I can later use the two pieces of ID information to identify that specific thread and to check if the thread is still running or not.</p>
  
  <p>I've found many online sources cast <code>pthread_t</code> to either <code>unsigned int</code> or <code>unsigned long</code>. Since I don't want any data loss during the casting, how should I deal with the <code>pthread_t</code> data so that it's a fixed-size piece of data (as mentioned, I need to store the thread information in shared memory).</p>
  
  <p>Also, how should I identify that specific thread by combination of process ID and thread ID later? How to check if the thread is still running or not?</p>