4

Do all threads of a specific process share the same status (D, R, S, ...) or may there be differences among these threads?

If so, where in /proc do I find information about the status of a certain thread? I am reading the process status from the /proc/<PID>/status files at the moment.

2 Answers 2

4

Different threads can certainly be in a different scheduler state at the same time. In fact, if they're all in the same state, that's a coincidence (except for stopped (Z), because that affects the whole process).

The subdirectory /proc/PID/task contains a subdirectory per thread of the process. The files in this directory are mostly the same as in the per-process directory. Some of the information is just duplicated (e.g. memory-related information, environment, privileges, etc.). Information that's specific to a thread, such as the scheduler state (running/sleeping/IO/…), can differ.

1

You can use ps command to find out about the status of all the threads of a process:

ps H -p 27901

This will show all the threads related to process 27901 and their status.

2
  • Thank you! I would rather prefer to not use an external program but to rather read these information from \proc directly Commented May 19, 2016 at 10:26
  • OK. By the way ps gets its information from proc file system. This could be useful man7.org/linux/man-pages/man5/proc.5.html
    – Vombat
    Commented May 19, 2016 at 10:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .