Processes and threads

Krantibrid
3 min readSep 27, 2021

Photo by Noor Sethi on Unsplash

Whenever we run a program on our computer, we start something called a process. The process simply means any program that is in execution.
A process contains threads. Threads are units of instruction that are waiting to be executed by the CPU. In an easy language, we can say that one process can contain a single to many threads. To show you a live example of multiple processes and threads on your computer, simply open the task manager (activity monitor for mac.)

Currently, I have 310 active processes and 3941 threads. This clearly indicates that every process has multiple threads.
You can picture a thread right here as being like a little to-do list that has some number of instructions

This thread goes to the CPU and the CPU runs every instruction on it.

These threads can have some real and urgent responsibilities to carry on such as a thread can be responsible for ensuring the keyboard typing is done properly or the mouse cursor is moving in the right direction as the user wants it to be; these are some high-priority tasks that the CPU needs to run urgently so else the user might think that his system is broken 😶. In such cases, ur OS scheduler comes into the picture. OS scheduler has to figure out a way to make sure that no thread has to wait for a considerable long time and urgent tasks are run on priority.
Deciding which order to execute these threads in is referred to as scheduling.
Scheduling is controlled by your operating system. Two ways of improving the rate at which we process threads is to either add more CPU courses to our machine or to allow our OS scheduler to detect big pauses in processing time due to expensive input and output operations. There are various scheduling algorithms used by the OS for optimizing thread processing.

These threads are then run on our CPU core. Every core can run one or more threads at one particular time, this is called multithreading. We can add more cores to our system to increase the speed of processing the threads.

This was a basic overview of the entire thread, process, scheduling world!

Now, when you come across lines like “Javascript is a single threaded language”, you will understand it better. Languages like javascript takes only one thread for its execution.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response