How is a process and a thread the same thing in Linux?
Linux didn't use to have special support for (POSIX) threads, and it simply treated them as processes that shared their address space as well as a few other resources (filedescriptors, signal actions, ...) with other "processes".
That implementation, while elegant, made certain things required for threads by POSIX difficult, so Linux did end up gaining that special support for threads and your premise is now no longer true.
Nevertheless, processes and threads still both remain represented as tasks within the kernel (but now the kernel has support for grouping those tasks into thread groups as well and APIs for working with those ((tgkill
, tkill
, exit_group
, ...)).
You can google LinuxThreads and NPTL threads to learn more about the topic.
What is the difference between a process and a thread?
Both processes and threads are independent sequences of execution. The typical difference is that threads (of the same process) run in a shared memory space, while processes run in separate memory spaces.
I'm not sure what "hardware" vs "software" threads you might be referring to. Threads are an operating environment feature, rather than a CPU feature (though the CPU typically has operations that make threads efficient).
Erlang uses the term "process" because it does not expose a shared-memory multiprogramming model. Calling them "threads" would imply that they have shared memory.
Linux Kernel: Threading vs Process - task_struct vs thread_info
Threads in Linux are treated as processes that just happen to share some resources. Each thread has its own thread_info
(at the bottom of the stack like you said) and its own task_struct
. I can think of two reasons why they are maintained as separate structures.
thread_info
is architecture dependent.task_struct
is generic.thread_info
cuts into the size of the kernel stack for that process, so it should be kept small.thread_info
is placed at the bottom of the stack as a micro-optimization that makes it possible to compute its address from the current stack pointer by rounding down by the stack size saving a CPU register.
Related Topics
How to Split One Text File into Multiple *.Txt Files
Sed In-Place Flag That Works Both on MAC (Bsd) and Linux
What's the Magic of "-" (A Dash) in Command-Line Parameters
Peak Memory Usage of a Linux/Unix Process
Is There Any API For Determining the Physical Address from Virtual Address in Linux
Can _Start Be the Thumb Function
Extract One Word After a Specific Word on the Same Line
How to Manage Perl Modules When Using a Package Manager
Kdevtmpfsi Using the Entire Cpu
How Do So_Reuseaddr and So_Reuseport Differ
Use Expect in a Bash Script to Provide a Password to an Ssh Command
What Is Double Dot(..) and Single Dot(.) in Linux
Cannot Connect to the Docker Daemon At Unix:/Var/Run/Docker.Sock. Is the Docker Daemon Running
How Are the Fs/Gs Registers Used in Linux Amd64