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?

1

1 Answer 1

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.

1
  • thank you for the answer and for the book suggestion
    – Bender
    Jun 16 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.