Back 2 BaseCS : OS : Process and Applications

Kshitij Agrawal
Back 2 baseCS
Published in
3 min readJul 20, 2024

Let me help you process this~

A process is “a series of actions or steps taken in order to achieve a particular end”. The term ‘process’ in computers also comes from the same origins. It used to be called a ‘job’ earlier but it means the same thing — it executes a series of steps in order to achieve a goal.

More technically, a program is some code which sits on your computer, while a process is an executing version of the aforementioned program.

A process is composed of several components — the ‘program’ itself, the memory allocated to it, a process control block (an object in the Operating System) containing information like process state (running, waiting etc.), process counter (address of the next instruction to be executed) and the process threads information.

Process Memory

A memory allocated to a process is divided into several sections. A brief summary of them below -

  • Text section contains your code. It is also called ‘image’ sometimes.
  • Data section contains global variables.
  • Heap section contains dynamically allocated memory during execution.
  • Stack section contains temporary memory (like function params, local variables etc.). [Now you know why endless recursive function calls can cause ‘stack’ overflow!]
Figure 1 — Various sections of memory

Process State

A process can be in many states, and these are different in different Operating systems.

  • New — State of a newly created process.
  • Running — Program under execution.
  • Waiting — Process is waiting for an event (I/O completion).
  • Ready — Ready for execution and waiting to be assigned to a CPU.
  • Terminated — finished execution.

At a given time, on a CPU core only one process can be ‘Running’.

Process Control Block

This object is a representation of a process in an OS, and contains -

  • Process State — mentioned above
  • Process Counter — next instruction to be executed
  • CPU registers — registers are small, fast storage locations within the CPU that hold temporary data during the execution. These are saved to memory when context switch happens, along with Process counter.
  • Other information — file handles, I/O devices, statistics, etc.

Check this task_struct here (line 756) — https://github.com/torvalds/linux/blob/master/include/linux/sched.h

Threads

A thread is the smallest unit of execution within a process. Different threads in a process share the ‘text’, ‘data’ and other information sections of the process memory.

In a single core system, the threads are just interleaved. One thread stops running , maybe is waiting for an I/O and other can execute. While on a multicore system, different threads can execute on different cores parallelly.

Courtesy: Abraham Silberschatz, Greg Gagne, and Peter Baer Galvin, “Operating System Concepts, Eighth Edition “, Chapter 4

In coming days and months, we will dig deeper into each of the OS components and learn concepts and implementations. If you are interested to learn these and up-level your computer engineering skills, please consider subscribing to this newsletter.

If you loved this piece, please consider leaving a small tip to keep me motivated! Your support means a lot!

--

--

Kshitij Agrawal
Back 2 baseCS

Director Of Engineering @ Microsoft Azure | IIT Roorkee