1

In my knowing, a thread is an execution flow of a process and all the threads of a process share some common structures. Furthermore, in modern PC the CPU executes only threads, not processes.

What I don't undertand is the meaning of term process and thread in Linux. Linux really distinguish between process and thread? And which is the role of the task_struct structure?

I've read that Linux schedules task_struct for execution, so I thought that task_struct represent a thread and not a process, but looking inside the definition of task_struct I saw that there is a reference to the children of task_struct. A thread can really have a child?

Bender
  • 121
  • I've found a very interesting explanation in the first answer of this question: https://unix.stackexchange.com/questions/31595/are-linux-kernel-threads-really-kernel-processes?rq=1 – Bender Jun 16 '22 at 15:22

1 Answers1

2

On a user level a process belongs to the OS. The process, has a copy of environment and standard file descriptors (stdin, stdout, stderr), which are inherited from the OS. Threads are belong to a process, and several threads belonging to the same process are sharing environment and file descriptors of that process.

And yes, both processes and threads can have children. The word child here is just referring to a new process/thread which was created by OS on a request from an existing process/thread.

task_struct is a thingy which makes processes and threads possible. It is how they are made inside. But on a user level, there is no access to task_struct. If you writing your own kernel - then sure you would have to work with it, and with the scheduler.

So if you dive into the kernel and/or how CPU works - then yes, there is no real difference between process and thread, since they are done by the same actual real life process. The difference is only on a user level, in how the actual application works.

I would suggest you to obtain a copy and read "Modern Operating Systems" by Andrew Tanenbaum, https://www.amazon.com/Modern-Operating-Systems-Andrew-Tanenbaum/dp/013359162X/ It is the best textbook on the subject.

White Owl
  • 5,129