architect-handbook

Software Architect Handbook

View on GitHub

Processes & Threads

A quick way to understand this is that:

Definitions

Process

Process means any program in execution. There’s a process Control block which controls the operation of any process and contains information about them, such as priority, id, state, cpu, register, etc. One characteristic of process is that it is isolated, meaning that a process does not share memory with any other process. Thus, each process has its own Control Block, Stack and Address Space.

Processes switching uses interface in operating system (they iteract only through system-provided inter-process communication mechanisms), so context switching is more expensive than with threads. If one server process is blocked no other server process can execute until the first one is unlocked.

A process can create other processes which are known as Child Processess.

Thread

It can be defined as the smallest sequence of programmed instructions that can be managed independently by a scheduler. Implementation of threads and processes differs between operating systems, but in most cases, a thread is a segment of a process. Thus, a process can have multiple threads that can be executed concurrently and share resources such as memory.

In particular, threads of a process share its executable code and the values of its dynamically allocated variables, and non-thread-local global variables at any given time.

Unlike processes:

A thread has 3 states: