Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In Linux threads are defined as "tasks".</p> <p>Each task is an individual execution unit within a process. They all have their individual task id <code>tid</code> - related to process ids (<code>pid</code>s).</p> <p>Each process comes with one main task when it starts and that "main" task identifies the process and indeed the process id <code>pid</code> is the task id <code>tid</code> of the main task.</p> <p>The process state in terms of execution resembles that of the main task including the status <code>R</code>, <code>D</code>, <code>S</code>...</p> <p>So if your process is marked as <code>D</code> (Disk sleep) it just means that the main task is in disk sleep. All other tasks (threads) could be doing anything else.</p> <p>Check <code>/proc/[pid]/task/[tid]/stat</code> for individual task states.</p> <p>Also <code>ps -eLf</code> to display ps entries for tasks.</p> <p>Try this code:</p> <pre><code>#include &lt;pthread.h&gt; #include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; void * thread_sleep() { long long int i = -1; while (i--); exit(0); return NULL; } int main() { pthread_t thread; pthread_create(&amp;thread, NULL, thread_sleep, NULL); getchar(); return 0; } </code></pre> <p>Run it and do</p> <pre><code>cat /proc/$PID/stat cat /proc/$PID/task/*/stat </code></pre> <p>You will notice that the process has status <code>S</code> (waiting for terminal input) as does the first task (same <code>tid</code> as the process <code>pid</code>) while the other thread is <code>R</code>. If you set <code>i</code> to something smaller it will actually finish at some point.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload