<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Haindavi-Saraswathi</title>
    <description>The latest articles on DEV Community by Haindavi-Saraswathi (@haindavisaraswathi).</description>
    <link>https://dev.to/haindavisaraswathi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1107266%2F10806f12-db34-4f07-8fa1-6f1c5ce588c6.png</url>
      <title>DEV Community: Haindavi-Saraswathi</title>
      <link>https://dev.to/haindavisaraswathi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/haindavisaraswathi"/>
    <language>en</language>
    <item>
      <title>Process vs Thread</title>
      <dc:creator>Haindavi-Saraswathi</dc:creator>
      <pubDate>Tue, 28 Oct 2025 03:48:30 +0000</pubDate>
      <link>https://dev.to/haindavisaraswathi/process-vs-thread-3ohb</link>
      <guid>https://dev.to/haindavisaraswathi/process-vs-thread-3ohb</guid>
      <description>&lt;p&gt;The entire world of applications revolves around scaling and performance speed — but where does it all begin?&lt;/p&gt;

&lt;p&gt;It all starts right here — with &lt;strong&gt;processes&lt;/strong&gt; and &lt;strong&gt;threads&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To understand a process, we first need to go one step back and look at what a &lt;strong&gt;program&lt;/strong&gt; actually is.&lt;/p&gt;




&lt;h2&gt;
  
  
  Program
&lt;/h2&gt;

&lt;p&gt;A computer isn’t human — it can’t think or decide on its own. We have to give it clear instructions to perform any task.&lt;/p&gt;

&lt;p&gt;These sets of instructions are what we call a &lt;strong&gt;program&lt;/strong&gt;. &lt;br&gt;
But how do we give these instructions? In what form? And how does the machine actually run them?&lt;/p&gt;

&lt;p&gt;From code to CPU , below picture shows how your program comes alive.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv7mrxn5rw13p1i0xmmns.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv7mrxn5rw13p1i0xmmns.png" alt="Let’s say you write a simple Python program to print “Hello, World!”&amp;lt;br&amp;gt;
It begins as code — just a text file with instructions written in Python.&amp;lt;br&amp;gt;
When you run it (python hello.py), Python translates the code and loads it into memory as a process.&amp;lt;br&amp;gt;
Then, the CPU executes those instructions — interpreting and printing the message.&amp;lt;br&amp;gt;
Finally, you see “Hello, World!” appear on your screen." width="760" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that our program is running, let’s talk about what it has become — a &lt;strong&gt;process&lt;/strong&gt;. &lt;/p&gt;




&lt;h2&gt;
  
  
  Process:
&lt;/h2&gt;

&lt;p&gt;A process is simply a program in execution.&lt;br&gt;
It’s not just the code anymore — it’s the code + the resources the operating system gives it to run.  When a process starts, the OS sets up everything it needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory space – where it stores variables, data, and instructions.&lt;/li&gt;
&lt;li&gt;CPU time – the processor cycles it gets to actually run.&lt;/li&gt;
&lt;li&gt;File handles and I/O – to read files, print output, or talk to the network.&lt;/li&gt;
&lt;li&gt;Process ID (PID) – a unique number so the OS can track it.
Every process lives inside its own isolated environment — it can’t directly access another process’s memory.
 &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Okay, so my process is running and it has a bunch of instructions to execute.Should I wait for them to run one by one… or can I somehow speed things up?&lt;/p&gt;

&lt;p&gt;That’s where &lt;strong&gt;threads&lt;/strong&gt; come in.&lt;/p&gt;




&lt;h2&gt;
  
  
  Thread:
&lt;/h2&gt;

&lt;p&gt;A thread is the smallest unit of execution inside a process — like a lightweight worker that helps your program do multiple things at the same time. &lt;br&gt;
A thread is “lightweight” because it takes less memory, less setup, and less time for the OS to manage compared to a process.&lt;/p&gt;

&lt;p&gt;When a program starts, it begins with one thread, the main thread.&lt;br&gt;
From there, you can create additional threads to perform other tasks simultaneously. &lt;/p&gt;

&lt;p&gt;Each thread has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Its own &lt;strong&gt;stack&lt;/strong&gt; (to keep track of function calls and local variables)&lt;/li&gt;
&lt;li&gt;Its own &lt;strong&gt;instruction pointer&lt;/strong&gt; (to know which line of code it’s running)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shared&lt;/strong&gt; access to the &lt;strong&gt;process’s memory&lt;/strong&gt; (heap, global variables, files, etc.)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Process vs Thread
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Aspect&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Process&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Thread&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A program in execution.&lt;/td&gt;
&lt;td&gt;A lightweight unit of execution inside a process.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Memory Space&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Has its &lt;strong&gt;own memory space&lt;/strong&gt; — fully isolated.&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Shares memory&lt;/strong&gt; with other threads in the same process.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Creation Cost&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;High&lt;/strong&gt; — needs new memory and OS resources.&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Low&lt;/strong&gt; — shares process resources; only needs its own stack/registers.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Communication&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Via &lt;strong&gt;Inter-Process Communication (IPC)&lt;/strong&gt; — slower.&lt;/td&gt;
&lt;td&gt;Via &lt;strong&gt;shared memory&lt;/strong&gt; — faster but needs synchronization.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Crash Impact&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;One process crashing doesn’t affect others.&lt;/td&gt;
&lt;td&gt;If one thread crashes, it can crash the entire process.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Context Switching&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Slower&lt;/strong&gt; — switches entire process context.&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Faster&lt;/strong&gt; — switches only registers and stack.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Isolation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Strong isolation&lt;/strong&gt; — safer, but uses more memory.&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Weak isolation&lt;/strong&gt; — faster, but risk of race conditions.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Running &lt;strong&gt;independent apps or services&lt;/strong&gt;.&lt;/td&gt;
&lt;td&gt;Running &lt;strong&gt;parallel tasks&lt;/strong&gt; within the same app.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Scaling Approach&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Horizontal scaling&lt;/strong&gt; — multiple processes across CPU cores, containers, or machines for reliability and load balancing.&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Vertical scaling&lt;/strong&gt; — multiple threads inside one process to use CPU cores efficiently for concurrent tasks.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Performance&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;More reliable under load; startup is heavier.&lt;/td&gt;
&lt;td&gt;Higher throughput for shared-memory tasks; needs careful synchronization.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Examples&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Chrome launching each tab as a separate process; microservices architecture.&lt;/td&gt;
&lt;td&gt;Each Chrome tab’s renderer thread; thread pools in Java or Node.js workers.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Restaurant Analogy:
&lt;/h2&gt;

&lt;p&gt;Imagine your computer as a restaurant.&lt;br&gt;
The &lt;strong&gt;recipe&lt;/strong&gt; is your &lt;strong&gt;program&lt;/strong&gt; — a set of written instructions waiting to be cooked.&lt;/p&gt;

&lt;p&gt;Once the cooking begins, it becomes a &lt;strong&gt;process&lt;/strong&gt; — an active kitchen with its own space, tools, and ingredients.&lt;/p&gt;

&lt;p&gt;Inside that kitchen, several chefs (&lt;strong&gt;threads&lt;/strong&gt;) work together on different parts of the dish — one boils pasta, another stirs sauce — all sharing the same kitchen.&lt;/p&gt;

&lt;p&gt;That’s how each process can have multiple threads, working in parallel to serve the dish faster.&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>beginners</category>
      <category>basic</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
