Files
system-design-101/data/guides/what-is-the-difference-between-process-and-thread.md
Kamran Ahmed ee4b7305a2 Adds ByteByteGo guides and links (#106)
This PR adds all the guides from [Visual
Guides](https://bytebytego.com/guides/) section on bytebytego to the
repository with proper links.

- [x] Markdown files for guides and categories are placed inside
`data/guides` and `data/categories`
- [x] Guide links in readme are auto-generated using
`scripts/readme.ts`. Everytime you run the script `npm run
update-readme`, it reads the categories and guides from the above
mentioned folders, generate production links for guides and categories
and populate the table of content in the readme. This ensures that any
future guides and categories will automatically get added to the readme.
- [x] Sorting inside the readme matches the actual category and guides
sorting on production
2025-03-31 22:16:44 -07:00

1.9 KiB
Raw Permalink Blame History

title, description, image, createdAt, draft, categories, tags
title description image createdAt draft categories tags
Process vs Thread: Key Differences Understand the core differences between processes and threads. https://assets.bytebytego.com/diagrams/0304-program-process-thread.png 2024-03-12 false
computer-fundamentals
Operating Systems
Concurrency

To better understand this question, lets first take a look at what a Program is. 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.

The following process explains the relationship between program, process, and thread.

  1. The program contains a set of instructions.

  2. The program is loaded into memory. It becomes one or more running processes.

  3. When a process starts, it is assigned memory and resources. A process can have one or more threads. For example, in the Microsoft Word app, a thread might be responsible for spelling checking and the other thread for inserting text into the doc.

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.