Linux Processes vs Threads – Understanding the Difference

lightweightlinuxlinux-kernelprocessthread

As far as I know in Linux kernel,

  • the structure task_struct represents threads i.e. light weight processes, but not processes.

  • processes are not represented by any structure, but by groups of threads sharing the same thread group id.

So is the following from Operating System Concepts correct?

Linux also provides the ability
to create threads using the clone() system call. However, Linux does not
distinguish between processes and threads
. In fact, Linux uses the term task
—rather than process or thread— when referring to a flow of control within a
program.

What does it mean?

Thanks.

Related How does Linux tell threads apart from child processes?

Best Answer

Linux also provides the ability to create threads using the clone() system call. However, Linux does not distinguish between processes and threads. In fact, Linux uses the term task —rather than process or thread— when referring to a flow of control within a program.

We need to distinguish between the actual implementation and the surface you see.

From user (system software developer) point of view there is a big difference: threads share a lot of common resources (e.g. memory mappings - apart from stack, of course - file descriptors).

Internally (warning: imprecise handwaving arguments) the Linux kernel1) is using what it has at hand, i.e. the same structure for processes and for threads, where for threads of a single process it doesn't duplicate some things rather it references a single instance thereof (memory map description).

Thus on the level of directly representing a thread or a process there is not much difference in the basic structure, the devil lies in how the information is handled.

You may as well be interested in reading Are threads implemented as processes on Linux?


1) Remember that "Linux" these days stands mostly for the whole OS, while in fact it only is the kernel itself.