0% found this document useful (0 votes)
85 views56 pages

Os Practical

The document describes setting up and conducting Experiment 1 in an Operating Systems lab course. The experiment involves installing Windows XP on a desktop PC. It outlines the necessary hardware and software requirements and provides step-by-step instructions for booting from the installation disc, navigating the setup windows, selecting a partition for installation, and beginning the Windows XP installation process.

Uploaded by

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

Os Practical

The document describes setting up and conducting Experiment 1 in an Operating Systems lab course. The experiment involves installing Windows XP on a desktop PC. It outlines the necessary hardware and software requirements and provides step-by-step instructions for booting from the installation disc, navigating the setup windows, selecting a partition for installation, and beginning the Windows XP installation process.

Uploaded by

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

Khalsa College of Engineering and Technology, Amritsar

(Department of Computer Science & Engineering)

Khalsa College of Engineering and Technology, Amritsar


Department of CSE

Course Code: BTCS404-18


Course Title: Operating System Lab

List of Experiments
Task 1: Installation Process of various operating systems.

Task 2: Implementation of CPU scheduling algorithms to find turnaround time and waiting
time. a) FCFS b) SJF c) Round Robin (pre-emptive) d) Priority.

Task 3: Virtualization, Installation of Virtual Machine Software and installation of Operating


System on Virtual Machine.

Task 4: Commands for files & directories: cd, ls, cp, md, rm, mkdir, rmdir. Creating and
viewing files using cat. File comparisons. Disk related commands: checking disk
free spaces. Processes in linux, connecting processes with pipes, background
processing, managing multiple processes. Background process: changing process
priority, scheduling of processes at command, batch commands, kill, ps, who, sleep.
Printing commands, grep, fgrep, find, sort, cal, banner, touch, file. File related
commands ws, sat, cut, grep.

Task 5: Shell Programming: Basic of shell programming, various types of shell, Shell
Programming in bash, conditional & looping statement, case statements, parameter
passing and arguments, shell variables, shell keywords, creating shell programs for
automate system tasks, report printing.

Task 6: Implementation of Bankers algorithm for the purpose of deadlock avoidance.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Course Code: BTCS404-18


Course Title: Operating System Lab

S.N NAME OF EXPERIMENT


O
1 Installation Process of Windows XP
2 Virtualization: Installation of Virtual Machine Software (VMWare)
3 Installation of LINUX (UBUNTU 22.04 ) on VMWare
4 Installation of LINUX (UBUNTU 22.04 ) and dual boot with Windows
XP/ Windows 7
5 WAP to implementation of FCFS CPU scheduling
6 WAP to implementation of SJF CPU scheduling
7 WAP to implementation of Round robin CPU scheduling
8 Commands for files & directories: cd, ls, cp, mv, rm, mkdir, rmdir.
9 Creating and viewing files using cat.
File comparisons.
Disk related commands: checking disk free spaces.
10 Processes in linux, connecting processes with pipes, background
processing, managing multiple processes. Manual help.
Background process: changing process priority, scheduling of processes
at command,
11 Batch commands, kill, ps, who, sleep.
Printing commands, grep, fgrep, find, sort, cal, banner, touch, file.
File related commands ws, sat, cut, grep.
12 Shell Programming: Basic of shell programming, various types of shell,
Shell Programming in bash
13 Conditional & looping statement, case statements
14 Parameter passing and arguments, shell variables, shell keywords,
15 Implement of bankers algorithm for purpose of deadlock avoidance.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Experiment No.1
Name of Experiment: Installation of Windows XP
Aim: ToInstall Windows XP
Hardware requirements: Intel based Desktop PC with1 GHz Processor &RAM of 512 MB
Software requirements: Windows XP CD
Procedure:-
Windows XP is one of Microsoft’s most popular operating systems, and though it’s starting
to show its age, many people still use it exclusively. Whether you’ve got an old computer that
you want to get functioning again or you want to install XP on your new machine, it will only
take a short while.
Ensure that your computer can run Windows XP. Your computer will need to meet or
exceed the minimum system requirements in order to run Windows XP. You can find your
system information by either checking the computer manufacturer's manual, or by running
DirectX Diagnostic on an existing Windows operating system of the computer.
To start the DirectX Diagnostic, open the Run dialog (press WinKey+R simultaneously), type
dxdiag, and click OK.
Minimum System Requirements
1GHz Intel or AMD CPU
512 MB of system RAM
5 GB of available drive space
CD or DVD-ROM
Set your computer to boot from CD/DVD. Before inserting the CD, you'll need to set your
computer to boot from a CD instead of from the hard drive. This will allow you to load the
Windows XP setup files before your computer boots to its installed operating system. You
can change the boot order from the BOOT menu in your BIOS.
To enter the BIOS of your computer, you usually press F9 or DEL when your computer starts
or notifies you that you can enter "setup". Click the green "BIOS" link for more information.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

In the BOOT menu, set the order so that your CD/DVD-ROM drive is set as the 1st Boot
Device.
If you are installing Windows XP from a USB drive, make sure that the USB drive is set as
the 1st Boot Device. You may need to have the USB drive inserted for it to appear as an
option
Load the installer. Once your Boot Order is set, insert the Windows XP CD into your drive
and Save and Exit from the BIOS. Your computer will reboot and you will be presented with
the message: Press any key to boot from CD. Press any key on your keyboard to start the
Setup program.
Setup will load files necessary to begin the installation, which may take a few moments.
Once the loading is complete, you will be taken to the Welcome screen.
Read the License Agreement. This document tells you what you can and can’t do with
Windows, and your rights as the consumer. After reading, press F8 indicating you agree to
the terms.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Select the partition you want to install on. You will see a list of available partitions on your
installed hard drives. If you are installing Windows XP on a new hard drive, you should see
only one entry labeled "Unpartitioned space." If you have a previous version of Windows or
Linux installed on your computer, you will potentially have multiple partitions.
Installing Windows
XP will erase all of
the data on the
partition that you
choose. Select a
partition that is
empty or that
contains data that
you do not care to lose.

Create a new partition. Select the Unpartitioned space and press “C”. This will open a new
screen where you can set the partition’s size from the available space. Enter the size in
megabytes (MB) for the new partition and then press ENTER.
By default, the partition will be set to the maximum amount of available space. Unless you
plan on creating multiple partitions, you can usually leave this at its default.
Windows XP requires at least 1.5 gigabytes (1536 MB) for its installation files, but you will
want more than this for programs, documents, downloads, and other files. 5 gigabytes (5120
MB) is a good baseline amount for Windows XP, with more if you plan on installing a lot of
programs.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

You can create multiple partitions on a single drive. This can allow you to separate your
programs from your movies and music, or to install another operating system. Windows XP
can only be installed on one discrete partition

Select your new partition. Once you’ve created your installation partition, you will be
returned to the partition selection screen. Select your new partition, usually labeled "C:
Partition 1 [Raw]" and press ENTER.
Select "Format the Partition using the NTFS File System" and press ENTER. NTFS is
the preferred method, supporting a larger amount of disk space per partition than FAT, and
including security features at the file system level. NTFS also includes system level
compression. There are almost no situations anymore where choosing FAT would be
preferable.
If your partition size is larger than 32 GB, you will not be given the option to choose FAT.
It is highly recommended to avoid Quick Format, as this skips an important process that
checks the hard drive for errors or bad sectors. This scan is what consumes the majority of the
time taken when performing a full format. If there are errors on a disk at the physical level,
it's best to catch them now rather than later.
Wait for the format
to complete. The system
will now format the
partition. The length
of time this process
requires depends on the

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

speed and size of the drive. In general, the larger the partition, the longer the process will
take.

Wait for the Setup files to copy. Windows will now start copying files from the installation
disc and prompt you to reboot the computer when the process is completed. Press ENTER
when prompted to reboot, otherwise it will do so automatically after 15 seconds.
Allow the
computer to
boot normally.
You will see the
message asking you to
press a key to boot
from CD. Ignore it and
allow the computer to
continue booting from
the hard drive. You
will see the Windows logo as the Setup program loads.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Wait for the installation to proceed. After the Windows logo goes away, you will see a list
of steps remaining on the left side of the screen, and tips for using windows on the right. The
time remaining for the installation will be displayed below the list of steps remaining.
It is normal for the screen to flicker, turn on and off, or resize during this process.
Choose your language and region settings. During the installation process a dialog window
will appear, asking you to choose your Regional settings. Select appropriate settings native to
your area. Click the Next button when that is completed.
Enter your full name if you want. This will be set as the “owner” of Windows, and will be
attached to certain things, such as Document creation.

Enter your Product Key. You will not be able to complete the installation process without a
valid Product Key.
Click "Next" to
continue.
Some versions of
Windows will not ask
for the Product Key
until installation is
complete
Set your computer’s name. This will be the name that represents the computer on a
network. Windows sets a default name, but you can change it if you would like. You can also

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

set a password for the Administrator account. This is optional, but recommended for public
computers.
Select your time zone. Ensure that the date/time are correct. Click "Next" to continue.
Wait for the installation to finalize. This will only take a few minutes, and the computer
will reboot when it is finished installing. Once the computer reboots, you will be taken to the
Windows XP desktop. At this point, installation is complete, though there are a few things
left to do before Windows is completely usable.
Start using Windows. You will now be looking at the default Windows XP Desktop.
Congratulations! There are a few things that you should probably do now that you have
Windows up and running:
Install any drivers that you need to for your computer’s hardware.

Precautions:
1. Check the
surface of the CD/ DVD before installation.
2. Take backup the data of the PC before installation.
3. Create partitions very carefully and utilize HD space as per requirement.
Conclusion:
4. A hard disk is partitioned into three drives.
5. C: drive is formatted with NTFS file system.
6. Windows XP is installed in C: drive.

Experiment No-2

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Name of the experiment: Installation of LINUX (UBUNTU 22.04 ) and dual boot with
Windows XP.
Aim: To Install the LINUX Operating System along with Windows XP.
Hardware requirements: Intel based Desktop PC,RAM 1GB
Software requirements: (UBUNTU 22.04 ) CD
Procedure:-
Installing (UBUNTU 22.04 )
Once Windows XP is installed, you can install (UBUNTU 22.04 ) by inserting CD One of
three and letting it boot. Then, just follow the instructions on the screen. When it's time to
partition the disk, you chose the default option to Remove All Linux Partitions on This
System since you had no Linux partitions.

Choosing this option will give you a warning that all of your data is going to be removed
from the Linux partition. Don’t worry about this warning, because on a fresh system there is
no data to be removed. On the next screen, the Linux installer breaks down the layout of the
hard drive for you to look like:

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

At the top of the partition layout, you see that /dev/hda1 is of the type NTFS/HPFS. This is
your Windows XP partition. Below that, there are four partitions for Linux. The first one is
an ext3 partition labeled /boot. The ext3 type is the standard file system type for (UBUNTU
22.04 ) and /boot is the name of the Linux boot partition. Next, there is another ext3
partition named /, which is the rest of the Linux file system. Finally, on an extended type
partition, there is a swap partition, which every Linux system needs. After this step, you need
to configure the Linux boot loader that is named GRUB.

GRUB will detect that there is already an OS installed in the master boot record and will give
you on opportunity to configure it. This is a critical step. If you don't configure it here, you

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

will have to manually edit the configuration files later. For my installation, I named the hda1
partition Windows XP and then clicked Next to continued to complete the installation by
installing what I needed to run my system

Rebooting
Once Linux is fully installed, the system will automatically reboot, and you will be greeted
with the GRUB boot loader screen
Choosing Windows XP from the list will start up Windows XP, as it should; choosing
(UBUNTU 22.04 ) will start that OS instead. If you don't choose any OS selection,
(UBUNTU 22.04 ) will start by default.
Precautions:
1 Check the surface of the CD before installation.
2 Create a GRUB and ROOT password
3 Create Linux partitions very carefully and utilize HD space as per requirement.
Conclusion:
We can dual boot (UBUNTU 22.04 ) with Windows XP.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Experiment No-3
Name of the experiment: Installation of VMWare
Aim: To Install VMWare for understanding Virtualization.
Hardware requirements: Intel based Desktop PC with 2GHz CPU & RAM 1GB
Software requirements: VMWare workstation Software
Procedure:-
This introduction is about how to install a virtual machine on your computer. A virtual
machine (VM) is a software implementation of a machine (a computer) that executes
programs like a physical machine. Most people have one computer. If you want to set up a
local area network or a machine to be small-scale experiments, it is not enough. You also
want to have both windows and Linux OS. Buy a computer is not worth it. Fortunately,
Virtual machine software can virtual a lot of guests in a host computer.
Install the VMware Workstation a Windows host computers.

Note: To install Workstation on a Windows XP host computer, you must log on as


administrator.

If you are installing from a CD, put your CD in your CD-ROM drive, it will begin
automatically.

If you are installing from a downloaded file, browse to the directory where you saved the
downloaded installer file and run the installer. The file name is similar with this: VMware-
workstation-full-7.1.3-324285.exe.

Choose the set up type you prefer. If you don’t know it very well, choose typical. Then
click next.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Choose the directory in which to install VMware Workstation. To install it in a directory


other than the default, click Change and browse to your directory of choice. If the directory
does not exist, the installer creates it for you. Click Next. Caution: Do not install VMware
Workstation on a network drive.

The installer has gathered the necessary information and is ready to begin installing the
software. If you want to change any settings or information you provided, now is the time to
make those changes. Click Back until you reach the dialog box containing the information
you want to change. If you do not need to make any changes, click Continue. The installer
begins copying files to your computer.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Enter your serial number, your name(Optional), company name(Optional),then click


Next. Note: If you skip this step, you must enter your serial number later, before you can
power on a virtual machine.
Restart your computer, allows VMware Workstation to complete the installation, then
double-click the VMware Workstation icon on your desktop.
Start the New Virtual Machine Wizard.
Choose File > New > Virtual Machine to begin creating your virtual machine.
Begin to install a guest operating system. Choose how you will install the guest operating
system, then click next.
Here is how to install Windows XP as a guest operating system. Enter the windows
product key, full name, password (optional) and click next

Name the virtual machine and choose the location for it. Click Browse if you want to
change the default location. Click next.
Installing a guest operating system inside your VMware Workstation virtual machine is the
same as installing it on a physical computer.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Power on your virtual machine by clicking the Power On button. Follow the instructions
provided by the operating system vendor.
Precautions:
1. Check the surface of the CD/ DVD before installation.
2. If the software is on HD, note down the path of the software.
3. Make sure that it is a licensed software and you are having the serial number
of the product.

Conclusion:
1. VMWare software is installed on Windows XP.
2. A virtual machine (VM) is a software implementation of a machine (a computer) that
executes programs like a physical machine.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Experiment No-4
Name of the experiment: Installation of LINUX UBUNTU 22.04 LTS on VM Ware.
Aim: To Install the LINUX Operating System on VMware.
Hardware requirements: Intel based Desktop PC, RAM 1GB
Software requirements: Ubuntu Linux ISO image (UBUNTU 22.04 LTS)
Procedure:-
VMware Workstation is very useful application that can provide you a feature function to
install several Operating Systems in it. You can switch between some Operating System
frequently while you are using that Operating System in VMware Workstation. Ubuntu is
also feature free software; it's fast and easy to use with some helpful Linux Command lines.
If you have software in DVD which contained software that you want to create, choose Install
disc. Otherwise, choosing the Installer Disc image file (ISO) software application with
extension ISO.
Keep pressing “Next” to continue, you see the screen mentions about browsing directory
Ubuntu will be stored in. Click “Next”.
Setting maximum disk size (GB) as 8 and choose the option “Store virtual disk as a single
file”, then hit "Next".
Hit Finish to end the creating of new Virtual Machine.
It will automatically reboot and take you go to this screen, next, it will run an Ubuntu
application as well (the one input "Ubuntu.ISO" above step)
The installing screen will appear and run as the picture. Being patient to wait
After finish running the installation, it will bring you go to this following screen, type the
username and password which is created before.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Finally, you have done setting Ubuntu Operating System.


Precautions:
1. Check the surface of the CD/ DVD before installation.
2. Assign resources to the new virtual machine as per the requirement.
3. Create Linux partitions very carefully and utilize HD space as per
requirement.
Conclusion:
1. A virtual machine is created.
2. Computer resources are provided to the virtual machine.
3. Ubuntu Linux is installed on VMWare and it is able to work as a virtual
machine.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Experiment 5
Program for implementation of FCFS scheduling

#include<iostream>
using namespace std;
// Function to find the waiting time for all
// processes
void findWaitingTime(int processes[], int n, int bt[], int wt[])
{
// waiting time for first process is 0
wt[0] = 0;

// calculating waiting time


for (int i = 1; i < n ; i++ )
wt[i] = bt[i-1] + wt[i-1] ;
}
// Function to calculate turn around time
void findTurnAroundTime( int processes[], int n, int bt[], int wt[], int tat[])
{
// calculating turnaround time by adding
// bt[i] + wt[i]
for (int i = 0; i < n ; i++)
tat[i] = bt[i] + wt[i];
}
//Function to calculate average time
void findavgTime( int processes[], int n, int bt[])
{
int wt[n], tat[n], total_wt = 0, total_tat = 0;

//Function to find waiting time of all processes


findWaitingTime(processes, n, bt, wt);

//Function to find turn around time for all processes


findTurnAroundTime(processes, n, bt, wt, tat);

//Display processes along with all details


cout << "Processes "<< " Burst time "
<< " Waiting time " << " Turn around time\n";

// Calculate total waiting time and total turn


// around time
for (int i=0; i<n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
cout << " " << i+1 << "\t\t" << bt[i] <<"\t "
<< wt[i] <<"\t\t " << tat[i] <<endl;
}

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

cout << "Average waiting time = "


<< (float)total_wt / (float)n;
cout << "\nAverage turn around time = "
<< (float)total_tat / (float)n;
}
// Driver code
int main()
{
//process id's
int processes[] = { 1, 2, 3};
int n = sizeof processes / sizeof processes[0];

//Burst time of all processes


int burst_time[] = {10, 5, 8};

findavgTime(processes, n, burst_time);
return 0;
}

Output:
Processes Burst time Waiting time Turn around time
1 10 0 10
2 5 10 15
3 8 15 23
Average waiting time = 8.33333
Average turn around time = 16

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Experiment 6
WAP to implement Shortest Job first with Arrival Time

#include<iostream>
using namespace std;
int mat[10][6];

void swap(int *a, int *b)


{
int temp = *a;
*a = *b;
*b = temp;
}

void arrangeArrival(int num, int mat[][6])


{
for(int i=0; i<num; i++)
{
for(int j=0; j<num-i-1; j++)
{
if(mat[j][1] > mat[j+1][1])
{
for(int k=0; k<5; k++)
{
swap(mat[j][k], mat[j+1][k]);
}
}
}
}
}

void completionTime(int num, int mat[][6])


{
int temp, val;
mat[0][3] = mat[0][1] + mat[0][2];
mat[0][5] = mat[0][3] - mat[0][1];
mat[0][4] = mat[0][5] - mat[0][2];

for(int i=1; i<num; i++)


{
temp = mat[i-1][3];
int low = mat[i][2];
for(int j=i; j<num; j++)
{
if(temp >= mat[j][1] && low >= mat[j][2])
{
low = mat[j][2];
val = j;

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

}
}
mat[val][3] = temp + mat[val][2];
mat[val][5] = mat[val][3] - mat[val][1];
mat[val][4] = mat[val][5] - mat[val][2];
for(int k=0; k<6; k++)
{
swap(mat[val][k], mat[i][k]);
}
}
}

int main()
{
int num, temp;

cout<<"Enter number of Process: ";


cin>>num;

cout<<"...Enter the process ID...\n";


for(int i=0; i<num; i++)
{
cout<<"...Process "<<i+1<<"...\n";
cout<<"Enter Process Id: ";
cin>>mat[i][0];
cout<<"Enter Arrival Time: ";
cin>>mat[i][1];
cout<<"Enter Burst Time: ";
cin>>mat[i][2];
}

cout<<"Before Arrange...\n";
cout<<"Process ID\tArrival Time\tBurst Time\n";
for(int i=0; i<num; i++)
{
cout<<mat[i][0]<<"\t\t"<<mat[i][1]<<"\t\t"<<mat[i][2]<<"\n";
}

arrangeArrival(num, mat);
completionTime(num, mat);
cout<<"Final Result...\n";
cout<<"Process ID\tArrival Time\tBurst Time\tWaiting Time\tTurnaround Time\n";
for(int i=0; i<num; i++)
{
cout<<mat[i][0]<<"\t\t"<<mat[i][1]<<"\t\t"<<mat[i][2]<<"\t\t"<<mat[i][4]<<"\t\
t"<<mat[i][5]<<"\n";
}
}

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Output:
Process ID Arrival Time Burst Time
1 2 3
2 0 4
3 4 2
4 5 4
Final Result...
Process ID Arrival Time Burst Time Waiting Time Turnaround Time
2 0 4 0 4
3 4 2 0 2
1 2 3 4 7
4 5 4 4 8

Experiment-7
WAP to implementation of Round robin scheduling.

#include<iostream>
using namespace std;

// Function to find the waiting time for all


// processes
void findWaitingTime(int processes[], int n,
int bt[], int wt[], int quantum)

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

{
// Make a copy of burst times bt[] to store remaining
// burst times.
int rem_bt[n];
for (int i = 0 ; i < n ; i++)
rem_bt[i] = bt[i];

int t = 0; // Current time

// Keep traversing processes in round robin manner


// until all of them are not done.
while (1)
{
bool done = true;

// Traverse all processes one by one repeatedly


for (int i = 0 ; i < n; i++)
{
// If burst time of a process is greater than 0
// then only need to process further
if (rem_bt[i] > 0)
{
done = false; // There is a pending process

if (rem_bt[i] > quantum)


{
// Increase the value of t i.e. shows
// how much time a process has been processed
t += quantum;

// Decrease the burst_time of current process


// by quantum
rem_bt[i] -= quantum;
}

// If burst time is smaller than or equal to


// quantum. Last cycle for this process
else
{
// Increase the value of t i.e. shows
// how much time a process has been processed
t = t + rem_bt[i];

// Waiting time is current time minus time


// used by this process
wt[i] = t - bt[i];

// As the process gets fully executed

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

// make its remaining burst time = 0


rem_bt[i] = 0;
}
}
}

// If all processes are done


if (done == true)
break;
}
}

// Function to calculate turn around time


void findTurnAroundTime(int processes[], int n,
int bt[], int wt[], int tat[])
{
// calculating turnaround time by adding
// bt[i] + wt[i]
for (int i = 0; i < n ; i++)
tat[i] = bt[i] + wt[i];
}

// Function to calculate average time


void findavgTime(int processes[], int n, int bt[],
int quantum)
{
int wt[n], tat[n], total_wt = 0, total_tat = 0;

// Function to find waiting time of all processes


findWaitingTime(processes, n, bt, wt, quantum);

// Function to find turn around time for all processes


findTurnAroundTime(processes, n, bt, wt, tat);

// Display processes along with all details


cout << "Processes "<< " Burst time "
<< " Waiting time " << " Turn around time\n";

// Calculate total waiting time and total turn


// around time
for (int i=0; i<n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
cout << " " << i+1 << "\t\t" << bt[i] <<"\t "
<< wt[i] <<"\t\t " << tat[i] <<endl;
}

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

cout << "Average waiting time = "


<< (float)total_wt / (float)n;
cout << "\nAverage turn around time = "
<< (float)total_tat / (float)n;
}

// Driver code
int main()
{
// process id's
int processes[] = { 1, 2, 3};
int n = sizeof processes / sizeof processes[0];

// Burst time of all processes


int burst_time[] = {10, 5, 8};

// Time quantum
int quantum = 2;
findavgTime(processes, n, burst_time, quantum);
return 0;
}

Output:
Processes Burst time Waiting time Turn around time
1 10 13 23
2 5 10 15
3 8 13 21
Average waiting time = 12
Average turn around time = 19.6667

Experiment No-8
Name of the experiment: Commands for files & directories: cd, ls, cp, mv, rm, mkdir, rmdir.
Aim: Test the Commands for files and Directories.
Hardware requirements: Intel based Desktop PC
Software requirements: Linux OS
Procedure:-
cd

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

The cd command, also known as chdir (change directory), is a command-line OS shell


command used to change the current working directory in operating systems such as Unix,
DOS, Windows, and Linux.
The parent directory of the current directory — in other words, the directory one level up
from the current directory, which contains the directory we're in now — is represented by
two dots ("..").
mkdir:- to create a directory
rmdir:- to remove a directory
ls:- list files and directories in the current directory
cp:- copies a file to other location (directory)
mv:- moves a file to other location
rm: - deletes a file

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Precautions:
1. Make sure that telnet server is powered ON and telnet service is running on the
server.
2. Note down the IP Address of the server machine before login remotely.
3. Make sure that you are having the username and password created on the server
machine.
Conclusion:
1. Directories can be created and deleted with ‘mkdir’ and ‘rmdir’ commands.
2. Files are copied, moved and removed with different commands.

Experiment No- 9
Name of the experiment: Creating and viewing files using cat, File comparisons, Disk
related commands: checking disk free spaces.
Aim: To test the concatenation, comparisons and checking the disk spaces.
Hardware requirements: Intel based Desktop PC
Software requirements: Linux OS
Procedure:-
cat:- used to create a file

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

$ cat filename – to display contents of a file


$ cat file1 file2 – display contents of file1 and file2
$ cat < file -- cat command now takes input from file and displays the contents on the
screen.
$ cat < oldfile > newfile – now cat takes input from oldfile and write its contents to newfile
cmp : this command is used to compare two files byte by byte and as any mismatch occurs,it
echoes it on the screen.if no mismatch occurs i gives no response.
comm : his command is used to find out the records available in one but not in another
du: The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the
information of disk usage of files and directories on a machine. The du command has many
parameter options that can be used to get the results in many formats. The du command also
displays the files and directory sizes in a recursively manner.
Using “-h” option with “du” command provides results in “Human Readable Format“.
Means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes etc.
df: The df command reports the amount of available disk space being used by file. df
displays the amount of disk space available on the file system containing each file name
argument. If no file name is given, the space available on all currently mounted file systems
is shown.

Precautions:
1. Make sure that telnet server is powered ON and telnet service is running on the
server.
2. Note down the IP Address of the server machine before login remotely.
3. Make sure that you are having the username and password created on the server
machine.
Conclusion:
1. Files can be created and viewed using cat command.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Experiment No-10
Name of the experiment: Processes in Linux, connecting processes with pipes, background
processing, managing multiple processes, Manual help, Background process: changing
process priority, scheduling of processes at command
Aim: To understand the Processes in Linux, connecting processes with pipes, background
processing, managing multiple processes, Manual help, Background process: changing
process priority, scheduling of processes at command.
Hardware requirements: Intel based Desktop PC
Software requirements: Linux OS
Procedure:-
pipes :- A pipe is a mechanism by which standard output of one program can be channeled
into the standard input of another program.
man :- It displays the manual on all unix commands and the options they support.
When you execute a program on your UNIX system, the system creates a special
environment for that program. This environment contains everything needed for the system to
run the program as if no other program were running on the system.
Whenever you issue a command in UNIX, it creates, or starts, a new process. When you tried
out the ls command to list directory contents, you started a process. A process, in simple
terms, is an instance of a running program.
The operating system tracks processes through a five digit ID number known as the pid or
process ID . Each process in the system has a unique pid.
Pids eventually repeat because all the possible numbers are used up and the next pid rolls or
starts over. At any one time, no two processes with the same pid exist in the system because it
is the pid that UNIX uses to track each process.
Starting a Process:
When you start a process (run a command), there are two ways you can run it:
Foreground Processes:
By default, every process that you start runs in the foreground. It gets its input from the
keyboard and sends its output to the screen.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

The process runs in the foreground, the output is directed to my screen, and if the ls
command wants any input (which it does not), it waits for it from the keyboard.
While a program is running in foreground and taking much time, we cannot run any other
commands (start any other processes) because prompt would not be available until program
finishes its processing and comes out.
Background Processes:
A background process runs without being connected to your keyboard. If the background
process requires any keyboard input, it waits.
The advantage of running a process in the background is that you can run other commands;
you do not have to wait until it completes to start another!
The simplest way to start a background process is to add an ampersand ( &) at the end of the
command.
This would also display all the files whose name start with ch and ends with .doc:
Here if the ls command wants any input (which it does not), it goes into a stop state until I
move it into the foreground and give it the data from the keyboard.
That first line contains information about the background process - the job number and
process ID. You need to know the job number to manipulate it between background and
foreground.
Listing Running Processes: ps command
One of the most commonly used flags for ps is the -f ( f for full) option, which provides more
information.
Here is the description of all the fileds displayed by ps -f command:
Column Description
UID User ID that this process belongs to (the person running it).
PID Process ID.
PPID Parent process ID (the ID of the process that started it).
C CPU utilization of process.
STIME Process start time.
TTY Terminal type associated with the process
TIME CPU time taken by the process.
CMD The command that started this process.
There are other options which can be used along with ps command:

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Option Description
-a Shows information about all users
-x Shows information about processes without terminals.
-u Shows additional information like -f option.
-e Display extended information.
Stopping Processes:
Ending a process can be done in several different ways. Often, from a console-based
command, sending a CTRL + C keystroke (the default interrupt character) will exit the
command. This works when process is running in foreground mode.
If a process is running in background mode then first you would need to get its Job ID using
ps command and after that you can use kill command to kill the process as follows:
Kill: kill command would terminate first_one process. If a process ignores a regular kill
command, you can use kill -9 followed by the process ID.
Parent and Child Processes:
Each unix process has two ID numbers assigned to it: Process ID (pid) and Parent process ID
(ppid). Each user process in the system has a parent process.
Most of the commands that you run have the shell as their parent. Check ps -f example where
this command listed both process ID and parent process ID.
whoami :- It identifies the invoking user and lists the user name, terminal line, and the date
and time of login.
logname :- to confirm your login name
Precautions:
1. Make sure that telnet server is powered ON and telnet service is running on the
server.
2. Note down the IP Address of the server machine before login remotely.
3. Make sure that you are having the username and password created on the server
machine.
Conclusion:
1. Pipes can be used to connect different processes and commands.
2. Multiple processes can be managed; foreground, background and
running processes can be listed with different process related
commands.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Experiment No-11
Name of the experiment: Batch commands, kill, ps, who, sleep. Printing commands, grep,
fgrep, find, sort, cal, banner, touch, file. File related commands ws, sat, cut, grep.
Aim: Test the Batch commands, Printing commands and File related commands.
Hardware requirements: Intel based Desktop PC
Software requirements: Linux OS
Procedure:-
Kill: The default signal for kill is TERM (which will terminate or "kill" the process). Use -l
or -L to list available signals. Particularly useful signals include HUP, INT, KILL, STOP,
CONT, and 0. Alternate signals may be specified in three ways: -9, -SIGKILL or -KILL.
Negative PID (process ID) values may be used to choose whole process groups; see the
PGID column in the output of the ps command. A PID of -1 is special; it indicates all
processes except two: the kill process itself, and init.
pwd: - pwd is an abbreviation for “print working directory”
grep :- The grep command is used to search and print specified patterns from a file.
It will display the entire line in the file, which contains string name.
finger :- It displays the login name, full name, terminal name, write status, idle time, login
time and even the office location for each user, who is currently logged in.
wc:- It counts lines, words and characters in the named files or the standard input if no names
appear.
file:- file command not only lists the name of the file but alos specifies the type of data that
the file contains. Unix reads the contents of each file and actually understands what kind of
file it is.
The metacharacter * asks the file command to ascertain the file contents of all the files in the
current directory.
cal :- It displays the entire calendar of any year from 1 A.D. upto 9999 A.D.
The cal command displays the current date as well as the calendar in which it displays the
month preceding, the current month itself and the month following the current month.
bc :- It is a programmable calculator and a rather complex calculator.
date:- It displays the system date along with time

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

umask :- A user is permitted to set his own file creation mask using the umask command. We
can determine the value of our current umask, using the umask command without any
arguments.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

These three octal digits refer to the permissions denied to the owner, group and others in the
system. Here , for the owner, zero or no permission is denied, whereas for both, the group and
others, a write permission (2) is denied
To set our own umask, we can use the umask command followed by the mask that we would
like to set. To set a generous umask of 000

chmod :- Unix provides a chmod (change mode) command that helps us to change
permissions of files that we own.
And in the permission field, r for read, w for write and x for execute.
File permissions are also assigned as numerical values from 0 to 7
Read permission -4
Write permission -2
Execute permission -1
Thus, for a file that has a permission field like –rwxrwxrwx, the permissions are said to be
777 (4+2+1) for the owner, group and others.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

adduser: - To create a user (login name) on the server (under root).


To create a user username under group groupname
passwd :- password of username for security purposes
groupadd :- To add (create) a group
sleep: The sleep command is used to delay for a specified amount of time.
Precautions:
1. Make sure that telnet server is powered ON and telnet service is running on the
server.
2. Note down the IP Address of the server machine before login remotely.
3. Make sure that you are having the username and password created on the server
machine.
Conclusion:
1. Users and groups can be added in Linux environment.
2. All users can be viewed with who command
3. Simple calculations can be done with bc command

Experiment No-12
Name of the experiment: Shell Programming: Basic of shell programming, various types of
shell, Shell Programming in bash
Aim: To understand the shell programming and programming in bash.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Hardware requirements: Intel based Desktop PC


Software requirements: Linux OS
Procedure:-
The shell provides you with an interface to the UNIX system. It gathers input from you and
executes programs based on that input. When a program finishes executing, it displays that
program's output.
A shell is an environment in which we can run our commands, programs, and shell scripts.
There are different flavors of shells, just as there are different flavours of operating systems.
Each flavour of shell has its own set of recognized commands and functions.
Shell Prompt:
The prompt, $, which is called command prompt, is issued by the shell. While the prompt is
displayed, you can type a command.
The shell reads your input after you press Enter. It determines the command you want
executed by looking at the first word of your input. A word is an unbroken set of characters.
Spaces and tabs separate words.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Shell Types:
In UNIX there are two major types of shells:
1. The Bourne shell. If you are using a Bourne-type shell, the default prompt is the $
character.
2. The C shell. If you are using a C-type shell, the default prompt is the % character.
There are again various subcategories for Bourne Shell which are listed as follows:
Bourne shell ( sh)
Korn shell ( ksh)
Bourne Again shell ( bash)
The different C-type shells follow:
C shell ( csh)
TENEX/TOPS C shell ( tcsh)
The original UNIX shell was written in the mid-1970s by Stephen R. Bourne while he was at
AT&T Bell Labs in New Jersey.
The Bourne shell was the first shell to appear on UNIX systems, thus it is referred to as "the
shell".
The Bourne shell is usually installed as /bin/sh on most versions of UNIX. For this reason, it
is the shell of choice for writing scripts to use on several different versions of UNIX.
In this tutorial, we are going to cover most of the Shell concepts based on Borne Shell.
Shell Scripts:
The basic concept of a shell script is a list of commands, which are listed in the order of
execution. A good shell script will have comments, preceded by a pound sign, #, describing
the steps.
There are conditional tests, such as value A is greater than value B, loops allowing us to go
through massive amounts of data, files to read and store data, and variables to read and store
data, and the script may include functions.
Shell scripts and functions are both interpreted. This means they are not compiled.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

We are going to write a many scripts in the next several tutorials. This would be a simple text
file in which we would put our all the commands and several other required constructs that
tell the shell environment what to do and when to do it.
Example Script:
Assume we create a test.sh script. Note all the scripts would have .sh extension. Before you
add anything else to your script, you need to alert the system that a shell script is being
started. This is done using the shebang construct.
Precautions:
1. Make sure that telnet server is powered ON and telnet service is running on the
server.
2. Note down the IP Address of the server machine before login remotely.
3. Make sure that you are having the username and password created on the server
machine.
Conclusion:
1. The shell programming varies with the different types of operating system.
2. All the shells have recognized set of functions and commands.

Experiment No-13
Name of the experiment: Conditional & looping statement, case statements
Aim: To understand the various statements such as if else, for, while etc.
Hardware requirements: Intel based Desktop PC
Software requirements: Linux OS
Procedure:-
Shell scripting supplies several ways of testing conditions and then performing specific
actions. Some examples of condition statements are the if condition, the case statement and
the test or expression statement. Conditions are also tested in the while loop and the until
loop and specific actions are repeated.
The IF condition
The simple form of the if statement consists of the if condition, a then statement followed by
commands to be executed when the if condition is true, and the IF statement (if spelled
backwards) which ends the if statement. The condition usually consists of a simple
comparison between two values, such as A=B or number=5.
It is also possible to create compound conditional statements by using one or more else if
(elif) clauses. If the first condition is false, then subsequent elif statements are checked.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

When an elif condition is found to be true, the statements following the associated then
statement are executed.
The table contains a list of operators available for use when evaluating conditional
statements:
Operator Meaning Mathematical Equivalent
-eq equal to x == y
-ge greater than or equal to x >= y
-gt greater than x>y
-le less than or equal to x <= y
-lt less than x<y
-ne not equal to x != y

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Loops
A loop provides a way to execute commands repeatedly until a condition is satisfied. The
bash shell provides several looping methods but we'll focus on the for loop and the while
loop.
for loop
The for loop executes the commands placed between the do and done statements until all
values in the value list passed to it have been processed.
while loop
while loops are another type of conditional statements that might come handy.
until loop
until loops are another type of conditional loops to perform in bash scripts.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Precautions:
1. Make sure that telnet server is powered ON and telnet service is running on the
server.
2. Note down the IP Address of the server machine before login remotely.
3. Make sure that you are having the username and password created on the server
machine.
Conclusion:
1. The if- else condition is implemented in the shell programming.
2. The looping statements are used to print the various statements.

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Experiment No-14
Name of the experiment: Parameter passing and arguments, shell variables, shell keywords.
Aim: To understand the concept of shell variables, shell keywords and how parameters are
passed.
Hardware requirements: Intel based Desktop PC
Software requirements: Linux OS
Procedure:-arameter passing and arguments
The command-line arguments $1, $2, $3,...$9 are positional parameters, with $0 pointing to
the actual command, program, shell script, or function and $1, $2, $3, ...$9 as the arguments
to the command.
Special Parameters $* and $@:
There are special parameters that allow accessing all of the command-line arguments at once.
$* and $@ both will act the same unless they are enclosed in double quotes, "". Both the
parameter specifies all command-line arguments but the "$*" special parameter takes the
entire list as one argument with spaces between and the "$@" special parameter takes the

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

entire list and separates it into separate arguments. We can write the shell script shown below
to process an unknown number of command-line arguments with either the $* or $@ special
parameters:
Precautions:
1. Make sure that telnet server is powered ON and telnet service is running on the
server.
2. Note down the IP Address of the server machine before login remotely.
3. Make sure that you are having the username and password created on the server
machine.
Conclusion:
1. The rules of shell variables are discussed.
2. The various keywords used in shell programming are implemented and the parameters
are passed in the shell script.

Experiment No-15
Name of the experiment: Vi Editor
Aim: To understand the Vi Editor.
Hardware requirements: Intel based Desktop PC
Software requirements: Linux OS
Procedure:-
Vi stands for “visual”. Like any Unix programs, vi is a power – packed editor. It cannot be
equated with the modern day word processors since it does not perform any text formatting. It
follows its own set of rules and makes no effort whatsoever to be ‘user-friendly’
vi - to start (open) vi editor
vi filename - to open file filename for editing
Vi works in three basic modes of operation :-
Command mode :- All the keys pressed by the user are interpreted to be editor commands.
To move the cursor, use the following keys :-
h or bkspc : Left
l or space bar : Right

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

k or - : Up
j or + or Enter : Down
w - moves forward a word
e - moves to last character in the word
b - moves back a word
$ - takes cursor to the end of line
L - moves cursor to the last line in the file
2w - moves forward 2 words
4$ - moves the cursor to the end of the fourth line.
Ctrl F - to move a screen forward
Ctrl B - to move one screen backward
dd - deletes current line
dw - deletes current word
x - deletes the character at the cursor position.
Insert mode: - Once vi is in the insert mode, letters typed in at the keyboard are echoed in
the editing buffer.
i - Invokes the insertion mode.
o - Invokes the insertion mode by opening a blank line below the current line.
And now we can edit the contents of the file.
Escape colon (:) mode :- vi has single line commands that are terminated with the “Enter”
key. Use following commands:
:q! - With this command, the original file will remain unaltered.
:wq - Quit and write changes to file.
Precautions:
1. Make sure that telnet server is powered ON and telnet service is running on the
server.
2. Note down the IP Address of the server machine before login remotely.
3. Make sure that you are having the username and password created on the server
machine.
Conclusion:
1. The vi editor works in three modes- command mode, insert mode and escape mode.
The commands of three modes are used i

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

Experiment 16
// WAP to illustrate Banker's Algorithm

#include<iostream>
using namespace std;

// Number of processes
const int P = 5;

// Number of resources
const int R = 3;

// Function to find the need of each process


void calculateNeed(int need[P][R], int maxm[P][R],
int allot[P][R])
{
// Calculating Need of each P
for (int i = 0 ; i < P ; i++)
for (int j = 0 ; j < R ; j++)

// Need of instance = maxm instance -


// allocated instance
need[i][j] = maxm[i][j] - allot[i][j];
}

// Function to find the system is in safe state or not


bool isSafe(int processes[], int avail[], int maxm[][R],
int allot[][R])
{
int need[P][R];

// Function to calculate need matrix


calculateNeed(need, maxm, allot);

// Mark all processes as infinish


bool finish[P] = {0};

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

// To store safe sequence


int safeSeq[P];

// Make a copy of available resources


int work[R];
for (int i = 0; i < R ; i++)
work[i] = avail[i];

// While all processes are not finished


// or system is not in safe state.
int count = 0;
while (count < P)
{
// Find a process which is not finish and
// whose needs can be satisfied with current
// work[] resources.
bool found = false;
for (int p = 0; p < P; p++)
{
// First check if a process is finished,
// if no, go for next condition
if (finish[p] == 0)
{
// Check if for all resources of
// current P need is less
// than work
int j;
for (j = 0; j < R; j++)
if (need[p][j] > work[j])
break;

// If all needs of p were satisfied.


if (j == R)
{
// Add the allocated resources of
// current P to the available/work
// resources i.e.free the resources
for (int k = 0 ; k < R ; k++)
work[k] += allot[p][k];

// Add this process to safe sequence.


safeSeq[count++] = p;

// Mark this p as finished


finish[p] = 1;

found = true;
}

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

}
}

// If we could not find a next process in safe


// sequence.
if (found == false)
{
cout << "System is not in safe state";
return false;
}
}

// If system is in safe state then


// safe sequence will be as below
cout << "System is in safe state.\nSafe"
" sequence is: ";
for (int i = 0; i < P ; i++)
cout << safeSeq[i] << " ";

return true;
}

// Driver code
int main()
{
int processes[] = {0, 1, 2, 3, 4};

// Available instances of resources


int avail[] = {3, 3, 2};

// Maximum R that can be allocated


// to processes
int maxm[][R] = {{7, 5, 3},
{3, 2, 2},
{9, 0, 2},
{2, 2, 2},
{4, 3, 3}};

// Resources allocated to processes


int allot[][R] = {{0, 1, 0},
{2, 0, 0},
{3, 0, 2},
{2, 1, 1},
{0, 0, 2}};

// Check system is in safe state or not


isSafe(processes, avail, maxm, allot);

Signature Of Faculty_____________________________
Khalsa College of Engineering and Technology, Amritsar
(Department of Computer Science & Engineering)

return 0;
}
Output:
System is in safe state.
Safe sequence is: 1 3 4 0 2

Signature Of Faculty_____________________________

You might also like