0% found this document useful (0 votes)
19 views68 pages

Of Operating System Practical

The document outlines the installation processes for various operating systems including Windows, Linux, and macOS, detailing the steps and prerequisites for each. It also discusses virtualization, explaining what a virtual machine is, its types, and how to install virtual machine software like VirtualBox on both Windows and Linux. Overall, it serves as a comprehensive guide for installing operating systems and understanding virtualization concepts.

Uploaded by

satjeet2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views68 pages

Of Operating System Practical

The document outlines the installation processes for various operating systems including Windows, Linux, and macOS, detailing the steps and prerequisites for each. It also discusses virtualization, explaining what a virtual machine is, its types, and how to install virtual machine software like VirtualBox on both Windows and Linux. Overall, it serves as a comprehensive guide for installing operating systems and understanding virtualization concepts.

Uploaded by

satjeet2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

Experiment - 1

Aim- Installation process of various Operating Systems.

❖​What is an Operating System?

An Operating System (OS) is software that acts as an interface between computer hardware
components and the user. Every computer must have at least one operating system to run other
programs. Applications such as Browsers, MS Office, Notepad Games, and others need an
environment to run and perform their tasks. Examples of operating systems include Windows, macOS,
Linux, and Android​

❖​Different ways to install an Operating System.

1.​ Bare Metal Installation: This means installing the OS directly on physical hardware. It requires a
bootable USB/DVD or PXE (network installation). It is common for personal computers, servers, and
workstations. Example: Installing Windows, Linux, or macOS on a laptop/desktop.

2.​ Virtual Machine (VM) Installation: In this, the OS is installed inside a virtualized environment
using software like VMware, VirtualBox, or Hyper-V.

3.​ Dual Boot Installation: In this Two or more OSes are installed on a single system. The user selects
the OS at startup (a bootloader like GRUB manages selection).

4.​ Live OS (Persistent or Non-Persistent): In this OS runs from a USB/DVD without installation on
the hard drive. It is mainly used for testing or recovery purposes.
5.​ Embedded OS Installation: Used in IoT devices, routers, or specialized hardware. The OS is flashed
onto a chip or a memory card. Example: Installing Raspberry Pi OS on a microSD card.

Windows
Windows is an operating system (OS) developed by Microsoft. It provides a graphical user interface (GUI),
making it easy for users to interact with their computers using a mouse, keyboard, and touchscreen. Windows
is one of the most widely used OSes in the world, especially for personal computers (PCs), laptops, and
servers.

❖​How to install Windows?​

●​ Prerequisites:
○​ Windows Installation Media: A USB flash drive (at least 8GB) or DVD with a Windows
ISO.
○​ Product Key: A valid Windows product key (unless you plan to enter it later or use digital
licensing).

●​ Steps:
1.​ Create/Obtain Installation Media
a.​ Download the official Windows ISO from Microsoft’s website or use the Media Creation Tool
(for Windows 10/11) remember to know your system configurations.
b.​ If using a USB then run the Media Creation Tool and follow the prompts to create bootable
media, or use third-party software like Rufus to create a bootable USB from the ISO.
c.​ Insert a USB drive with at least 8GB of storage into your computer and open Rufus.

d.​ Select "USB flash drive" select the ISO file for Windows.
e.​ Choose the USB drive you inserted earlier and click "Next." The tool will now download the
Windows files and create a bootable USB drive. This process may take some time, depending
on your internet speed and the performance of your computer.

2.​ Prepare the Computer:


a.​ Insert the bootable USB drive into the computer where you want to install Windows.
b.​ Restart the computer and enter the BIOS or UEFI settings.
c.​ This usually involves pressing a specific key (such as F2, F10, or DEL) during startup. Refer to
your computer's documentation or search online for instructions specific to your device.
d.​ Locate the boot order settings and move the USB drive to the top of the list.
e.​ Save your settings and exit the BIOS or UEFI. The computer should now boot from the USB
drive.

3.​ Boot from Installation Media:


a.​ After reboot, you should see a prompt that says, “Press any key to boot from USB/DVD…”.
Press a key to start the installer.

4.​ Initial
a.​ Select your language, time and currency format, and keyboard/input method.
b.​ Click Install Now.

5.​ Enter Product Key

a.​ You can either enter your valid product key now or skip and enter it after installation
(depending on your version of Windows and licensing).

6.​ Answer to next prompts


a.​ Read and accept the Microsoft Software License Terms.
b.​ Custom (Advanced) if doing a clean install.
c.​ You will see a list of drives/partitions.
d.​ Delete, format, or create partitions as needed. If you want a completely clean install, delete all
partitions on the target drive and let Windows setup create the required partitions automatically.
e.​ Windows will copy files and install. Your system may restart several times.
f.​ Choose a username, password, privacy settings, and sign in with your Microsoft account if
desired (Windows 10/11).

👍
g.​ Wait for final setup steps.
h.​ “Installation Done ”

7.​ Post Installation


a.​ Install device drivers (Windows often does this automatically, but check your manufacturer’s
website for the latest drivers).
b.​ Run Windows Update to ensure the system is fully patched.
c.​ Restore your files from backup if needed.

LINUX

Linux is a free, open-source operating system (OS) based on Unix. It was originally created by Linus
Torvalds in 1991 and has since become one of the most widely used operating systems in the world. Unlike
Windows or macOS, Linux is open-source, meaning anyone can modify, distribute, and use it freely.

❖​Types of Linux Installation

Linux can be installed in many ways but some popular ways that our industry uses are:
●​ Single Boot
●​ Dual Boot
●​ Virtual Box

❖​How to install Linux ​

●​ Prerequisites​
○​ Linux ISO: Obtain a distribution of your choice (e.g., Ubuntu, Fedora, Linux Mint, etc.).
○​ Bootable USB/DVD: Use a tool like Rufus (Windows) or Etcher (macOS, Linux) to create a
bootable USB from the ISO.​

●​ Steps
1.​ Create Bootable Media:
a.​ Download the ISO of your chosen Linux distribution.
b.​ It depends on you which type/version of Linux you want like Ubuntu, Debian, Kali,
Arc, Mint etc.
c.​ Use Rufus or another tool to create a bootable USB drive.

2.​ Boot from USB:


a.​ Restart your computer and enter the BIOS/UEFI settings (usually by pressing F2, F12,
or Del during startup). It’s different with every machine out there, see more methods
here
b.​ Change the boot order to prioritize the USB drive or DVD drive. You need to make sure
you’re not having any other USBs or DVDs mounted.
c.​ Save the changes and exit the BIOS/UEFI settings.

3.​ Disabling Secureboot and Fastboot (Only for Newer Machines)


a.​ To ensure successful installation of Ubuntu, it is important to disable BitLocker and
secure boot from your bootable drive. It should be noted that in most modern machines,
there is only one drive for booting and storing data, and disabling secure boot without
disabling BitLocker may automatically trigger security measures that prevent the
installation of Ubuntu.
4.​ Installing Linux (Ubuntu):
a.​ Boot from the USB/DVD you created. You’ll see the Linux distribution’s installer.
b.​ When you boot into Linux for the first time, you’ll typically be greeted with an initial
setup wizard.
c.​ This wizard will guide you through various configuration options.

5.​ Start Installation:


a.​ Double-click the “Install” icon on the desktop or select “Install” from the welcome
menu (depending on distro).​

6.​ Language and Keyboard:


a.​ Choose your language and keyboard layout.
7.​ Installation Type (Partitioning)(for Dual Boot):
a.​ Erase disk and install Linux: This will remove all existing data on the selected drive
and create default partitions for Linux.

b.​ Something else (manual partitioning): If you want custom partitions (e.g., separate
/home partition), choose this option and set up partitions manually (/, swap, /home,
etc.).
8.​ User Account Setup:
a.​ Enter your username, password, and computer name.​

9.​ Begin Installation:


a.​ The installer copies files to your drive. This might take several minutes.​

10.​Restart:
a.​ When prompted, restart the computer. Remove the USB drive when prompted.
b.​ And Ubuntu.

11.​Post-Installation:
a.​ Log in with the username/password you created.​
b.​ Update the system (e.g., sudo apt update && sudo apt upgrade in Ubuntu/Debian-based
distros).
MACOS
macOS is an operating system (OS) developed by Apple for its Mac computers. It provides a smooth,
user-friendly experience with a sleek design and powerful performance. macOS is known for its stability,
security, and deep integration with Apple’s ecosystem (iPhones, iPads, Apple Watch, etc.).

❖​ How to install macOs?

macOS is licensed only for Apple hardware. If you have a Mac and want to do a fresh installation or
reinstall macOS, follow these steps. So we cant install macOs on any machine but if you want to
experience macOs on normal PC you can install Linux and customize and for more details you can
install Hackintosh (for non-Apple Hardware)

●​ Prerequisites
○​ Apple machine

●​ Steps to setup macOs or reinstall it

1.​ Setting up new Mac


a.​ Press the power button to turn on your Mac for the first time.
b.​ Once your Mac boots up, choose your preferred language from the list.
c.​ Select your region (country), which helps configure date, time, and keyboard settings
automatically.
d.​ You’ll see an Accessibility screen offering features like VoiceOver, Zoom, or other
assistive options if needed.
e.​ Your Mac will scan for available Wi-Fi networks.
f.​ A screen will appear about Data & Privacy, explaining how Apple handles personal
information
g.​ If you want to transfer data from another Mac, PC, or a Time Machine backup, choose
the appropriate option (e.g., “From a Mac, Time Machine backup, or startup disk”).
h.​ Follow the on-screen prompts to start transferring data
i.​ Enter your Apple ID email address and password.
j.​ If you have two-factor authentication, enter the 6-digit code sent to your trusted
devices.
k.​ Agree to the Terms and Conditions to proceed.
l.​ After signing in with your Apple ID, your Mac will sync with iCloud services like
iCloud Drive, Photos, and more.
m.​ If your Mac has a Touch ID sensor (like many MacBook models), you can set it up now
by placing your finger on the sensor repeatedly as instructed.

2.​ Reinstalling macOS


a.​ Reinstalling macOS (especially if you plan to erase the drive) can result in data loss if
you don’t back up first.
b.​ Use Time Machine with an external hard drive,
c.​ The process to enter macOS Recovery differs slightly depending on the type of Mac
i.​ For Apple Silicon Macs:
1.​ Shut down your Mac (if it’s on).
2.​ Press and hold the power button (Touch ID button) until you see
“Loading startup options.”
3.​ Select Options and click Continue.
4.​ If prompted, enter your administrator password or the password for
the disk.
ii.​ For Intel-based Macs
1.​ Shut down your Mac.
2.​ Press the power button, then immediately press and hold Command
(⌘) + R.
3.​ Hold these keys until you see the Apple logo or a spinning globe.
4.​ Release the keys, and if prompted, enter your administrator password
or the password for the disk.
d.​ If you want a clean slate (e.g., selling or giving away your Mac, or if you’re
encountering serious software issues).
e.​ If you merely want to reinstall macOS while keeping your data, you can skip erasing
the disk.
f.​ In the macOS Utilities (or Recovery Assistant) window, select Reinstall macOS (or
Reinstall macOS Ventura/Monterey, etc. depending on your version).
g.​ Click Continue and follow the prompts.
h.​ Agree to the software license terms when asked.
i.​ Select the disk you wish to install macOS on (the one you just erased, or your existing
drive if you chose not to erase).
j.​ Click Install (or Continue). The installer will begin downloading (if needed) and
installing macOS.
k.​ The Mac may restart several times during the installation.
l.​ Do not close the lid (if it’s a laptop) or power off your Mac during the process.
m.​ The progress bar may pause or move slowly; this is normal.
n.​ Choose Language & Region.
o.​ Connect to Wi-Fi if needed.
p.​ Sign in with your Apple ID (or create one if you don’t have it).
q.​ Customize settings like Siri, Location Services, Analytics, etc.
r.​ Suppose you have a Time Machine or other backup. In that case, you can use
Migration Assistant during Setup Assistant or later from the Applications > Utilities
folder to restore your files, apps, and settings.
Experiment - 2

Aim- Virtualization, Installation of virtual machine software and installation of


Operating System on a virtual machine.

❖​What is Virtualization?
➢​ Virtual Machine abstracts the hardware of our personal computer such as CPU, disk drives,
memory, NIC (Network Interface Card), etc, into many different execution environments as per
our requirements.. For example, VirtualBox.
➢​ When we run different processes on an operating system, it creates an illusion that each process
is running on a different processor having its own virtual memory, with the help of CPU
scheduling and virtual-memory techniques.
➢​ There are additional features of a process that cannot be provided by the hardware alone like
system calls and a file system. The virtual machine approach does not provide these additional
functionalities but it only provides an interface that is the same as basic hardware.

❖​Virtual Machine
Virtualization is the method of creating a software-based, or “virtual” version of a computer with good
amounts of CPU, memory, and storage that are “borrowed” from a physical host computer (such as
your personal computer) and/or a remote server. The working of the virtual machine is very simple just
check the published article on the Working of a Virtual Machine.

❖​Types of Virtual Machine


1.​ Process Virtual Machine
2.​ System Virtual Machine

❖​How to install Virtual Machine


1.​ Windows

a.​ Download the VirtualBox Installer:


i.​ Go to the official VirtualBox Downloads page.
ii.​ Under “VirtualBox x.x.x platform packages,” click “Windows hosts” to
download the .exe installer.​

b.​ Run the Installer


i.​ Locate the downloaded VirtualBox-x.x.x-Win.exe file and double-click it.
ii.​ If you see a User Account Control prompt, click Yes to allow installation.​

c.​ Choose Setup Options


i.​ In the setup wizard, click Next to begin.
ii.​ You can typically keep the default features selected (VirtualBox Application,
USB support, Networking, etc.).
iii.​ Click Next to continue.​

d.​ Network Interface Warning


i.​ You may see a message that your network will be temporarily disconnected
during installation. This is normal because VirtualBox installs network drivers
for virtual machines.
ii.​ Click Yes to proceed.​

e.​ Begin Installation


i.​ Click Install to start the installation process.
ii.​ If prompted again by User Account Control, click Yes to allow the installation.
iii.​ Wait for the progress bar to reach 100%.
2.​ Linux
a.​ Update Package Lists
i.​ sudo apt update
b.​ Install VirtualBox
i.​ You can usually install the version available in your distro’s repositories:
1.​ sudo apt install virtualbox
ii.​ This installs the main VirtualBox package. However, it may not always be the
latest version.​

c.​ For Offical by Oracle​



i.​ `wget -qO - https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo
apt-key add -`
ii.​ `wget -qO - https://www.virtualbox.org/download/oracle_vbox.asc | sudo
apt-key add -`

iii.​ `echo "deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian


$(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list`
iv.​ `sudo apt update`
v.​ `sudo apt install virtualbox@latest`​

d.​ Install Required Kernel Modules


i.​ VirtualBox requires kernel modules (e.g., vboxdrv). Usually, this is handled
automatically by DKMS if installed.​
`sudo apt install dkms`
ii.​ If kernel modules fail to build or load, reboot your system or run:
`sudo /sbin/vboxconfig`
iii.​ After a successful build, you should see the vboxdrv module loaded.​

e.​ Check Installation


i.​ Launch VirtualBox via your app menu or by typing virtualbox in a ​
terminal. If it opens without errors, you’re good to go.​



3.​ Mac Os
a.​ Download VirtualBox
i.​ Open your web browser and go to the official VirtualBox download page.
ii.​ Look for the section labelled "VirtualBox platform packages."
iii.​ Click the OS X hosts (macOS) download link to get the .dmg installer.​

b.​ Open the Installer


i.​ Locate the downloaded file (typically in your Downloads folder), named
something like VirtualBox-<version>-OSX.dmg.
ii.​ Double-click the .dmg file to mount it.
iii.​ In the mounted image, you’ll see a VirtualBox.pkg file (an installer package).

c.​ Run the Installer


i.​ Double-click the VirtualBox.pkg file to launch the installer.
ii.​ If prompted with message about the file being downloaded click Open.
iii.​ Follow the on-screen instructions. You may see the standard macOS prompts
iv.​ You can click Continue to proceed with the default installation settings.
v.​ Destination: Choose your main hard drive (usually the default location).
vi.​ Click Install to begin the installation process.

d.​ Complete the Installation


i.​ Once you allow the kernel extension (kext) or system software, the VirtualBox
installation should complete.
ii.​ You’ll see a message indicating the installation was successful.

❖​Installing OS in Virtual box (same for all OS)​

1.​ Prepare Your Installation Media


a.​ You can now install any operating system in any virtual machine like in Mac, Linux or
Windows.
b.​ Obtain the OS installer or ISO file
i.​ For example, if you’re installing Windows, download the Windows ISO from
Microsoft.
ii.​ For Linux, download the ISO from the distro’s official website
c.​ Verify the ISO file (optional but recommended).
i.​ Some OS providers offer checksums (like MD5, SHA256). Verifying ensures
your file isn’t corrupted.​

2.​ Open VirtualBox and Create a New Virtual Machine


a.​ Launch VirtualBox from your Applications (macOS), Start Menu (Windows), or
application launcher (Linux).
b.​ Click the “New” button (usually at the top-left corner in the VirtualBox Manager).
c.​ Name and Operating System
i.​ Enter a Name (e.g., “Windows 10” or “Ubuntu 22.04” or Hackintosh).
ii.​ Under Type, select the OS type (Microsoft Windows, Linux, etc.).
iii.​ Under Version, choose the specific version (e.g., “Windows 10 (64-bit)” or
“Ubuntu (64-bit)”).​

d.​ Memory Size (RAM)


i.​ Allocate the recommended RAM size. Typically, VirtualBox suggests a
minimum.
ii.​ For Windows 10, 4 GB (4096 MB) is often a comfortable starting point. For
Linux, 2 GB (2048 MB) is usually enough for light usage.

e.​ SDD
i.​ Select “Create a virtual solid state drivenow” if you don’t already have a virtual
disk.
ii.​ Click “Create.”​

f.​ SSD Disk File Type


i.​ Choose VDI (VirtualBox Disk Image) (the default) or any other format you
prefer.
ii.​ Click “Next.”
g.​ Storage on Physical Hard Disk
i.​ Usually, “Dynamically allocated” is recommended.
1.​ It grows in size as needed, up to the maximum you set.
h.​ File Location and Size
i.​ Choose where to store the virtual disk and set the maximum size (e.g., 20 GB,

40 GB, etc.).​

i.​ Configure the Virtual Machine Settings (Optional but Recommended)


i.​ Select the newly created VM in the VirtualBox Manager.
ii.​ Click “Settings.”
iii.​ System → Processor: Adjust the number of CPU cores if you want more
performance.
iv.​ Display: Increase Video Memory if needed (e.g., 64 MB or 128 MB for modern
OS).
v.​ Storage: Under the Storage tab, click the empty CD icon (under Controller: IDE
or Controller: SATA) and then click the small disk icon on the right to choose a
virtual optical disk file.
vi.​ Select the OS ISO you downloaded.

j.​ Start the Virtual Machine and Install the OS


i.​ Click “Start” in VirtualBox Manager with your new VM selected.
ii.​ The VM will boot from the ISO file (like booting from a DVD in a real PC).
iii.​ Follow the OS’s on-screen installation prompts. This will vary depending on the
OS:
1.​ Windows: Choose language, accept the license, select “Custom
Installation,” pick the virtual drive, etc.
2.​ Linux: You may get a “Live” environment; choose “Install,” follow the
distro’s installer steps.
iv.​ If prompted to format or partition the virtual drive, choose the
recommended/automatic options unless you have specific partitioning needs.
v.​ Reboot the virtual machine when prompted.
vi.​ If the ISO is still inserted, you might need to remove it from the virtual drive or
press a key to skip booting from the ISO again.

You’re Ready to Use Your Virtual Machine!
Experiment - 3
Aim- Overview of single user systems, network operating system and multiuser
system.

What is an Operating System (OS)?


An Operating System (OS) is system software that manages computer hardware and software resources and
provides common services for computer programs. It acts as an intermediary between the hardware and
software, ensuring that resources such as CPU, memory, storage, and peripherals are used efficiently.

The main functions of an OS include:

1.​ Process Management: Scheduling and managing processes, ensuring smooth execution.

2.​ Memory Management: Allocating and deallocating memory as needed by different programs.

3.​ File System Management: Organizing and managing data storage and access to files.

4.​ Security and Access Control: Protecting the system and its data from unauthorized access.

5.​ User Interface: Providing an interface (command-line or graphical) for users to interact with the
system.

6.​ Device Management: Managing input/output devices such as printers, keyboards, and mice.

The OS is essential for the operation of any computing system, whether it’s a personal computer, a server, or
an embedded system.
Single-User Systems

What is a Single-User System?

A Single-User System is a type of computer system designed to be used by one user at a time. It is a
standalone system where the user has exclusive access to the system’s resources such as CPU, memory, and
storage. These systems are typically used in personal computing environments and are simple to use.

Characteristics:

●​ Single User Access: Only one user can interact with the system at a time.​

●​ Personal Use: These systems are mainly designed for personal tasks like word processing, browsing
the web, playing games, and other individual uses.​

●​ Simple Configuration: They are easy to set up and use, with minimal technical expertise required.​

●​ Local Resources: The system uses local resources, and there is no resource sharing with other
systems.

Components:

1.​ Hardware: Typically consists of personal computers, laptops, tablets, or smartphones.

2.​ Operating System: Includes systems like Windows, macOS, and Linux (in some cases), optimized
for single-user use.

3.​ User Interface: Typically has a Graphical User Interface (GUI) for ease of interaction. Common
examples include Windows and macOS.

4.​ Task Management: Allows the user to run multiple applications in sequence or concurrently, though
only one user has access at any given time.​

How it Works:

●​ The system allocates all the resources (like CPU time and memory) to the single user.
●​ Users can run multiple applications concurrently through multitasking, but it’s not a multi-user
environment.

●​ The file system allows the user to store and manage files locally without concerns of other users’
interference.

Examples:

●​ Personal Computers (PCs) and Laptops used by individuals for home or office work.

●​ Smartphones and Tablets used by individuals for communication and entertainment.​

Network Operating Systems (NOS)

What is a Network Operating System (NOS)?

A Network Operating System (NOS) is a specialized operating system designed to manage and coordinate
multiple computers in a network. It enables resource sharing, communication, and centralized management
within the network. A NOS helps connect computers and devices, allowing them to work together efficiently
over local area networks (LAN) or even wide area networks (WAN).

Characteristics:

●​ Resource Sharing: A NOS allows multiple computers to share resources such as printers, databases,
and files over a network.

●​ Centralized Management: The NOS typically runs on a central server, and it manages network
resources, user access, and permissions.
●​ Security and Authentication: The NOS provides features like user authentication, file permissions,
and encryption to ensure secure access to resources.​

●​ Remote Access: Users can access shared resources remotely, often through virtual private networks
(VPNs) or other secure communication methods.

●​ Communication Services: The NOS offers tools for communication, such as email servers,
messaging services, and networked applications.

Components:

1.​ Server: The central system where resources are stored and managed.

2.​ Client: Other computers or devices that connect to the server to access shared resources.

3.​ Protocols: Network protocols such as TCP/IP, FTP, and SMB are used to manage communication
between systems.

4.​ Security Features: Includes tools for user authentication, authorization, and encryption.

How it Works:

●​ The server hosts resources like files and printers, while clients access these resources remotely.

●​ The NOS manages access control, ensuring that users only have access to the resources they are
authorized to use.

●​ File systems are shared over the network, allowing multiple users to interact with the same files
simultaneously.

Examples:

●​ Microsoft Windows Server: Widely used for network management and resource sharing.

●​ Linux-based servers: Common in businesses and institutions.

●​ Unix servers: Used in large enterprises, offering high stability and performance.​

Multiuser Systems in Detail

What is a Multiuser System?

A Multiuser System is an operating system designed to allow multiple users to access and use the system
resources simultaneously. These systems are built for environments where many users need to interact with a
central system, sharing its resources like CPU, memory, and storage. Multiuser systems are typically used in
large-scale enterprises, universities, and data centers.​

Characteristics:
●​ Simultaneous User Access: Multiple users can log in and interact with the system at the same time,
each with their own session.

●​ Resource Sharing: The system allocates shared resources (CPU, memory, disk space) efficiently
among all users.

●​ Process Scheduling: The OS uses sophisticated scheduling algorithms to ensure fair access to system
resources. It switches between users' tasks so fast that it appears as though they are being executed
concurrently.

●​ Isolation and Security: Each user’s data and processes are isolated from others, preventing
unauthorized access.

●​ Centralized Administration: Administrators manage system resources, security, and user access from
a central location.​

Components:

1.​ Multiple User Accounts: Each user has an individual account and home directory, with specific
permissions assigned to files and resources.

2.​ Operating System: The OS supports multi-user functionality, such as UNIX, Linux, or Windows
Server (with remote desktop services).

3.​ Scheduling Algorithms: The OS uses scheduling techniques like Round Robin, First Come, First
Served, or Priority Scheduling to allocate CPU time fairly to all users.

4.​ File System Management: The OS manages shared files, ensuring that multiple users can access them
without interfering with each other.

How it Works:
●​ The system’s resources (like CPU and memory) are divided into time slots for each user. The OS uses
time-sharing techniques to give users access to the system’s resources in rapid succession.

●​ Each user has their own user session, where they can run programs and store files without affecting
other users’ sessions.

●​ Security and access control ensure that users can only access their files or those explicitly shared
with them.

Examples:

●​ UNIX/Linux Systems: Used in universities, research labs, and businesses where many users need
access to a powerful central system.

●​ Mainframe Systems: Used by large enterprises for processing vast amounts of data and serving
multiple users simultaneously.

●​ Windows Server (with Remote Desktop Services): Allows multiple users to access separate virtual
desktops on the same server.
Experiment - 3
Aim- Write a program for the simulation of following CPU scheduling
algorithms to find turnaround time and waiting time.​
a) FCFS ​ ​ b) SJF ​ ​ ​ c) Round Robin ​ d) Priority

a)​ FCFS​

#include <iostream>
#include <vector>
using namespace std;
int noP, avgTAT = 0, avgWT = 0;
vector<int> Processes;
vector<int> BT;
vector<int> AT;
vector<int> WT;
vector<int> TAT;
void findWT()
{
WT[0] = 0;
for (int i = 1; i < noP; i++)
{
WT[i] = BT[i - 1] + WT[i - 1];
}
}
void findTAT()
{
for (int i = 0; i < noP; i++)
{
TAT[i] = BT[i] + WT[i];
}
}
void avgTime()
{
findWT();
findTAT();
cout << "Process\tBurst Time\tWaiting Time\tTurnaround Time\n";
for (int i = 0; i < noP; i++)
{
avgTAT = TAT[i] + avgTAT;
avgWT = WT[i] + avgWT;
cout << " " << i + 1 << "\t\t" << BT[i] << "\t "
<< WT[i] << "\t\t " << TAT[i] << endl;
}
cout << "Average waiting time = "
<< (float)avgWT / (float)noP;
cout << "\nAverage turn around time = "
<< (float)avgTAT / (float)noP;
}
int main()
{
cout << "Enter the no of processes -> ";

cin >> noP;


Processes.resize(noP);
BT.resize(noP);
WT.resize(noP);
TAT.resize(noP);
AT.resize(noP);

for (int i = 0; i < noP; i++)


{

cout << "Enter the Burst Time of " << i + 1 << " Process -> ";
cin >> BT[i];
cout << "Enter the Arrival Time of " << i + 1 << " Process -> ";
cin >> AT[i];
}
avgTime();
}
Output->
b)​SJF
#include <iostream>
#include <vector>
using namespace std;
int noP, avgTAT = 0, avgWT = 0;
vector<int> Processes;
vector<int> BT;
vector<int> AT;
vector<int> WT;
vector<int> TAT;
void findWT()
{
WT[0] = 0;
for (int i = 1; i < noP; i++)
{
WT[i] = BT[i - 1] + WT[i - 1];
}
}
void findTAT()
{
for (int i = 0; i < noP; i++)
{
TAT[i] = BT[i] + WT[i];
}
}
void avgTime()
{
findWT();
findTAT();
cout << "Process\tBurst Time\tWaiting Time\tTurnaround Time\n";
for (int i = 0; i < noP; i++)
{
avgTAT = TAT[i] + avgTAT;
avgWT = WT[i] + avgWT;
cout << " " << i + 1 << "\t\t" << BT[i] << "\t "
<< WT[i] << "\t\t " << TAT[i] << endl;
}
cout << "Average waiting time = "
<< (float)avgWT / (float)noP;
cout << "\nAverage turn around time = "
<< (float)avgTAT / (float)noP;
}
void sortAccordingToTheBurstTime()
{

for (int i = 0; i < noP; i++)


{
int minIndex = i;
for (int j = i + 1; j < noP; j++)
{
if (BT[j] < BT[minIndex] || (BT[j] == BT[minIndex] && AT[j] < AT[minIndex]))
{
minIndex = j;
}
}
swap(BT[i], BT[minIndex]);
swap(AT[i], AT[minIndex]);
swap(Processes[i], Processes[minIndex]);
}
avgTime();
}

int main()
{
cout << "Enter the no of processes -> ";​
cin >> noP;
Processes.resize(noP);
BT.resize(noP);
WT.resize(noP);
TAT.resize(noP);
AT.resize(noP);

for (int i = 0; i < noP; i++)


{

cout << "Enter the Burst Time of " << i + 1 << " Process -> ";
cin >> BT[i];
cout << "Enter the Arrival Time of " << i + 1 << " Process -> ";
cin >> AT[i];
}
sortAccordingToTheBurstTime();
}

Output->
c)​ Round Robin
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

struct Process
{
int id;
int burst_time; // Burst time (execution time)
int remaining_time; // Remaining burst time for the process
int arrival_time; // Arrival time
int completion_time; // Completion time
int waiting_time; // Waiting time
int turnaround_time; // Turnaround time
};

void calculateTurnaroundAndWaitingTime(vector<Process> &processes)


{
int total_wt = 0, total_tat = 0;
int n = processes.size();

for (int i = 0; i < n; i++)


{
processes[i].turnaround_time = processes[i].completion_time -
processes[i].arrival_time;
processes[i].waiting_time = processes[i].turnaround_time -
processes[i].burst_time;

total_wt += processes[i].waiting_time;
total_tat += processes[i].turnaround_time;
}

cout << "\nAverage Waiting Time: " << (float)total_wt / n;


cout << "\nAverage Turnaround Time: " << (float)total_tat / n;
}

void roundRobin(vector<Process> &processes, int quantum)


{
queue<int> readyQueue;
int n = processes.size();
int currentTime = 0;

// Initializing remaining burst time


for (int i = 0; i < n; i++)
{
processes[i].remaining_time = processes[i].burst_time;
}

vector<bool> inQueue(n, false); // To track processes in the queue


// Push the first process into the queue
readyQueue.push(0);
inQueue[0] = true;

vector<int> ganttChart; // Gantt chart to keep track of executed processes

while (!readyQueue.empty())
{
int idx = readyQueue.front();
readyQueue.pop();
inQueue[idx] = false; // Remove from the queue

// If the process can finish within the quantum


if (processes[idx].remaining_time <= quantum)
{
currentTime += processes[idx].remaining_time;
processes[idx].completion_time = currentTime;
processes[idx].remaining_time = 0;
ganttChart.push_back(processes[idx].id); // Add the process to the Gantt
chart
}
else
{
// Process runs for the full quantum and then goes back to the queue
currentTime += quantum;
processes[idx].remaining_time -= quantum;
ganttChart.push_back(processes[idx].id); // Add the process to the Gantt
chart

// Push back the process into the queue if it's not already there
if (!inQueue[idx])
{
readyQueue.push(idx);
inQueue[idx] = true;
}
}

// Push all the newly arrived processes to the queue


for (int i = 0; i < n; i++)
{
if (processes[i].arrival_time <= currentTime && processes[i].remaining_time
> 0 &&
!inQueue[i])
{
readyQueue.push(i);
inQueue[i] = true;
}
}
}

cout << "\nRound Robin Scheduling (Quantum = " << quantum << "):\n";
calculateTurnaroundAndWaitingTime(processes);

// Print Gantt Chart


cout << "\nGantt Chart: ";
for (int i = 0; i < ganttChart.size(); i++)
{
cout << "P" << ganttChart[i] << " ";
}
cout << endl;
}

int main()
{
int n;
cout << "Enter the number of processes: ";
cin >> n;

vector<Process> processes(n);

cout << "\nEnter Process details (ID, Arrival Time, Burst Time):\n";
for (int i = 0; i < n; i++)
{
processes[i].id = i + 1;
cout << "\nProcess " << i + 1 << ":\n";
cout << "Arrival Time: ";
cin >> processes[i].arrival_time;
cout << "Burst Time: ";
cin >> processes[i].burst_time;
}

int quantum;
cout << "\nEnter quantum for Round Robin Scheduling: ";
cin >> quantum;

roundRobin(processes, quantum);

return 0;
}
Output->​


​ d) Priority
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Process
{
int id;
int burst_time; // Burst time (execution time)
int remaining_time; // Remaining burst time for the process
int arrival_time; // Arrival time
int completion_time; // Completion time
int waiting_time; // Waiting time
int turnaround_time; // Turnaround time
int priority; // Priority of the process
};

void calculateTurnaroundAndWaitingTime(vector<Process> &processes)


{
int total_wt = 0, total_tat = 0;
int n = processes.size();

for (int i = 0; i < n; i++)


{
processes[i].turnaround_time = processes[i].completion_time -
processes[i].arrival_time;
processes[i].waiting_time = processes[i].turnaround_time -
processes[i].burst_time;

total_wt += processes[i].waiting_time;
total_tat += processes[i].turnaround_time;
}

cout << "\nAverage Waiting Time: " << (float)total_wt / n;


cout << "\nAverage Turnaround Time: " << (float)total_tat / n;
}

void priorityScheduling(vector<Process> &processes)


{
int n = processes.size();
int currentTime = 0;

// Sort the processes by arrival time and then by priority (lower value of priority
means higher priority)
sort(processes.begin(), processes.end(), [](Process &a, Process &b)
{
if (a.arrival_time == b.arrival_time)
return a.priority < b.priority;
return a.arrival_time < b.arrival_time; });

vector<int> ganttChart; // Gantt chart to keep track of executed


processes
vector<Process> completedProcesses; // To store completed processes for final
calculations

// Execute the processes based on priority scheduling


while (!processes.empty())
{
// Find the process with the highest priority (lowest priority value)
int idx = -1;
for (int i = 0; i < n; i++)
{
if (processes[i].arrival_time <= currentTime && processes[i].remaining_time
> 0)
{
if (idx == -1 || processes[i].priority < processes[idx].priority)
{
idx = i;
}
}
}

if (idx == -1)
{
currentTime++;
continue; // No process is ready to execute, increment time
}

// Execute the selected process


currentTime += processes[idx].burst_time;
processes[idx].completion_time = currentTime;
processes[idx].remaining_time = 0;
completedProcesses.push_back(processes[idx]); // Store completed process for
later calculation
ganttChart.push_back(processes[idx].id); // Add the process to the Gantt
chart

// Remove the process from the ready queue (no longer needed in the original
vector)
processes.erase(processes.begin() + idx);
}

cout << "\nPriority Scheduling:\n";


calculateTurnaroundAndWaitingTime(completedProcesses);

// Print Gantt Chart


cout << "\nGantt Chart: ";
for (int i = 0; i < ganttChart.size(); i++)
{
cout << "P" << ganttChart[i] << " ";
}
cout << endl;
}

int main()
{
int n;
cout << "Enter the number of processes: ";
cin >> n;

vector<Process> processes(n);

cout << "\nEnter Process details (ID, Arrival Time, Burst Time, Priority):\n";
for (int i = 0; i < n; i++)
{
processes[i].id = i + 1;
cout << "\nProcess " << i + 1 << ":\n";
cout << "Arrival Time: ";
cin >> processes[i].arrival_time;
cout << "Burst Time: ";
cin >> processes[i].burst_time;
cout << "Priority: ";
cin >> processes[i].priority;
processes[i].remaining_time = processes[i].burst_time;
}

priorityScheduling(processes);
return 0;
}​


Output->


Experiment - 5
Aim- Write a program for the simulation of producer-consumer problem
using semaphores.

#include <iostream>
#include <pthread.h>
#include <semaphore.h>
#include <vector>
#include <unistd.h>
#include <ctime>

using namespace std;

#define BUFFER_SIZE 5
#define MAX_ITEMS 20

vector<int> buffer(BUFFER_SIZE, 0);

sem_t emptySlots;
sem_t fullSlots;
sem_t mutex;

int produced_count = 0;
int consumed_count = 0;

int random_delay()
{
return rand() % 3 + 1;
}

void print_buffer()
{
cout << "Buffer: [";
for (int i = 0; i < BUFFER_SIZE; i++)
{
cout << buffer[i] << " ";
}
cout << "]" << endl;
}

void *producer(void *arg)


{
int item = 0;
while (produced_count < MAX_ITEMS)
{
item++;
sleep(random_delay());

sem_wait(&emptySlots);
sem_wait(&mutex);

for (int i = 0; i < BUFFER_SIZE; i++)


{
if (buffer[i] == 0)
{
buffer[i] = item;
produced_count++;
cout << "Producer produced item " << item << " at slot " << i << endl;
break;
}
}

sem_post(&mutex);
sem_post(&fullSlots);

print_buffer();
}
return nullptr;
}

void *consumer(void *arg)


{
while (consumed_count < MAX_ITEMS)
{
sem_wait(&fullSlots);
sem_wait(&mutex);

int item = -1;


for (int i = 0; i < BUFFER_SIZE; i++)
{
if (buffer[i] != 0)
{
item = buffer[i];
buffer[i] = 0;
consumed_count++;
cout << "Consumer consumed item " << item << " from slot " << i << endl;
break;
}
}

sem_post(&mutex);
sem_post(&emptySlots);

print_buffer();

sleep(random_delay());
}
return nullptr;
}

int main()
{
srand(time(0));

sem_init(&emptySlots, 0, BUFFER_SIZE);
sem_init(&fullSlots, 0, 0);
sem_init(&mutex, 0, 1);

pthread_t producer_thread, consumer_thread;

pthread_create(&producer_thread, nullptr, producer, nullptr);


pthread_create(&consumer_thread, nullptr, consumer, nullptr);

pthread_join(producer_thread, nullptr);
pthread_join(consumer_thread, nullptr);

sem_destroy(&emptySlots);
sem_destroy(&fullSlots);
sem_destroy(&mutex);

cout << "\nSimulation complete: " << endl;


cout << "Total items produced: " << produced_count << endl;
cout << "Total items consumed: " << consumed_count << endl;

return 0;
}
Output->
Experiment - 6
Aim- Write a program for the simulation of producer-consumer problem
using semaphores.

#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

class BankersAlgorithm
{
private:
int numProcesses; // Number of processes
int numResources; // Number of resource types
vector<vector<int>> maxMatrix; // Maximum demand matrix
vector<vector<int>> allocationMatrix; // Allocation matrix
vector<vector<int>> needMatrix; // Need matrix
vector<int> available; // Available resources

public:
BankersAlgorithm(int processes, int resources)
{
numProcesses = processes;
numResources = resources;

maxMatrix.resize(numProcesses, vector<int>(numResources, 0));


allocationMatrix.resize(numProcesses, vector<int>(numResources, 0));
needMatrix.resize(numProcesses, vector<int>(numResources, 0));
available.resize(numResources, 0);
}

void inputData()
{
cout << "Enter the available resources (space-separated): ";
for (int i = 0; i < numResources; i++)
{
cin >> available[i];
}

cout << "\nEnter the maximum demand matrix:\n";


for (int i = 0; i < numProcesses; i++)
{
cout << "For Process " << i + 1 << ": ";
for (int j = 0; j < numResources; j++)
{
cin >> maxMatrix[i][j];
}
}
cout << "\nEnter the allocation matrix:\n";
for (int i = 0; i < numProcesses; i++)
{
cout << "For Process " << i + 1 << ": ";
for (int j = 0; j < numResources; j++)
{
cin >> allocationMatrix[i][j];
}
}

calculateNeed();
}

void calculateNeed()
{
for (int i = 0; i < numProcesses; i++)
{
for (int j = 0; j < numResources; j++)
{
needMatrix[i][j] = maxMatrix[i][j] - allocationMatrix[i][j];
}
}
}

bool isSafe()
{
vector<bool> finish(numProcesses, false); // Track which processes are finished
vector<int> work = available; // Work vector for checking safety

int count = 0;
while (count < numProcesses)
{
bool found = false;
for (int i = 0; i < numProcesses; i++)
{
if (!finish[i])
{
bool canFinish = true;
for (int j = 0; j < numResources; j++)
{
if (needMatrix[i][j] > work[j])
{
canFinish = false;
break;
}
}
if (canFinish)
{
for (int j = 0; j < numResources; j++)
{
work[j] += allocationMatrix[i][j];
}
finish[i] = true;
found = true;
count++;
}
}
}
if (!found)
{
return false; // No safe sequence found
}
}
return true; // Safe sequence exists
}

void displayMatrices()
{
// Header for display
cout << setw(12) << "Allocation" << setw(8) << "Max" << setw(8) << "Need" <<
setw(8) << "Available" << endl;
cout << setw(4) << " " << setw(4) << "A B C D " << setw(4) << "A B C D " <<
setw(4) << "A B C D " << setw(4) << "A B C D " << endl;

// Display each row for processes


for (int i = 0; i < numProcesses; i++)
{
cout << "P" << i << " ";
// Print allocation row
for (int j = 0; j < numResources; j++)
{
cout << setw(4) << allocationMatrix[i][j];
}

cout << " ";

// Print max row


for (int j = 0; j < numResources; j++)
{
cout << setw(4) << maxMatrix[i][j];
}

cout << " ";

// Print need row


for (int j = 0; j < numResources; j++)
{
cout << setw(4) << needMatrix[i][j];
}

cout << " ";

// Print available row (only at the bottom)


if (i == numProcesses - 1)
{
cout << " ";
for (int j = 0; j < numResources; j++)
{
cout << setw(4) << available[j];
}
}
cout << endl;
}
}
};

int main()
{
int numProcesses, numResources;

cout << "Enter the number of processes: ";


cin >> numProcesses;
cout << "Enter the number of resource types: ";
cin >> numResources;

BankersAlgorithm bankers(numProcesses, numResources);


bankers.inputData();

bankers.displayMatrices();

if (bankers.isSafe())
{
cout << "\nThe system is in a safe state." << endl;
}
else
{
cout << "\nThe system is in an unsafe state." << endl;
}

return 0;
}
Output->​
Experiment - 7
Aim- Write a program for the simulation of following contiguous memory
allocation techniques​
a) Worst-fit ​ ​ ​ b) Best-fit​​ ​ ​ c) First-fit​

a) Worst-fit
#include <iostream>
#include <vector>

using namespace std;

// Function for First-fit memory allocation


void firstFit(vector<int> &memory, vector<int> &processes)
{
cout << "First-fit Allocation:" << endl;
for (int i = 0; i < processes.size(); i++)
{
bool allocated = false;
for (int j = 0; j < memory.size(); j++)
{
if (memory[j] >= processes[i])
{
memory[j] -= processes[i];
cout << "Process " << i + 1 << " allocated to block " << j + 1 << endl;
allocated = true;
break;
}
}
if (!allocated)
{
cout << "Process " << i + 1 << " cannot be allocated" << endl;
}
}
}

int main()
{
int m, n;
cout << "Enter number of memory blocks: ";
cin >> m;
cout << "Enter number of processes: ";
cin >> n;

vector<int> memory(m), processes(n);

cout << "Enter the size of memory blocks: ";


for (int i = 0; i < m; i++)
{
cin >> memory[i];
}

cout << "Enter the size of processes: ";


for (int i = 0; i < n; i++)
{
cin >> processes[i];
}

// First-fit allocation
firstFit(memory, processes);

return 0;
}
Output->​




b) Best-fit​
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

// Function for Best-fit memory allocation


void bestFit(vector<int> &memory, vector<int> &processes)
{
cout << "Best-fit Allocation:" << endl;
for (int i = 0; i < processes.size(); i++)
{
int bestIdx = -1;
int minDiff = INT_MAX;
for (int j = 0; j < memory.size(); j++)
{
if (memory[j] >= processes[i] && memory[j] - processes[i] < minDiff)
{
bestIdx = j;
minDiff = memory[j] - processes[i];
}
}
if (bestIdx != -1)
{
memory[bestIdx] -= processes[i];
cout << "Process " << i + 1 << " allocated to block " << bestIdx + 1 << endl;
}
else
{
cout << "Process " << i + 1 << " cannot be allocated" << endl;
}
}
}
int main()
{
int m, n;
cout << "Enter number of memory blocks: ";
cin >> m;
cout << "Enter number of processes: ";
cin >> n;
vector<int> memory(m), processes(n);
cout << "Enter the size of memory blocks: ";
for (int i = 0; i < m; i++)
{
cin >> memory[i];
}
cout << "Enter the size of processes: ";
for (int i = 0; i < n; i++)
{
cin >> processes[i];
}
bestFit(memory, processes);

return 0;
}

Output->
c) Worst-fit​
#include <iostream>
#include <vector>
#include <climits>

using namespace std;


void worstFit(vector<int> &memory, vector<int> &processes)
{
cout << "Worst-fit Allocation:" << endl;
for (int i = 0; i < processes.size(); i++)
{
int worstIdx = -1;
int maxDiff = -1;
for (int j = 0; j < memory.size(); j++)
{
if (memory[j] >= processes[i] && memory[j] - processes[i] > maxDiff)
{
worstIdx = j;
maxDiff = memory[j] - processes[i];
}
}
if (worstIdx != -1)
{
memory[worstIdx] -= processes[i];
cout << "Process " << i + 1 << " allocated to block " << worstIdx + 1 <<
endl;
}
else
{
cout << "Process " << i + 1 << " cannot be allocated" << endl;
}
}
}

int main()
{
int m, n;
cout << "Enter number of memory blocks: ";
cin >> m;
cout << "Enter number of processes: ";
cin >> n;

vector<int> memory(m), processes(n);

cout << "Enter the size of memory blocks: ";


for (int i = 0; i < m; i++)
{
cin >> memory[i];
}

cout << "Enter the size of processes: ";


for (int i = 0; i < n; i++)
{
cin >> processes[i];
}
worstFit(memory, processes);
return 0;
}​

Output->



Experiment - 8
Aim- Write a program for the simulation of following page replacement
algorithms​
a) FIFO ​ ​ ​ b) LRU ​ ​ ​ c) Optimal​

a) FIFO
#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

int fifo_page_replacement(vector<int> &page_references, int num_frames)


{
vector<int> frames;
unordered_set<int> frames_set;
int page_faults = 0;

for (int page : page_references)


{
if (frames_set.find(page) == frames_set.end())
{
if (frames.size() < num_frames)
{
frames.push_back(page);
frames_set.insert(page);
}
else
{
frames_set.erase(frames[0]);
frames[0] = page;
frames_set.insert(page);
}
page_faults++;
}

// Print frames horizontally at each step


cout << "Frames: ";
for (int frame : frames)
{
cout << frame << " ";
}
cout << endl;
}

return page_faults;
}

int main()
{
vector<int> page_references = {1, 2, 3, 4, 5, 3, 4, 1, 6, 7, 8, 9, 7, 8, 9, 5, 4,
2};
int num_frames = 4;

cout << "FIFO Page Replacement:" << endl;


int fifo_faults = fifo_page_replacement(page_references, num_frames);
cout << "Total FIFO page faults: " << fifo_faults << endl;

return 0;
}

Output->



b) LRU ​
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

int lru_page_replacement(vector<int> &page_references, int num_frames)


{
vector<int> frames;
unordered_set<int> frames_set;
int page_faults = 0;
for (int page : page_references)
{
if (frames_set.find(page) == frames_set.end())
{
if (frames.size() < num_frames)
{
frames.push_back(page);
frames_set.insert(page);
}
else
{
frames_set.erase(frames[0]);
frames.erase(frames.begin());
frames.push_back(page);
frames_set.insert(page);
}
page_faults++;
}
else
{
auto it = find(frames.begin(), frames.end(), page);
frames.erase(it);
frames.push_back(page);
}

// Print frames horizontally at each step


cout << "Frames: ";
for (int frame : frames)
{
cout << frame << " ";
}
cout << endl;
}

return page_faults;
}

int main()
{
vector<int> page_references = {1, 2, 3, 4, 5, 3, 4, 1, 6, 7, 8, 9, 7, 8, 9, 5, 4,
2};
int num_frames = 4;

cout << "LRU Page Replacement:" << endl;


int lru_faults = lru_page_replacement(page_references, num_frames);
cout << "Total LRU page faults: " << lru_faults << endl;

return 0;
}​



Output->



c) Optimal
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int optimal_page_replacement(vector<int> &page_references, int num_frames)


{
vector<int> frames;
int page_faults = 0;

for (int i = 0; i < page_references.size(); ++i)


{
int page = page_references[i];

if (find(frames.begin(), frames.end(), page) == frames.end())


{
if (frames.size() < num_frames)
{
frames.push_back(page);
}
else
{
int farthest = -1;
int index_to_replace = -1;

for (int j = 0; j < frames.size(); ++j)


{
auto it = find(page_references.begin() + i, page_references.end(),
frames[j]);
if (it == page_references.end())
{
index_to_replace = j;
break;
}
else
{
int next_use = it - page_references.begin();
if (next_use > farthest)
{
farthest = next_use;
index_to_replace = j;
}
}
}

frames[index_to_replace] = page;
}
page_faults++;
}

// Print frames horizontally at each step


cout << "Frames: ";
for (int frame : frames)
{
cout << frame << " ";
}
cout << endl;
}

return page_faults;
}

int main()
{
vector<int> page_references = {1, 2, 3, 4, 5, 3, 4, 1, 6, 7, 8, 9, 7, 8, 9, 5, 4,
2};
int num_frames = 4;

cout << "Optimal Page Replacement:" << endl;


int optimal_faults = optimal_page_replacement(page_references, num_frames);
cout << "Total Optimal page faults: " << optimal_faults << endl;
return 0;
}


Output->


Experiment - 9
Aim- Write a program for the simulation of following disk scheduling
algorithms​
a) FCFS​ ​ ​ b) SCAN​ ​ ​ c) C-SCAN​

a) FCFS
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int fcfs_disk_scheduling(vector<int> &requests, int initial_head_position)


{
int total_seek_count = 0;
int current_position = initial_head_position;

// Traverse through all disk requests


cout << "FCFS Disk Scheduling (Detailed):" << endl;
for (int i = 0; i < requests.size(); i++)
{
int next_request = requests[i];
int seek_distance = abs(next_request - current_position);
total_seek_count += seek_distance;

cout << "Current Head: " << current_position


<< " -> Next Request: " << next_request
<< " | Seek Distance: " << seek_distance
<< " | Total Seek Count: " << total_seek_count << endl;

current_position = next_request; // Move head to the requested position


}

return total_seek_count;
}

int main()
{
vector<int> requests = {176, 79, 34, 60, 92, 11, 41, 114};
int initial_head_position = 50;

int total_seek_count = fcfs_disk_scheduling(requests, initial_head_position);


cout << "\nTotal Seek Count for FCFS: " << total_seek_count << endl;

return 0;
}
Output->



b) SCAN​
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int scan_disk_scheduling(vector<int> &requests, int initial_head_position, int


disk_size)
{
int total_seek_count = 0;
int current_position = initial_head_position;
bool direction = true; // true means moving towards the higher end, false means
moving towards lower end

// Sort the requests to handle them in order


sort(requests.begin(), requests.end());

vector<int> left, right;


for (int i = 0; i < requests.size(); i++)
{
if (requests[i] < current_position)
{
left.push_back(requests[i]);
}
else
{
right.push_back(requests[i]);
}
}

cout << "SCAN Disk Scheduling (Detailed):" << endl;


if (direction)
{
// Move towards higher end first
total_seek_count += abs(current_position - right[0]);
current_position = right[0];
cout << "Current Head: " << current_position
<< " -> Next Request: " << right[0]
<< " | Seek Distance: " << abs(current_position - right[0])
<< " | Total Seek Count: " << total_seek_count << endl;

for (int i = 1; i < right.size(); i++)


{
total_seek_count += abs(right[i] - current_position);
current_position = right[i];
cout << "Current Head: " << current_position
<< " -> Next Request: " << right[i]
<< " | Seek Distance: " << abs(right[i] - current_position)
<< " | Total Seek Count: " << total_seek_count << endl;
}

// Then move towards the lower end


total_seek_count += abs(current_position - left.back());
current_position = left.back();
cout << "Current Head: " << current_position
<< " -> Next Request: " << left.back()
<< " | Seek Distance: " << abs(current_position - left.back())
<< " | Total Seek Count: " << total_seek_count << endl;

for (int i = left.size() - 2; i >= 0; i--)


{
total_seek_count += abs(left[i] - current_position);
current_position = left[i];
cout << "Current Head: " << current_position
<< " -> Next Request: " << left[i]
<< " | Seek Distance: " << abs(left[i] - current_position)
<< " | Total Seek Count: " << total_seek_count << endl;
}
}
else
{
// Move towards the lower end first
total_seek_count += abs(current_position - left.back());
current_position = left.back();
cout << "Current Head: " << current_position
<< " -> Next Request: " << left.back()
<< " | Seek Distance: " << abs(current_position - left.back())
<< " | Total Seek Count: " << total_seek_count << endl;

for (int i = left.size() - 2; i >= 0; i--)


{
total_seek_count += abs(left[i] - current_position);
current_position = left[i];
cout << "Current Head: " << current_position
<< " -> Next Request: " << left[i]
<< " | Seek Distance: " << abs(left[i] - current_position)
<< " | Total Seek Count: " << total_seek_count << endl;
}
// Then move towards the higher end
total_seek_count += abs(current_position - right[0]);
current_position = right[0];
cout << "Current Head: " << current_position
<< " -> Next Request: " << right[0]
<< " | Seek Distance: " << abs(current_position - right[0])
<< " | Total Seek Count: " << total_seek_count << endl;

for (int i = 1; i < right.size(); i++)


{
total_seek_count += abs(right[i] - current_position);
current_position = right[i];
cout << "Current Head: " << current_position
<< " -> Next Request: " << right[i]
<< " | Seek Distance: " << abs(right[i] - current_position)
<< " | Total Seek Count: " << total_seek_count << endl;
}
}

return total_seek_count;
}

int main()
{
vector<int> requests = {176, 79, 34, 60, 92, 11, 41, 114};
int initial_head_position = 50;
int disk_size = 200;

int total_seek_count = scan_disk_scheduling(requests, initial_head_position,


disk_size);
cout << "\nTotal Seek Count for SCAN: " << total_seek_count << endl;

return 0;
}
Output->



c) C-SCAN​
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int cscan_disk_scheduling(vector<int> &requests, int initial_head_position, int


disk_size)
{
int total_seek_count = 0;
int current_position = initial_head_position;

// Sort the requests


sort(requests.begin(), requests.end());

vector<int> left, right;


for (int i = 0; i < requests.size(); i++)
{
if (requests[i] < current_position)
{
left.push_back(requests[i]);
}
else
{
right.push_back(requests[i]);
}
}

cout << "C-SCAN Disk Scheduling (Detailed):" << endl;


// First, handle the right part of the requests
total_seek_count += abs(current_position - right[0]);
current_position = right[0];
cout << "Current Head: " << current_position
<< " -> Next Request: " << right[0]
<< " | Seek Distance: " << abs(current_position - right[0])
<< " | Total Seek Count: " << total_seek_count << endl;

for (int i = 1; i < right.size(); i++)


{
total_seek_count += abs(right[i] - current_position);
current_position = right[i];
cout << "Current Head: " << current_position
<< " -> Next Request: " << right[i]
<< " | Seek Distance: " << abs(right[i] - current_position)
<< " | Total Seek Count: " << total_seek_count << endl;
}

// Then move to the lowest track and serve the left part of the requests
total_seek_count += abs(current_position - (disk_size - 1));
current_position = disk_size - 1; // Move to the farthest position
cout << "Current Head: " << current_position
<< " -> Next Request: " << disk_size - 1
<< " | Seek Distance: " << abs(current_position - (disk_size - 1))
<< " | Total Seek Count: " << total_seek_count << endl;

total_seek_count += abs(current_position - left[0]);


current_position = left[0];
cout << "Current Head: " << current_position
<< " -> Next Request: " << left[0]
<< " | Seek Distance: " << abs(current_position - left[0])
<< " | Total Seek Count: " << total_seek_count << endl;

for (int i = 1; i < left.size(); i++)


{
total_seek_count += abs(left[i] - current_position);
current_position = left[i];
cout << "Current Head: " << current_position
<< " -> Next Request: " << left[i]
<< " | Seek Distance: " << abs(left[i] - current_position)
<< " | Total Seek Count: " << total_seek_count << endl;
}

return total_seek_count;
}

int main()
{
vector<int> requests = {176, 79, 34, 60, 92, 11, 41, 114};
int initial_head_position = 50;
int disk_size = 200;

int total_seek_count = cscan_disk_scheduling(requests, initial_head_position,


disk_size);
cout << "\nTotal Seek Count for C-SCAN: " << total_seek_count << endl;

return 0;
}

Output->



Experiment - 10
Aim- Write a program for the simulation of following file allocation strategies
a) Sequential​ ​ b) Indexed​ ​ c) Linked​

a) Sequential​
#include <iostream>
#include <vector>

using namespace std;

void sequential_allocation(vector<int> &file_blocks, int block_size)


{
cout << "\nSequential Allocation (File Allocation):" << endl;
int file_size = file_blocks.size();

// Assuming file_blocks represents block numbers where the file is stored


int starting_block = file_blocks[0];
int end_block = file_blocks[file_size - 1];
cout << "Starting block for the file: " << starting_block << endl;
cout << "Ending block for the file: " << end_block << endl;
cout << "The file occupies the following contiguous blocks: ";
for (int i = 0; i < file_size; i++)
{
cout << file_blocks[i] << " ";
}
cout << endl;
cout << "Total number of blocks occupied by the file: " << file_size << endl;
}

int main()
{
vector<int> file_blocks = {2, 3, 4, 5}; // Contiguous blocks for the file
int block_size = 4; // Number of blocks to store the file

sequential_allocation(file_blocks, block_size);

return 0;
}

Output->​ ​


b) Indexed Allocation​
#include <iostream>
#include <vector>

using namespace std;

void indexed_allocation(vector<int> &file_blocks, vector<int> &index_table)


{
cout << "\nIndexed Allocation (File Allocation):" << endl;
int file_size = file_blocks.size();

// Index table stores pointers to file blocks


cout << "File blocks in memory (non-contiguous): ";
for (int i = 0; i < file_size; i++)
{
index_table.push_back(file_blocks[i]); // Map each block in index table
cout << file_blocks[i] << " ";
}
cout << endl;
cout << "Index Table (addresses of file blocks): ";
for (int i = 0; i < file_size; i++)
{
cout << index_table[i] << " ";
}
cout << endl;

cout << "Total number of blocks: " << file_size << endl;
cout << "The file is scattered across the following blocks: ";
for (int i = 0; i < file_size; i++)
{
cout << file_blocks[i] << " ";
}
cout << endl;
}

int main()
{
vector<int> file_blocks = {2, 5, 8, 10};​
vector<int> index_table;
indexed_allocation(file_blocks, index_table);
return 0;
}

Output->​



c) Linked Allocation​
#include <iostream>
#include <vector>

using namespace std;

void linked_allocation(vector<int> &file_blocks)


{
cout << "\nLinked Allocation (File Allocation):" << endl;
int file_size = file_blocks.size();

cout << "File blocks stored in memory (linked list): ";


for (int i = 0; i < file_size; i++)
{
if (i != file_size - 1)
{
cout << file_blocks[i] << " -> ";
}
else
{
cout << file_blocks[i];
}
}
cout << endl;
cout << "Each block contains the address of the next block:" << endl;
for (int i = 0; i < file_size - 1; i++)
{​
cout << "Block " << file_blocks[i] << " points to block " << file_blocks[i + 1] << endl;
}​
cout << "The last block (block " << file_blocks[file_size - 1] << ") points to NULL
(end of file)." << endl;
cout << "Total number of blocks occupied by the file: " << file_size << endl;
}
int main()
{
vector<int> file_blocks = {2, 5, 7, 9}; // Non-contiguous blocks for the file
linked_allocation(file_blocks);

return 0;
}

Output->
Experiment - 11
Aim- To study the features of Windows and Linux operating system.

An Operating System (OS) is software that manages hardware and software resources on a computer or
device. It provides a user interface and manages tasks such as memory, processes, file systems, input/output
(I/O) devices, and security. The OS ensures that software applications can function by providing a stable and
consistent environment for users and hardware components.

1.​ Process Management:


○​ The OS manages processes, including multitasking, scheduling, and execution of processes. It
ensures that each process gets enough CPU time and that resources are allocated efficiently.
2.​ Memory Management:
○​ It handles the allocation, deallocation, and management of memory. The OS ensures that each
running process has access to its own memory space without interfering with others.
3.​ File System Management:
○​ The OS manages files, directories, and storage devices. It provides file access, organization,
creation, deletion, and security measures for data storage.
4.​ Device Management:
○​ The OS controls and coordinates the use of input and output devices such as keyboards, mice,
printers, and disk drives. It manages device drivers and ensures that devices can communicate
with the computer effectively.
5.​ Security and Access Control:
○​ The OS ensures system security by managing authentication (user login, password protection),
controlling access to resources, and implementing encryption to protect user data.​

Windows Operating System

What is Windows OS?

Windows is a family of proprietary operating systems developed by Microsoft. It is one of the most widely
used operating systems in personal computers, workstations, and servers. Known for its graphical user
interface (GUI), ease of use, and compatibility with a vast array of hardware and software, Windows has
become the default OS in many professional and personal environments.

Features of Windows OS

1.​ Graphical User Interface (GUI):

○​ Windows provides a user-friendly graphical interface with windows, icons, buttons, and
menus. This makes it easy for users to interact with the system and navigate files, programs,
and settings.

2.​ Multitasking:

○​ Windows allows users to run multiple applications simultaneously. The OS effectively


manages CPU time, memory, and other resources to provide smooth multitasking experiences.
3.​ File Management:

○​ Windows has an integrated file management system through File Explorer, allowing users to
manage, organize, and access files in a tree structure.

4.​ Security Features:

○​ Windows offers various built-in security features like Windows Defender, firewall protection,
User Account Control (UAC), BitLocker encryption, and secure boot processes to protect
against malware and unauthorized access.

5.​ Software Compatibility:

○​ Windows is compatible with a wide range of third-party applications, including business


software, gaming applications, media tools, and more. It supports numerous file formats,
ensuring extensive compatibility across industries.

6.​ Network and Internet Connectivity:

○​ Windows supports a range of networking protocols such as TCP/IP and can easily connect to
local area networks (LANs), wide area networks (WANs), and the internet. It also supports file
sharing, remote desktop, and online services.

7.​ System Restore and Backup:

○​ Windows provides built-in backup and recovery tools, such as the "System Restore" function,
which allows users to revert their system to a previous state in case of failure or issues.

8.​ Virtualization Support:

○​ Windows supports virtualization technologies like Hyper-V, allowing users to create virtual
machines to run multiple OS instances on a single physical machine.

9.​ Plug and Play (PnP):

○​ Windows automatically detects and configures new hardware without the need for manual
installation of drivers. It ensures seamless integration of peripheral devices.

Components of Windows OS

1.​ Kernel:

○​ The kernel is the core of the Windows OS. It manages system resources such as memory,
processes, and hardware communication. The kernel communicates directly with the hardware.

2.​ User Interface (UI):

○​ The user interface includes the graphical desktop, taskbar, start menu, and windows that allow
users to interact with the system.

3.​ File System:

○​ Windows uses the NTFS (New Technology File System) as its primary file system, providing
features like file compression, encryption, and permissions.
4.​ Device Drivers:

○​ Device drivers are small programs that allow the operating system to interact with hardware
peripherals such as printers, displays, and sound cards.

5.​ Services:

○​ Background processes or services that run without direct user interaction. These services
handle system functions like printing, networking, and security.

6.​ Control Panel/Settings:

○​ The Control Panel and Settings app allow users to modify system configurations, install
programs, manage hardware, and configure the network.

You might also like