Skip to content

A collection of OS-level projects and lab exercises performed during my Operating System Sessional.

Notifications You must be signed in to change notification settings

Tanvir-Mahamood/Operating-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  Operating System Design

Welcome to my Operating System Design repository, a comprehensive collection of OS-level projects and lab exercises performed during my university sessional. The contents are based on the widely respected textbooks:

  • Operating System Design The XINU Approach This repository is organized into modules that correspond to various chapters and labs of the course. From process management to interprocess communication, and Linux shell scripting to XINU emulation, it is a hands-on journey through OS concepts with real C and shell code.

๐Ÿ“ Repository Structure

โœ… Chapter2_XINU_Codes

C source files derived from Chapter 2 Concurrent Execution and Operating System services of the XINU book. These demonstrate:

  • Console message printing
  • Process creation and scheduling
  • Multiple processs executing same piece of codes
  • Semaphore-based synchronization
  • Producer-consumer problem using semaphores

โœ… lab02: Linux Process Management

C code examples for basic Linux process control:

  • Retrieving PID and PPID (current process id and parent process id)
  • Exploring memory addresses of different variable types
  • Passing command line arguments
  • Process creation using fork()
  • Race conditions after fork()
  • Child termination with EXIT_SUCCESS, EXIT_FAILURE, and custom exit codes

โœ… lab03: Interprocess Communication (IPC)

This directory contains:

  • Message passing between processes using pipe()
  • Parent-child communication
  • Demonstrates high-level IPC with process synchronization

โœ… Shell_Programming & Shell_Programming2

A collection of beginner to intermediate shell scripts covering:

  • Input/output, variables, arrays, strings
  • Arithmetic operations, conditionals, loops
  • Logical operations, file & directory creation
  • Random number generation
  • Argument passing, redirection

โœ… projects: Shell Scripting Projects

Mini shell-based tools:

  • ๐Ÿ“Ÿ Digital Clock
  • ๐Ÿ’พ RAM Status Viewer
  • ๐Ÿ’ฝ Disk Usage Monitor

๐Ÿ’ป Software Setup and Environment (For Windows Users)

To run these OS-level programs and XINU, follow one of these installation environments:

  1. ๐Ÿ› ๏ธ Using WSL (Windows Subsystem for Linux)
    WSL is fast, easy to use, and integrates well with your existing Windows setup. Itโ€™s suitable for learning and practicing shell scripting without the overhead of virtualization. If you use Windows, WSL lets you run Linux natively without a VM. Install lightweight distributions like Ubuntu from the Microsoft Store. WSL 2 is highly efficient and integrates well with Windows.

โœ… Install WSL and Ubuntu:

Open PowerShell as Administrator Run the following command:

wsl --install
  • Restart your computer after installation
  • Open the Microsoft Store and search for Ubuntu
  • Click Install, then launch Ubuntu from the Start Menu

โœ… Update and install essential tools:

sudo apt update && sudo apt upgrade -y
sudo apt install build-essential gcc g++ make gdb

Now you can compile and run the C and shell files directly inside WSL.

โ–ถ๏ธYouTube: You can Folow this Install Ubuntu on Windows 11(WSL)

๐Ÿ› ๏ธ Some issues that should be handled: WSL instance is configured to log in directly as the root user. This bypasses the usual setup process that asks for a Unix username and password during the first launch. Here's how you can fix it:

  • Check the Default User: By default, the root user is set in the WSL instance. To change this:

    • Open PowerShell or Command Prompt.
    • Run the following command to check which WSL distributions are installed:
     wsl -l -v
    • Identify your Ubuntu distribution name (e.g., Ubuntu-22.04).
  • Create a New Non-Root User: If you donโ€™t have a regular user set up, you can create one manually:

    • In the WSL terminal (where it shows root@Username:~#), run:
    adduser your_username

    Replace your_username with your preferred username. Follow the prompts to set a password and additional information (you can leave them blank).

    • Add the user to the sudo group:
    usermod -aG sudo your_username
  • Set the Default User: Set your new user as the default user for WSL:

    • In PowerShell or Command Prompt, run:
    wsl --set-default-user your_username

    Now, when you open Ubuntu, it will prompt you to log in as the new user instead of the root user.

  • Restart WSL: To ensure the changes take effect, restart WSL by running:

wsl --shutdown

Open Ubuntu again, and you should see your new user instead of root.

๐Ÿ› ๏ธ To set or reset a password for a user in WSL (including the root user), follow these steps:

  • Log In as Root: If you're already logged in as root in WSL (root@username:~#), you can set the password for any user.

  • Set the Password: Use the passwd command to set or reset the password for any user, including root: For the root user:

    passwd

    You will be prompted to enter a new password and confirm it.

    For another user (e.g., your_username):

    passwd your_username

    Replace your_username with the actual username. Again, you'll be prompted to enter and confirm the new password.

  • Verify the Change Once you've set the password, you can test it by logging in as that user:

    Switch to the user:

    su - your_username
    • Enter the password when prompted.

๐Ÿ’ก Some Shell Commands:

# Check the Ubuntu version:
lsb_release -a

# Check kernel version:
uname -r

# Disk usage:
df -h

# Memory usage:
free -h

# List files and directories
ls -l

# Create a new file:
touch testfile.txt

# Create a directory:
mkdir testdir

# Move into the directory:
cd testdir

# Delete the directory:
rmdir ../testdir

# Check IP address:
ifconfig

Note

Install net-tools if ifconfig is not available:

sudo apt update && sudo apt install net-tools
# Ping a website:
ping -c 4 google.com

# Update package lists:
sudo apt update


# Upgrade installed packages:
sudo apt upgrade

# Install a sample package (e.g., nano, a text editor):
sudo apt install nano

# Open nano:
nano testfile.txt

# View running processes:
ps aux


# Monitor system performance:
top

# Install a text editor like vim or nano for shell scripting:
sudo apt install vim

# Check if gcc is installed for C programming:
gcc --version

# (Install it if needed):
sudo apt install build-essential

  1. ๐Ÿ› ๏ธ Dual Boot on Windows:
    Dual boot" or "dual booting" refers to the practice of installing and running multiple operating systems (OS) on a single computer, often Windows and Linux. This allows you to choose which OS to boot into each time you start your computer. Instead of splitting resources between operating systems, they are kept separate, and each OS needs its own partition and bootloader entry โ–ถ๏ธYouTube: You can follow this: How to Dual Boot Windows 11 and Ubuntu

  2. ๐Ÿ› ๏ธ Install Ubuntu Linux on Windows via the Microsoft Store:
    Find the distribution you prefer on the Microsoft Store and then click Get. Ubuntu will then be installed on your machine. Once installed, you can either launch the application directly from the Microsoft Store or search for Ubuntu in your Windows search bar.
    โ–ถ๏ธYouTube: You can follow How to Install Ubuntu Linux on Windows via the Microsoft Store

  3. ๐Ÿ› ๏ธ Using VirtualBox with Ubuntu (Recommended for XINU Emulation):
    VirtualBox, developed by Oracle, is a free and open-source virtualization software that allows you to run multiple operating systems simultaneously on a single computer. In the context of running Linux on Windows, VirtualBox enables you to install and run a Linux operating system as a virtual machine (VM) within your Windows environment. This means you can have a separate, isolated Linux system running alongside your Windows host operating system.
    โ–ถ๏ธYouTube: You can follow How to download and install Ubuntu 22.04 LTS in Virtualbox windows 10 with Full screen tutorial


**โ–ถ๏ธYouTube:** You can follow [How To Install Ubuntu Linux in VirtualBox 2025 (Hindi) Step by Step](https://youtu.be/9EAPGgkLVV8?si=lFfIrRpN0dPqqvoS)

โœ… Step-by-step Installation:

  • Download and install VirtualBox

  • Download Ubuntu ISO (20.04 or 22.04 LTS)

  • Create a new Virtual Machine in VirtualBox:

    • Type: Linux
    • Version: Ubuntu (64-bit)
    • Memory: at least 2 GB
    • Disk: at least 20 GB (dynamically allocated)
  • Install Ubuntu from the ISO file by booting the VM.

โœ… Install development tools inside Ubuntu:

sudo apt update
sudo apt install gcc g++ make gdb git qemu

Tip

By installng any of these, you will be able to run shell scripts and c code dor linux process management.

Important

You may need to use shared folder. It allow you to easily access files and folders on your host operating system (Windows or Linux) from within your guest operating system (Windows or Linux) without needing a network connection. This provides a simple way to transfer and share data between the host and guest machines.


**โ–ถ๏ธYouTube:** You can follow [Creating Shared folder in Virtualbox for Windows and Ubuntu](https://youtu.be/TtTtpPL0L8I?si=oyMFDwQOE3-ods4f)



In order emulate XINU on Ubuntu, we have to download and install XINU on our LINUX system. I am using Virtual Box.

๐Ÿงช Running and Emulating XINU:

This section assumes you're inside the Ubuntu system (either WSL or VirtualBox).

  • Install X Server (Optional. Only needed for GUI.)
    Xinu doesnโ€™t strictly require an X server unless your course involves graphical user interfaces (GUI). If GUI functionality is needed, youโ€™ll need an X server to forward the graphical output.
    Download and install X Server
    Start the X server application.

  • Install QEMU

    sudo apt update
    sudo apt upgrade
    sudo apt install qemu-system qemu-utils
    sudo apt install flex bison gawk qemu-system-x86 xorriso grub-common
    grub-pc-bin
  • Build XINU OS

    git clone https://github.com/zrafa/xinu-x86-gui
  • Navigate to the Makefile using file explorer.

    • For WSL. Linux > Ubuntu > home > username >xinu-x86-gui > compile
    • For Ubuntu home > username >xinu-x86-gui > compile

    Inside Makefile, find run-qemu and add this to the end of the command -nographic
    It will look like:

    add the code here
  • (run once for every time you boot WSL/Ubuntu)

    sudo chmod 666 /dev/kvm

๐Ÿ› ๏ธ Troubleshooting

  1. If /dev/kvm is not found on your system, it usually means that KVM (Kernel-based Virtual Machine) is not available or not set up on your Ubuntu environment. Here's how you can diagnose and fix this:

    • Step 1: Check If Your CPU Supports Virtualization

      egrep -c '(vmx|svm)' /proc/cpuinfo

      If the output is 0, your CPU does not support virtualization, or it is not enabled in your BIOS/UEFI. If the output is 1 or more, your CPU supports virtualization.
      If virtualization is supported but not enabled:

      • Reboot your system.
      • Enter your BIOS/UEFI settings.
      • Look for an option like Intel VT-x, AMD-V, or Virtualization Technology, and enable it.
    • Step 2: Install KVM and Related Packages

      sudo apt update 
      sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils
      ls -l /dev/kvm
  2. system is missing the flex tool and possibly some configuration files or dependencies required by the Makefile. Here's how to fix these issues: Install it using the following command:

    sudo apt update
    sudo apt install flex
    sudo apt install bison libfl-dev build-essential
  3. You might encounter grub related errors while running make run-qemu.

    • Step 1: Install xorriso Run the following command to install xorriso:
      sudo apt update
      sudo apt install xorriso
      sudo apt install grub-pc-bin grub-common

**After the installations without touble, you are mpletely ready to test and run Shell Script, Linux Process management c code and XINU Processmanagement code.

โš™๏ธ How to Run a Shell Script in Linux

  • Navigate to the Script's Directory

    cd /path
  • Create a new shell file

    touch filename.sh
  • To use vim as editor:

     vim filename.sh

    i + enter : to enter inset mode
    esc to exit insert mode
    :wq to save and quit
    :q to quit without saving

    To use nano as editor: (I have used it)

    nano filename.sh

    Ctrl + o to save
    Ctrl + x to exit (You will be prompted if file is not saved)

  • Write Shell Script

    #!/bin/bash
    echo "Hello World"

    Press Ctrl + o and Ctrl + x

  • Provide permission to execute file

    chmod +x filename.sh
  • Execute the shell file:

    ./filename.sh

There are a lot of Shell Programming tutorial available on internet. I have followed: Master SHELL SCRIPTING in ONE VIDEO

โš™๏ธ How to run C Code for Linux Process Management

  • Create and Write C Code: You may use File Explorer or Linux Terminal (same as shell file creation). say, filename.c

  • Compile it:

    gcc filename.c -o filename

    It will create object(.o) file.

  • Run it:

    ./filename

โš™๏ธ How to run C Code for XINU Process Management

In Xinu, everything you run (like a "program") is actually a process that is compiled and built into the Xinu image. Once the system boots, these processes (often written as C functions) can be run as commands from the Xinu shell.
Running a C program in Xinu is done by defining a function, registering it as a shell command, and invoking it from the shell after the OS boots.

๐Ÿ”› How to emulate XINU OX on LINUX: Run:

make clean
make
# if XINU is ready, then
make run-qemu

๐Ÿ“ด How to Shut Down XINU

top # To see running processes. Get PID of QEMU. Say, QEMU_id

Press q to exit top

Then kill the QEMU

kill QEMU_id

โš™๏ธ Running code in XINU

  • Create a c file, xsh_hello.c, in xinu-x86-gui > shell

  • Open and write code inside it

    #include <xinu.h>
    #include <stdio.h>
    
    shellcmd xsh_hello(int nargs, char *args[]) {
      printf("Hello World);
      return 0;
    }
  • Open cmdtab.c from same directory (xinu-x86-gui > shell) Add new entry

    {'hello', FALSE, xsh_hello.c},

    [!NOTE] FALSE, because hello is not a built in command

  • Open shprototypes.h header file from xinu-x86-gui > include and Add prototype of our function:

    extern shellcmd xsh_hello(int32, char *[])
  • Open process.h header file from xinu-x86-gui > include Change NPROC from 8 to 20\

  • Build and run the the OS from xinu-x86-gui > compile directory

    cd xinu-x86-gui/compile 
    make clean 
    make 
    make run-qemu 
  • In xinu shell, type command hello and press enter

๐Ÿ’ป Author Tanvir Mahamood 3rd Year CSE, RUET LinkedIn | GitHub
Feel free to reach out via email: deltatanvir2002@gmail.com

About

A collection of OS-level projects and lab exercises performed during my Operating System Sessional.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published