A quick introduction to processes in Computer Science

Imdad Codes
4 min readOct 13, 2015

--

Processes and threads in Operating Systems (OS) have always been some of my favourite topics in Computer Science. They allow you to understand, in a much deeper way, how the OS manages programs during their different stages of execution, tackle issues regarding memory and ensure isolated security right down to the kernel. It’s just bloody interesting!

The basic idea

A process is simply a program in execution. One program strictly has one process associated with it. In very rare cases this may not always be true (Google Chrome as an example), but this is true a majority of the time.

A process in memory

Each process has different components that allow it to perform its intended tasks. Notably, the stack and heap are used for local variable and dynamic memory allocation respectively.

There are more components but sufficed to say that each process needs these components to run as a program.

Monitoring processes in the system

At any given time there may be a couple hundred or less processes running. Sometimes it useful to see detailed information about them, especially if your computer is running slow: as certain processes may be hogging the computer’s memory or the CPU. Being able to pinpoint and subsequently destroy them is very handy indeed and can be achieved fairly easily.

If you’re running Windows, you can open up the Task Manager and click the Processes tab to see this information. If you’re running Linux or a Unix based machine you can run a number of different commands:

ps aux // this will display a list of processestop // detailed information about all processes, threads, memory hoggers and network packets

How does the operating system manage processes

A process can be in a particular state at any given time. It may have just been created, waiting to run, waiting for access to some I/O device, interrupted by some other process etc. To ensure maximal productivity, the operating system needs to understand the state of all of these processes and be able to intelligently create new ones, switch between them, pause them, suspend them etc. at the right times.

A process control block

To do this effectively, the operating system maintains what’s known as a Process Control Block for each process. It contains useful information such as the current process state, the next instruction to perform and currently allocated devices to the process.

This enables the operating system to manage different processes effectively, by saving the current state in the PCB, switching between them and reloading certain processes later on.

How does the operating switch between different processes

Context switching with PCB’s

Context switching refers to the specific activity where an operating system saves the state of a running process and pauses it in order to run another one. It must do so in a way that ensures these processes do not conflict, and that the saved process can be resumed later on without any issues. This ensures a key feature in operating systems: multitasking. The diagram shows how the PCB is used to save the state of the process, run another, and then reload and continue the initial one later on.

That’s all for now.

In the next article we’ll go over parent-child processes, scheduling and how processes can communicate with each other using IPC (sockets and pipes).

Click the Follow button to receive a notification when the new article is published.

In the meantime you can check out my other articles…

Or watch my tutorial videos on YouTube

Or reach out to me

on Facebook, Twitter, LinkedIn or my website

Credits

Special thanks to

for early draft comments

--

--

Imdad Codes

Cofounder and CTO @ LiveLinkAI | Creator @imdadcodes (10M+ Reach)