What is the technical difference between a process and a thread?
I get the feeling a word like \'process\' is overused and there are also hardware and software threa
Trying to answer it from Linux Kernel's OS View
A program becomes a process when launched into memory. A process has its own address space meaning having various segments in memory such as .text
segement for storing compiled code, .bss
for storing uninitialized static or global variables, etc.
Each process would have its own program counter and user-space stack.
Inside kernel, each process would have its own kernel stack (which is separated from user space stack for security issues) and a structure named task_struct
which is generally abstracted as the process control block, storing all the information regarding the process such as its priority, state,(and a whole lot of other chunk).
A process can have multiple threads of execution.
Coming to threads, they reside inside a process and share the address space of the parent process along with other resources which can be passed during thread creation such as filesystem resources, sharing pending signals, sharing data(variables and instructions) therefore making threads lightweight and hence allowing faster context switching.
Inside kernel, each thread has its own kernel stack along with the task_struct
structure which defines the thread. Therefore kernel views threads of same process as different entities and are schedulable in themselves. Threads in same process share a common id called as thread group id(tgid
), also they have a unique id called as the process id (pid
).