A process is an instance of a running program. Only when the program is initiated are the processes created.
<aside> 💡 Early computers only supported one process per program.
</aside>

Flow:
A state is the current activity of that process.
Each process may be in one of the following states:
New - The process is being created.
Ready - The process is waiting to be assigned to a processor.
Running - When instructions are being executed.
Waiting - The process is waiting for some event to occur. (Such as I/O completion or signal reception)
Terminated - The process has finished execution.
New → Ready: Upon completion of initialization.Ready → Running: Scheduled by the CPU.Running → Waiting: Needs resources or I/O.Running → Terminated: Completes execution or exits.Waiting → Ready: Required resource becomes available.Running → Ready: Preempted by scheduler.A zombie process, also known as a defunct process, is a process that has completed execution but still has an entry in the process table. This happens when a child process has finished its execution, but its parent process hasn't yet read its exit status.
They're identified by the 'Z' state in process status outputs.
PCB refers to a data structure that keeps track of information about a specific process.

Example of a process control block.
Process State - State of the process.
Process ID - Unique identifier of the process.
Program Counter - Indicates the address of the next instruction that has to be executed.
Registers - Indicates the registers being used by a specific process.
Scheduling Information - Contains the priority of the process, and the pointers to the scheduling queue.
Memory management information - Represents the memory that is being used by a specific process.
Accounting information - Indicates the resources used by the process such as cpu or memory.
List of open file - Each process necessitates the presence of certain files in the main memory during execution. During the process’s execution, PCB keeps track of the files it uses.
Process scheduling is the activity of the process manager that handles the removal of the running process from the CPU and the selection of another process based on a particular strategy.

Non-Preemptive: A process’ resource cannot be taken before the process has finished running.
Preemptive: The process switches from running state to ready state or from waiting state to ready state during resource allocation. This switching happens because the CPU may give other processes priority and substitute the currently active process for the higher priority process.
It brings the new process to the ‘Ready State’. It controls the Degree of Multi-programming, i.e., the number of processes present in a ready state at any point in time. It is important that the long-term scheduler make a careful selection of both I/O and CPU-bound processes. I/O-bound tasks are which use much of their time in input and output operations while CPU-bound processes are which spend their time on the CPU. The job scheduler increases efficiency by maintaining a balance between the two. They operate at a high level and are typically used in batch-processing systems.
It is responsible for selecting one process from the ready state for scheduling it on the running state.
<aside> 💡
Short-term scheduler only selects the process to schedule, it doesn’t load the process on running.
</aside>

The dispatcher is responsible for loading the process selected by the Short-term scheduler by context switching.
It is responsible for suspending and resuming the process, mainly by swapping. Swapping may be necessary to improve the process mix or because a change in memory requirements has overcommitted available memory, requiring memory to be freed up. It is helpful in maintaining a perfect balance between the I/O bound and the CPU bound, by reducing the degree of Multi-programming.
System calls provide an interface to the services made available by an operating system.
User mode
Kernel mode
Most programs run in user mode, but some might need access to resources. Thus, the program calls for requests, and these are called system calls.
| System Call | Purpose |
|---|---|
| open() | Opens a file or device. |
| read() | Reads data from a file or device. |
| write() | Writes data to a file or device. |
| close() | Closes a file or device. |
| fork() | Creates a new process (a child). |
| exec() | Replaces the current process with a new program. |
| socket() | Creates a network socket for communication. |
| bind() | Associates a socket with an address/port |
| listen() | Prepares a socket to accept connections. |
| accept() | Accepts an incoming connection on a socket. |
A system call table is essentially a lookup table in the kernel for the functions. It maps syscall numbers to to their corresponding functions, and jumps to the function address when called.
Here’s what a system call table on a Linux machine might look like:
0 common read sys_read
1 common write sys_write
2 common open sys_open