DEV Community

Cover image for Popular interview question: What is the difference between Process and Thread ?
Mounira Say
Mounira Say

Posted on

1

Popular interview question: What is the difference between Process and Thread ?

To better understand this question, let's first take a look at what is a program.A program is an executable file containing a set of instructions and passively stored on disk.
One program can have multiple processes.For example, the chrome browser creates a different process for every single tab.
A Process means a program is in execution.When a program is loaded into the memory and becomes active, the program becomes a process.The process requires some essential resources such as registers,program counter,and stack.

A Thread is the smallest unit of execution within a process.

Main differences between process and thread:

  • processes are usually independent,while threads exist as subsets of a process.
  • Each process has its own memory space.Threads that belong to the same process share the same memory. -A process is a heavyweight operation. It takes more time to create and terminate. -Context switching is more expensive between processes. -Inter-thread communication is faster for threads.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay