<?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>Forem: Nadeem Rashid</title>
    <description>The latest articles on Forem by Nadeem Rashid (@nadeemrashid__).</description>
    <link>https://forem.com/nadeemrashid__</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%2F1818560%2Faf7ebfbd-398b-47f6-8f8f-784b6728b3dd.png</url>
      <title>Forem: Nadeem Rashid</title>
      <link>https://forem.com/nadeemrashid__</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nadeemrashid__"/>
    <language>en</language>
    <item>
      <title>Git: The Tool Every Developer Needs to Know</title>
      <dc:creator>Nadeem Rashid</dc:creator>
      <pubDate>Thu, 20 Mar 2025 05:10:06 +0000</pubDate>
      <link>https://forem.com/nadeemrashid__/git-the-tool-every-developer-needs-to-know-bnh</link>
      <guid>https://forem.com/nadeemrashid__/git-the-tool-every-developer-needs-to-know-bnh</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In software development, keeping track of code changes and managing different versions of a project is crucial. &lt;strong&gt;Git&lt;/strong&gt; is a powerful tool that helps developers:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save progress and revisit previous changes.
&lt;/li&gt;
&lt;li&gt;Collaborate efficiently without overwriting each other’s work.
&lt;/li&gt;
&lt;li&gt;Manage different versions of a project easily.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With Git, multiple contributors can work on the same project simultaneously. Additionally, platforms like &lt;strong&gt;GitHub&lt;/strong&gt; allow developers to store their projects online, making remote collaboration seamless.  &lt;/p&gt;

&lt;p&gt;This guide covers &lt;strong&gt;Git fundamentals, essential commands, and how to use Git with remote repositories&lt;/strong&gt;. By the end, you will have a solid foundation for managing code effectively. &lt;/p&gt;

&lt;h2&gt;
  
  
  Things We Will Learn in This Blog
&lt;/h2&gt;

&lt;p&gt;In this blog, we will dive into the key concepts and commands of Git to help you manage your code and collaborate with others. Here’s what you’ll learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What Git is and why it’s important&lt;/strong&gt; for version control and collaboration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to check if Git is installed&lt;/strong&gt; and how to install it if needed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to configure Git&lt;/strong&gt; with your name and email to track commits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key Git terms&lt;/strong&gt; such as repositories, commits, branches, merges, and remotes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Git workflow&lt;/strong&gt; and how changes flow through different stages (working directory, staging area, and local repository).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Basic Git commands&lt;/strong&gt; for initializing repositories, staging, committing, and pushing changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to work with remote repositories&lt;/strong&gt; (e.g., GitHub) for collaboration and managing versions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to undo changes&lt;/strong&gt; and fix mistakes using Git’s powerful commands.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to work with branches&lt;/strong&gt; to create new features or fixes without affecting the main project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By the end of this blog, you'll have a comprehensive understanding of Git and how to use it to manage your projects effectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Git and Why Use It?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Git&lt;/strong&gt; is a &lt;strong&gt;distributed version control system (DVCS)&lt;/strong&gt; that helps developers manage code efficiently. It allows you to &lt;strong&gt;track changes, collaborate with others, and maintain different versions&lt;/strong&gt; of a project without losing progress.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Key Benefits of Git:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Track Changes&lt;/strong&gt; – Keep a complete history of modifications.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaboration&lt;/strong&gt; – Work smoothly with multiple developers.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Branching &amp;amp; Merging&lt;/strong&gt; – Experiment with new features without affecting the main project.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backup &amp;amp; Recovery&lt;/strong&gt; – Revert to previous versions if needed.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Industry Standard&lt;/strong&gt; – Used by companies like &lt;strong&gt;Google, Microsoft&lt;/strong&gt;, and major open-source projects.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using Git, teams can work together efficiently while keeping their code organized and secure.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Checking if Git is Installed
&lt;/h2&gt;

&lt;p&gt;Before using Git, check if it's already installed on your system. Open a terminal or command prompt and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If Git is installed, it will display something like below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git version 2.45.0.windows.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the command does not work, Git is not installed on your system&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Git
&lt;/h2&gt;

&lt;p&gt;You can download and install Git from the official website:&lt;br&gt;
&lt;a href="https://git-scm.com/downloads" rel="noopener noreferrer"&gt;Download Git&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Configuring Git
&lt;/h2&gt;

&lt;p&gt;After installing Git, you need to set up your &lt;strong&gt;username&lt;/strong&gt; and &lt;strong&gt;email&lt;/strong&gt;. This information is used to track your commits and associate them with you.  &lt;/p&gt;
&lt;h3&gt;
  
  
  Set Your Name and Email
&lt;/h3&gt;

&lt;p&gt;Run the following commands in your terminal or command prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Verifying Your Git Configuration
&lt;/h3&gt;

&lt;p&gt;To check if your details were saved correctly, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will display a list of all configured settings. You should see your name and email in the output, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user.name=Your Name  
user.email=your.email@example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Basic Git Terms
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Repository (Repo)&lt;/strong&gt; – A folder where Git is initialized to track changes in a project.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Commit&lt;/strong&gt; – A saved version of your project at a specific point in time.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remote Repository&lt;/strong&gt; – A version of your repository stored online (e.g., GitHub, GitLab).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Staging Area&lt;/strong&gt; – An intermediate area where changes are gathered before they are committed to the repository. It allows you to prepare and review changes before finalizing them in a commit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Branch&lt;/strong&gt; – A separate line of development that allows you to work on changes without affecting the main project. Useful for adding new features or fixing bugs.
&lt;/li&gt;
&lt;/ul&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%2Fh9pgtd415h015cjztcd8.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%2Fh9pgtd415h015cjztcd8.png" alt="Braching" width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Merge&lt;/strong&gt; – Combining changes from two different branches into one. For example, adding new features from a feature branch to the main project branch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clone&lt;/strong&gt; – Copying a repository from a remote source to your local machine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pull&lt;/strong&gt; – Getting the latest changes from a remote repository to update your local copy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Push&lt;/strong&gt; – Sending your local changes to a remote repository to share with others.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Understanding Git Workflow
&lt;/h2&gt;

&lt;p&gt;Git follows a &lt;strong&gt;three-stage process&lt;/strong&gt; to track and manage code changes efficiently. This workflow ensures that every change is &lt;strong&gt;tracked, reviewed, and stored safely&lt;/strong&gt; before being shared.  &lt;/p&gt;

&lt;p&gt;The main stages of Git workflow are:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Working Directory&lt;/strong&gt; – The folder where your project exists and where you modify files.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Staging Area&lt;/strong&gt; - A temporary space where changes are prepared before committing. This allows you to review modifications before permanently saving them in the local repository.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local Repository&lt;/strong&gt; – A hidden &lt;code&gt;.git&lt;/code&gt; directory on your computer where committed versions are stored.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remote Repository&lt;/strong&gt; – A version of your repository hosted on platforms like &lt;strong&gt;GitHub&lt;/strong&gt; or &lt;strong&gt;GitLab&lt;/strong&gt;, used for collaboration.
&lt;/li&gt;
&lt;/ul&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%2Fx6hbwq2g4z7tu6u08hqw.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%2Fx6hbwq2g4z7tu6u08hqw.png" alt="Git Workflow" width="800" height="668"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Basic Git Workflow
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Initialize a repository&lt;/strong&gt;: &lt;code&gt;git init&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Clone an existing repository&lt;/strong&gt;: &lt;code&gt;git clone &amp;lt;repo-url&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Stage changes&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git add &amp;lt;file-name&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git add .&lt;/code&gt; (to add all files)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Commit changes&lt;/strong&gt;: &lt;code&gt;git commit -m "Your message"&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Push changes to remote&lt;/strong&gt;: &lt;code&gt;git push origin &amp;lt;branch-name&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pull the latest changes&lt;/strong&gt;: &lt;code&gt;git pull origin &amp;lt;branch-name&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Essential Git Commands
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. Setup &amp;amp; Initialization
&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;Action&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Command&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Configure Git&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;git config --global user.name "Your Name"&lt;/code&gt;&lt;br&gt;&lt;code&gt;git config --global user.email "your@email.com"&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Set up Git with your name and email.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Initialize a repo&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git init&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Create a new local repository.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Link repo to GitHub&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git remote add origin &amp;lt;repo-url&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Connect local repo to GitHub.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  2. Tracking &amp;amp; Committing Changes
&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;Action&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Command&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Check status&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git status&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;See modified/untracked files.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Stage all changes&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Add all modified files to staging.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Stage a specific file&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git add &amp;lt;filename&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Add a specific file.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Commit changes&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git commit -m "Your message"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Save changes locally.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  3. Pushing Code to GitHub
&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;Action&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Command&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Push to GitHub&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git push -u origin main&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Upload commits to GitHub.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Push to a different branch&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git push origin &amp;lt;branch-name&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Push changes to a specific branch.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  4. Pulling &amp;amp; Updating Code
&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;Action&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Command&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Fetch latest changes&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git pull origin main&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Update local repo from GitHub.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Clone a repository&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git clone &amp;lt;repo-url&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Download a copy of an existing GitHub repo.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  5. Undo &amp;amp; Fix Mistakes
&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;Action&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Command&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Undo last commit (keep changes)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git reset --soft HEAD~1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Remove the last commit but keep changes.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Revert to last committed state&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git checkout -- &amp;lt;filename&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Undo changes in a specific file.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Reset all uncommitted changes&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git reset --hard&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Remove all local changes. ⚠ Be careful!&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  6. Branching &amp;amp; Merging
&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;Action&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Command&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Create a new branch&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git branch &amp;lt;branch-name&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Create a new branch.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Switch branches&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git checkout &amp;lt;branch-name&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Move to another branch.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Create &amp;amp; switch to a new branch&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git checkout -b &amp;lt;branch-name&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Create and switch to a new branch.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Merge branches&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;git merge &amp;lt;branch-name&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Merge a branch into the current branch.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Git is an essential tool for every developer, enabling efficient version control and seamless collaboration. By mastering its core concepts and commands, you can streamline your workflow, keep your projects organized, and ensure smooth collaboration.&lt;/p&gt;

&lt;p&gt;This blog covered Git fundamentals—from installation to essential commands for tracking, committing, and pushing changes. We also explored working with remote repositories, managing branches, and fixing mistakes. With these skills, you’re ready to manage your codebase and collaborate effectively.&lt;/p&gt;

&lt;p&gt;Start using Git today to level up your development process!&lt;/p&gt;

</description>
      <category>git</category>
      <category>beginners</category>
      <category>learning</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How Operating Systems Manage Processes</title>
      <dc:creator>Nadeem Rashid</dc:creator>
      <pubDate>Mon, 17 Mar 2025 10:49:09 +0000</pubDate>
      <link>https://forem.com/nadeemrashid__/how-operating-systems-manage-processes-3ig0</link>
      <guid>https://forem.com/nadeemrashid__/how-operating-systems-manage-processes-3ig0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Our computer is like a battlefield where multiple programs are constantly&lt;br&gt;
fighting for CPU time. Without a proper management system, everything would slow down, freeze, or even crash. Whether you're browsing the web, running apps, or handling background tasks, something needs to decide which process gets priority and how system resources are shared.&lt;br&gt;
This is where the Operating System (OS) comes in—it acts as the ultimate manager, ensuring that every process gets a fair share of CPU time, avoiding conflicts, and keeping the system running smoothly.&lt;br&gt;
But what exactly is a process? Simply put, &lt;strong&gt;a process is a running instance of a program.&lt;/strong&gt; Each process has its own memory, registers, and execution state, allowing multiple processes to run simultaneously without interfering with each other.&lt;/p&gt;
&lt;h2&gt;
  
  
  What You’ll Learn in This Blog:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What a process is and its lifecycle&lt;/li&gt;
&lt;li&gt;How the OS tracks processes using the Process Control Block (PCB)&lt;/li&gt;
&lt;li&gt;How process scheduling ensures efficiency&lt;/li&gt;
&lt;li&gt;The role of context switching in multitasking&lt;/li&gt;
&lt;li&gt;How processes are created, managed, and terminated&lt;/li&gt;
&lt;li&gt;Real-world examples of process management&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  1. What a process is and its lifecycle
&lt;/h2&gt;

&lt;p&gt;A process is an instance of a program in execution. While a program is&lt;br&gt;
just a set of stored instructions (such as a &lt;code&gt;.exe&lt;/code&gt; file or a script), it becomes a process when it is loaded into main memory and starts running. So, a process is simply a running program—using CPU time, memory, and system resources to execute its tasks.&lt;br&gt;&lt;br&gt;
However, processes are not limited to just the apps you open. Your Operating System (OS) itself runs multiple background processes to keep your system functional. Some common types of processes include:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;System processes&lt;/strong&gt; – Managing memory, hardware, and security.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Background services&lt;/strong&gt; – Updating software, syncing files, and running scheduled tasks.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Driver processes&lt;/strong&gt; – Handling devices like keyboards, printers, and network adapters.
Because many processes run at the same time, the OS needs to manage them efficiently to ensure smooth performance and prevent one process from using all the resources.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Understanding the Process Lifecycle:
&lt;/h2&gt;

&lt;p&gt;A process doesn’t simply move from start to finish in a straight path. Instead, it moves through different states based on what it’s doing and what resources it needs. The OS keeps track of these states and transitions to manage CPU time efficiently and ensure fair resource allocation.&lt;br&gt;
Here’s a breakdown of the different process states:&lt;br&gt;
&lt;strong&gt;1. New (Created):&lt;/strong&gt; A process starts in the New state when it is created. At this stage, the OS assigns the necessary memory and resources before it can run.&lt;br&gt;
&lt;strong&gt;2. Ready:&lt;/strong&gt; Once a process is ready to execute, it moves into the Ready state, waiting for the CPU to schedule it. Multiple processes in the ready state form a queue, where the OS decides which one runs next.&lt;br&gt;
&lt;strong&gt;3. Running:&lt;/strong&gt; A process moves to the Running state when it is assigned CPU time and actively executes its instructions. The CPU switches between processes rapidly to maintain multitasking.&lt;br&gt;
&lt;strong&gt;4. Waiting (Blocked):&lt;/strong&gt; A process enters the Waiting state if it needs to wait for something, like user input, disk access, or network data. It remains in this state until the required resource is available.&lt;br&gt;
&lt;strong&gt;5. Terminated (Exit):&lt;/strong&gt; A process reaches the Terminated state when it completes execution or encounters an error. The OS then frees up its resources and removes it from the system.&lt;br&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%2Fwsoe3l6fmlr2nhlqvlv0.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%2Fwsoe3l6fmlr2nhlqvlv0.png" alt="Process LifeCycle" width="675" height="281"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  2. How the OS Tracks Processes Using the Process Control Block
&lt;/h2&gt;

&lt;p&gt;When multiple processes are running, the OS must efficiently track and manage them. This is done using a &lt;strong&gt;Process Control Block (PCB)&lt;/strong&gt;, a data structure that stores essential details about each process.&lt;br&gt;&lt;br&gt;
The PCB helps the OS keep track of a process's state, resources, and execution history, ensuring smooth multitasking and process switching.  &lt;/p&gt;
&lt;h3&gt;
  
  
  Key Components of the Process Control Block
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Process ID (PID):&lt;/strong&gt;
A unique number assigned to each process for identification.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Process State:&lt;/strong&gt;
Indicates whether the process is in the &lt;strong&gt;New&lt;/strong&gt;, &lt;strong&gt;Ready&lt;/strong&gt;, &lt;strong&gt;Running&lt;/strong&gt;, &lt;strong&gt;Waiting&lt;/strong&gt;, or &lt;strong&gt;Terminated&lt;/strong&gt; state.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Program Counter (PC):&lt;/strong&gt;
Stores the memory address of the next instruction to be executed.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CPU Registers:&lt;/strong&gt;
Hold temporary data, execution-related information, and process-specific variables.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory Information:&lt;/strong&gt;
Contains details about the memory allocated to the process, including the address space.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I/O Information:&lt;/strong&gt;
Tracks the input/output devices and files the process is interacting with.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Priority:&lt;/strong&gt;
Determines the scheduling priority of the process, deciding how soon it gets CPU time.
The OS updates the PCB dynamically as a process moves through different states. This allows seamless switching between processes and efficient resource allocation.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Transition to Process Scheduling
&lt;/h3&gt;

&lt;p&gt;Tracking processes is just the first step—next, the OS must decide which process should run and when. That’s where Process Scheduling comes into play. Let’s dive in!&lt;br&gt;
Since multiple processes compete for execution, the OS must schedule them efficiently to maintain system performance and responsiveness. This is where &lt;strong&gt;process scheduling&lt;/strong&gt; plays a crucial role.&lt;/p&gt;
&lt;h3&gt;
  
  
  Illustration of a Process Control Block
&lt;/h3&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%2Fypkosh7amkebxxk0vap1.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%2Fypkosh7amkebxxk0vap1.png" alt="Process Control Block" width="367" height="366"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  3. How Process Scheduling Ensures Efficiency
&lt;/h2&gt;

&lt;p&gt;Now that we understand how the OS tracks processes using the Process Control Block (PCB), the next challenge is determining which process gets CPU time and when. Since multiple processes compete for execution, the OS must schedule them efficiently to maintain system performance and responsiveness.&lt;br&gt;
To achieve this, the OS follows three levels of scheduling:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Long-Term Scheduling:&lt;/strong&gt; Decides which processes are admitted into the system for execution, helping manage the overall system workload.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Short-Term Scheduling:&lt;/strong&gt; Determines which process runs next, using scheduling algorithms like First-Come-First-Serve (FCFS), Round Robin, and Priority Scheduling to optimize performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Medium-Term Scheduling:&lt;/strong&gt; Temporarily suspends (or swaps out) processes to free up memory and improve efficiency, particularly in virtual memory systems.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  4. Context Switching: The Backbone of Multitasking
&lt;/h2&gt;

&lt;p&gt;Context switching is how the OS quickly switches between processes, keeping multitasking smooth. But every switch comes with a cost—since the CPU spends time saving and loading process states instead of executing tasks.&lt;br&gt;
&lt;strong&gt;How Context Switching Works:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Interrupt or System Call: A running process (P₀) gets interrupted (e.g., time slice ends, higher-priority process needs CPU).&lt;/li&gt;
&lt;li&gt;Save Current Process State: The OS stores P₀'s execution details (program counter, registers, etc.) in its Process Control Block (PCB₀).&lt;/li&gt;
&lt;li&gt;Load the Next Process: The OS retrieves P₁’s saved state from PCB₁ and restores its execution context.&lt;/li&gt;
&lt;li&gt;Resume Execution: P₁ starts running while P₀ stays idle.&lt;/li&gt;
&lt;li&gt;Repeat: When it’s time to switch back, the OS repeats the process, saving P₁’s state and restoring P₀’s.
&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%2F6weoy5xehelr2p11bn03.png" alt="Context Switching" width="647" height="570"&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  5.Process Creation &amp;amp; Termination
&lt;/h2&gt;

&lt;p&gt;Every process in an operating system starts somewhere. But how exactly are processes created? And once they complete their tasks, how does the OS handle their termination?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Process Creation: How New Processes Start&lt;/strong&gt;
A new process is typically created when a user runs a program or when an existing process spawns a child process. This parent-child relationship allows complex applications to break tasks into multiple subprocesses, improving efficiency.
In UNIX-based operating systems, processes are created using the &lt;strong&gt;fork()&lt;/strong&gt; system call. This function duplicates the calling (parent) process, creating a new (child) process with an identical memory space.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example: Process Creation Using fork() in C:&lt;/strong&gt;
Given below is the simple example which shows how a process creates a child process using fork() in C:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;    
#include &amp;lt;unistd.h&amp;gt;   // Provides access to the fork() system call
int main() {
    // Creating a child process using fork()
    int pid = fork(); 
    // fork() returns:
    // &amp;gt; 0  → to the parent process (the returned value is the child's PID)
    // == 0 → to the child process
    // &amp;lt; 0  → if fork() fails (error case)
    if (pid &amp;gt; 0) {
        // This block runs in the **parent process**
        printf("Parent Process: PID = %d, Child PID = %d\n", getpid(), pid);
    } 
    else if (pid == 0) {
        // This block runs in the **child process**
        printf("Child Process: PID = %d, Parent PID = %d\n", getpid(), getppid());
    } 
    else {
        // If fork() fails, an error message is displayed
        printf("Fork failed! Unable to create a new process.\n");
    }
    sleep(30);  // Keep the process running for 30 seconds
    return 0; // Exit the program successfully
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2F124ukdlwubibk9mamnpl.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%2F124ukdlwubibk9mamnpl.png" alt="fork" width="778" height="135"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Process Termination: How Processes End&lt;/strong&gt;
A process can terminate in various ways:

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Normal termination:&lt;/strong&gt; When the process completes execution and exits gracefully.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Abnormal termination:&lt;/strong&gt; If an error occurs, causing the process to stop unexpectedly.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Killed by another process:&lt;/strong&gt; A process can be forcefully stopped using the &lt;code&gt;kill&lt;/code&gt; command in UNIX/Linux.
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example: Killing a Process in Linux&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Find the process ID (PID) using:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ps aux | grep process_name
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Kill the process using:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kill -9 PID
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  6 Real-World Use Cases &amp;amp; Examples
&lt;/h2&gt;

&lt;p&gt;Process management isn't just a theoretical concept—it plays a crucial role in real-world applications. Let’s explore two well-known examples:&lt;br&gt;
**1. Google Chrome: Multi-Process Architecture&lt;br&gt;
Have you ever noticed that when one Chrome tab crashes, the whole browser doesn’t? That’s because it follows a multi-process model, where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each tab runs as a separate process → A crash in one tab doesn’t affect others.&lt;/li&gt;
&lt;li&gt;Plugins and extensions have their own processes → Improves security and isolation.&lt;/li&gt;
&lt;li&gt;Processes 
run in a sandbox → Prevents malware from spreading to the OS.
We can observe this by opening Chrome’s built-in Task Manager:
Open Google Chrome.
Press Shift + Esc (Windows) or go to Menu &amp;gt; More Tools &amp;gt; Task Manager.
You can see each tab, extension, and service listed as a separate process.
Here's an example of what it looks like:
&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%2Fvjuqysg76cr9td4ai90b.png" alt="chrome multi tab" width="800" height="821"&gt;
In the above image, we can see multiple processes running, such as:&lt;/li&gt;
&lt;li&gt;Browser process (Main UI)&lt;/li&gt;
&lt;li&gt;GPU process (Handles graphical rendering)&lt;/li&gt;
&lt;li&gt;Network service (Manages internet connections)&lt;/li&gt;
&lt;li&gt;Tabs running as separate processes (e.g., Diffchecker tab)&lt;/li&gt;
&lt;li&gt;Multiple subframe processes (for ads, embedded content, etc.)
&lt;strong&gt;2. Linux: Managing System Processes with systemd
Linux follows a hierarchical process management model, where system processes are initialized by **systemd&lt;/strong&gt; or &lt;strong&gt;init&lt;/strong&gt;. These processes handle everything from launching system services to managing user applications.
&lt;strong&gt;Key Linux System Processes:&lt;/strong&gt;
&lt;strong&gt;systemd&lt;/strong&gt; - The first process started at boot, managing all other processes.
&lt;strong&gt;cron&lt;/strong&gt; - Handles scheduled tasks (e.g., backups, script execution).
&lt;strong&gt;sshd&lt;/strong&gt; - Manages remote SSH connections.
&lt;strong&gt;Xorg&lt;/strong&gt; - Provides graphical display services.
To view top 10 running processes in Linux, run the below command:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ps aux | head -10 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2F8g5cj4k3935jbb5xf5kw.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%2F8g5cj4k3935jbb5xf5kw.png" alt="running processes in linux" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
For a real-time view, run the below command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;top  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fl71ipjanxrkotpn9sdv6.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%2Fl71ipjanxrkotpn9sdv6.png" alt="Real Time View of Running Processes" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7 Conclusion
&lt;/h2&gt;

&lt;p&gt;Behind every smooth computing experience lies the &lt;strong&gt;OS’s powerful process management system&lt;/strong&gt;—silently juggling multiple programs, allocating resources, and ensuring everything runs without chaos. Without it, even the most advanced systems would struggle to keep up.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Key Takeaways:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Every &lt;strong&gt;process follows a lifecycle&lt;/strong&gt;, transitioning through different states.
&lt;/li&gt;
&lt;li&gt;The OS tracks each process using a &lt;strong&gt;Process Control Block (PCB)&lt;/strong&gt; to store vital execution details.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CPU scheduling&lt;/strong&gt; ensures fair resource distribution, optimizing performance.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Context switching&lt;/strong&gt; keeps multitasking smooth by rapidly switching between active processes.
&lt;/li&gt;
&lt;li&gt;Processes are &lt;strong&gt;created and terminated dynamically&lt;/strong&gt;, adapting to system needs.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real-world applications&lt;/strong&gt; like Chrome’s multi-process model and Linux’s system management highlight its importance.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Final Thought
&lt;/h3&gt;

&lt;p&gt;Next time you open multiple applications, &lt;strong&gt;pause for a moment&lt;/strong&gt;—how does your OS decide which one gets CPU time first? The answer lies in &lt;strong&gt;CPU Scheduling&lt;/strong&gt;, a key concept we’ll explore in the next blog!&lt;br&gt;&lt;br&gt;
What’s your biggest question about OS process management? &lt;strong&gt;Drop a comment below&lt;/strong&gt;, and let’s discuss! 🚀  &lt;/p&gt;

</description>
      <category>operatingsystem</category>
      <category>beginners</category>
      <category>processces</category>
      <category>linux</category>
    </item>
    <item>
      <title>Bit Manipulation In Problem Solving</title>
      <dc:creator>Nadeem Rashid</dc:creator>
      <pubDate>Wed, 25 Dec 2024 10:46:29 +0000</pubDate>
      <link>https://forem.com/nadeemrashid__/bit-manipulation-in-problem-solving-4k2g</link>
      <guid>https://forem.com/nadeemrashid__/bit-manipulation-in-problem-solving-4k2g</guid>
      <description>&lt;p&gt;In programming, efficiency is crucial, and bit manipulation is one of the most powerful techniques for achieving it. At the core of every computer, data is represented as binary sequences of 0's and 1's — bits. Directly manipulating these bits allows you to optimize performance, save memory, and simplify algorithms, often achieving faster and more space-efficient solutions than traditional methods. Bit manipulation is especially useful in competitive programming, embedded systems, and scenarios where performance is a priority. In this blog, we’ll explore the essential bit manipulation operations and demonstrate how to apply them in problem-solving, helping you sharpen your coding skills and tackle challenges more effectively.&lt;/p&gt;

&lt;h1&gt;
  
  
  Basic Bit Manipulation Operations
&lt;/h1&gt;

&lt;p&gt;1.&lt;strong&gt;AND (&amp;amp;):&lt;/strong&gt;&lt;br&gt;
Compares two bits and returns 1 if both are 1, otherwise it returns 0.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;X&lt;/th&gt;
&lt;th&gt;Y&lt;/th&gt;
&lt;th&gt;X &amp;amp; Y&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 Example:
 a = 10001
 b = 11111
 a &amp;amp; b = 10001

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;2.&lt;strong&gt;OR (|):&lt;/strong&gt; &lt;br&gt;
Compares two bits and returns 1 if atleast one of the bits is 1 , otherwise it produces 0.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;X&lt;/th&gt;
&lt;th&gt;Y&lt;/th&gt;
&lt;th&gt;X | Y&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Example:
 a = 10001
 b = 11111
 a | b = 11111
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;3.&lt;strong&gt;NOT (~):&lt;/strong&gt;&lt;br&gt;
It changes 1 to 0 and vice versa.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;X&lt;/th&gt;
&lt;th&gt;~X&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:  
a = 10001  
~a = 01110

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;4.&lt;strong&gt;Left Shift (&amp;lt;&amp;lt;):&lt;/strong&gt;&lt;br&gt;
Left shift moves bits to the left, filling the rightmost positions with zeros. This is equivalent to multiplying by 2 for each shift.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:  
a = 5 (in binary: 101)  
a &amp;lt;&amp;lt; 2 = 10100 (which equals 20, i.e., 5 * 2 * 2 = 20)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5.&lt;strong&gt;Right Shift (&amp;gt;&amp;gt;):&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Right shift moves bits to the right, which is equivalent to division by 2 for each shift.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:  
a = 5 (in binary: 101)  
a &amp;gt;&amp;gt; 2 = 1 (which equals 1, i.e., 5 / 2 / 2 = 1)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6.&lt;strong&gt;XOR (^):&lt;/strong&gt;&lt;br&gt;
XOR compares the bits and returns 1 if the bits are different, and 0 if the bits are the same. XOR is often called the "odd 1 detector."&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;X&lt;/th&gt;
&lt;th&gt;Y&lt;/th&gt;
&lt;th&gt;X ^ Y&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Now that we've covered the basics of bit manipulation, let's apply these operations to solve some common problems. Below are some examples and their solutions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Check If a Number Is Odd or Even&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Description&lt;/strong&gt;:&lt;br&gt;
To determine if a number is odd or even, we use a bitwise AND operation with 1. If the least significant bit (LSB) is 1, the number is odd; if it is 0, the number is even.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach:&lt;/strong&gt;&lt;br&gt;
   Perform num &amp;amp; 1.&lt;br&gt;
     If the result is 0, the number is even.&lt;br&gt;
     If the result is 1, the number is odd.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;num = int(input("Enter a number: "))
if num &amp;amp; 1:
    print("Odd")
else:
    print("Even")


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Count the Number of 1's in a Binary Representation of a Number&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Description&lt;/strong&gt;:&lt;br&gt;
This approach repeatedly checks the LSB of the number using the bitwise AND operation with 1. Each time a 1 is found, we increment the count. The number is right-shifted in every iteration until all bits are processed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach:&lt;/strong&gt;&lt;br&gt;
   Keep shifting the number right while checking the LSB.&lt;br&gt;
Count the number of times the LSB is 1&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def countOnes(num):
    count = 0
    while num:
        count += (num &amp;amp; 1)
        num &amp;gt;&amp;gt;= 1
    return count

num = int(input("Enter a number: "))
print(f"Number of 1s: {countOnes(num)}")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Check If a Number Is a Power of 2&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Description:&lt;/strong&gt;&lt;br&gt;
A number is a power of two if it has exactly one bit set in its binary representation. Using the condition num &amp;amp; (num - 1), we can clear the rightmost set bit and check if the result is 0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach:&lt;/strong&gt;&lt;br&gt;
Perform num &amp;amp; (num - 1).&lt;br&gt;
If the result is 0 and the number is greater than 0, the number is a power of 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def isPowerOfTwo(num):
    return num &amp;gt; 0 and (num &amp;amp; (num - 1)) == 0

num = int(input("Enter a number: "))
if isPowerOfTwo(num):
    print("Power of 2")
else:
    print("Not a power of 2")

print(f"Number of 1s: {countOnes(num)}")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Change the Bit of a Number at a Particular Position&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Description:&lt;/strong&gt;&lt;br&gt;
To modify a bit at a specific position in a number, we use bitwise OR to set the bit to 1 and bitwise AND with a complemented mask to set the bit to 0. This allows precise control over the binary representation of the number.&lt;br&gt;
&lt;strong&gt;Approach:&lt;/strong&gt;&lt;br&gt;
Use the bitwise OR operation to set a bit to 1.&lt;br&gt;
Use the bitwise AND operation with the complement to set a bit to 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
def changeBit(num, pos, bit):
    if bit == 1:
        num |= (1 &amp;lt;&amp;lt; pos)  # Set bit to 1
    else:
        num &amp;amp;= ~(1 &amp;lt;&amp;lt; pos)  # Set bit to 0
    return num

num = int(input("Enter a number: "))
pos = int(input("Enter position of bit to change: "))
bit = int(input("Enter the bit value (0 or 1): "))
num = changeBit(num, pos, bit)
print(f"Updated number: {num}")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Find the Single Number in an Array&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Description:&lt;/strong&gt;&lt;br&gt;
When every element in an array appears exactly twice except for one, XOR operation can help identify the unique element. XOR cancels out duplicate values, leaving only the single number.&lt;br&gt;
&lt;strong&gt;Approach:&lt;/strong&gt;&lt;br&gt;
Use XOR to cancel out duplicate elements. Since 𝑎⊕𝑎=0, &lt;br&gt;
and 𝑎⊕0=𝑎, XORing all elements will leave only the unique number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
def findSingleNumber(arr):
    result = 0
    for num in arr:
        result ^= num
    return result

size = int(input("Enter the size of the array: "))
arr = [int(input(f"Enter element {i + 1}: ")) for i in range(size)]
print(f"Single number: {findSingleNumber(arr)}")


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Check Whether Two Numbers Have Opposite Signs&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Description:&lt;/strong&gt;&lt;br&gt;
The XOR operation can determine if two numbers have opposite signs by checking the sign bit. If the result of XOR is negative, the numbers have opposite signs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach:&lt;/strong&gt;&lt;br&gt;
Use XOR: if the result is negative, the numbers have opposite signs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def haveOppositeSigns(a, b):
    return (a ^ b) &amp;lt; 0

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if haveOppositeSigns(a, b):
    print("Opposite signs")
else:
    print("Same sign")


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Swap Two Numbers Without Using a Temporary Variable&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Description:&lt;/strong&gt;&lt;br&gt;
Swapping two numbers without using extra memory can be achieved using the XOR operation. It allows the values to be exchanged in-place through three XOR operations.&lt;br&gt;
&lt;strong&gt;Approach:&lt;/strong&gt;&lt;br&gt;
Use XOR to swap two numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def swap(a, b):
    a ^= b
    b ^= a
    a ^= b
    return a, b

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
a, b = swap(a, b)
print(f"Swapped: a = {a}, b = {b}")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8. Reverse the Bits of a Number&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Description:&lt;/strong&gt;&lt;br&gt;
Reversing the bits of a number involves iteratively shifting the bits to construct the reversed number while extracting bits from the original number.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach:&lt;/strong&gt;&lt;br&gt;
Use bitwise shifts and OR to reverse the bits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def reverseBits(num):
    reversed = 0
    while num:
        reversed = (reversed &amp;lt;&amp;lt; 1) | (num &amp;amp; 1)
        num &amp;gt;&amp;gt;= 1
    return reversed

num = int(input("Enter a number: "))
print(f"Reversed bits: {reverseBits(num)}")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Bit manipulation is a powerful technique that allows you to solve problems efficiently by working directly with binary representations of numbers. Mastering these fundamental operations can significantly improve your problem-solving skills, especially when working with time and memory constraints.&lt;/p&gt;

&lt;p&gt;For more examples and detailed code snippets, feel free to explore the repository where these problems and solutions are implemented: &lt;a href="https://github.com/NadeemRashid2000/Bit_Manipulation" rel="noopener noreferrer"&gt;BitManipulation_Github&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>nextjs</title>
      <dc:creator>Nadeem Rashid</dc:creator>
      <pubDate>Wed, 25 Dec 2024 09:09:42 +0000</pubDate>
      <link>https://forem.com/nadeemrashid__/nextjs-341n</link>
      <guid>https://forem.com/nadeemrashid__/nextjs-341n</guid>
      <description></description>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
