0% found this document useful (0 votes)
76 views

OS Complete File

The document provides instructions for installing Ubuntu 14.04 LTS. It discusses key features of Ubuntu 14.04 such as the Linux kernel version, included software applications, and long term support. The summary then outlines the 12 step process for installing Ubuntu, which includes writing the ISO file to a USB drive or DVD, selecting installation options, setting the hostname and user account, and rebooting once installation is complete.

Uploaded by

anup kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

OS Complete File

The document provides instructions for installing Ubuntu 14.04 LTS. It discusses key features of Ubuntu 14.04 such as the Linux kernel version, included software applications, and long term support. The summary then outlines the 12 step process for installing Ubuntu, which includes writing the ISO file to a USB drive or DVD, selecting installation options, setting the hostname and user account, and rebooting once installation is complete.

Uploaded by

anup kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 101

PRACTICAL FILE

Delhi Technical Campus,


Knowledge Park-III,Greater
Noida

Operating Systems (Linux Programming and Administration) Lab


LAB CODE: ETCS-352

SUBMITTED TO :
SUBMITTED BY :
Mr. Nitesh Singh Bhati
Ashish kumar (20318002718)
{ Asst. Professor,
rd
(B.Tech - CSE) 3 Year Dept. of Comp. Sc. Engg.}

Section-A
Operating System GGSIPU ETCS-304

INDEX

S.No NAME OF THE EXPERIMENT DATE T.SIGN


.
Introduction to Linux Commands :
A 01/03/2021
Terminal Navigation Commands

Introduction to Linux Commands :


B 01/03/2021
File Management Commands

Introduction to Linux Commands :


C 01/03/2021
System Management Commands

Write a program to implement CPU


1 01/03/2021
scheduling for first come first serve.

Write a program to implement CPU


2 08/03/2021
scheduling for Shortest job first.

Write a program to implement Priority


3 15/03/2021
Scheduling.

Write a program to implement CPU


4 22/03/2021
scheduling for Round Robin.

Write a program to implement Page


5 Replacement Techniques : LRU, 05/04/2021
FIFO, Optimal.

Write a program to implement


6 Memory Allocation Techniques : 12/04/2021
Best Fit, First Fit, Worst Fit.

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Write a program to implement


7 03/05/2021
ReadersWriter using
Semaphores.
Write a program to implement
8 10/05/2021
Banker’s Algorithm.

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

EXPERIMENT 1

INSTALLATION OF UBUNTU

Ubuntu is a complete Linux operating system, freely available with both


community and professional support. The Ubuntu community is built on
the ideas enshrined in the Ubuntu Manifesto: that software should be
available free of charge, that software tools should be usable by people
in their local language and despite any disabilities, and that people
should have the freedom to customize and alter their software in
whatever way they see fit.

1. Ubuntu will always be free of charge, and there is no extra fee for the
“enterprise edition”, we make our very best work available to everyone
on the same Free terms.
2. Ubuntu includes the very best in translations and accessibility
infrastructure that the Free Software community has to offer, to make
Ubuntu usable by as many people as possible.
3. Ubuntu is shipped in stable and regular release cycles; a new release
will be shipped every six months. Every two even years an Ubuntu long
term support (LTS) release will become available, that is supported for
5 years. The Ubuntu releases in between (known as development or
non-LTS releases) are supported for 9 month each.
4. Ubuntu is entirely committed to the principles of open source software
development; we encourage people to use open source software,
improve it and pass it on.
5. Ubuntu is suitable for both desktop and server use. The current Ubuntu
release supports Intel x86 (IBM-compatible PC), AMD64 (x86-64),
ARMv7,

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

ARMv8 (ARM64), IBM POWER8/POWER9 (ppc64el), IBM Z


zEC12/zEC13/z14
and IBM LinuxONERockhopper I+II/Emporer I+II (s390x).
6. Ubuntu includes thousands of pieces of software, starting with the Linux
kernel version 4.15 and GNOME 3.28, and covering every standard
desktop application from word processing and spreadsheet applications
to internet access applications, web server software, email software,
programming languages and tools and of course several games.

Sponsorship by Canonical

The Ubuntu Project is sponsored by Canonical Ltd


(http://www.canonical.com/). Canonical will not charge licence fees for
Ubuntu, now or at any stage in the future. Canonical’s business model
is to provide technical support and professional services related to
Ubuntu. We encourage more companies also to offer support for
Ubuntu, and will list those that do on the Support pages of this web site.

UBUNTU 14.04 LTS (TRUSTY TAHR)

Ubuntu 14.04 LTS has been released officially & code name is Trusty
Tahr. Ubuntu is the fastest growing desktop operating system
consists of Ubuntu
14.04 LTS 32-bit
and Ubuntu 14.04 LTS 64-bit.

Features of Ubuntu 14.04 LTS


• New kernel 3.13
• Python 3.4
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

• Libreoffice-4.2.3
• AppArmor with lot of new feature
• Xorg-15.01 (Display Server)
• Ubuntu Desktop – y with lot of new features
Unit
• Upstart 1.12.1
• Oxide – Oxide is a webview based on Chromium to deliver web
content. Oxide allows us to better support 3rd party developers and
applications within the Ubuntu archive by providing a fast and secure

INSTALLATION STEPS OF UBUNTU 14.04


Step 1: Write the downloaded ISO file into USB drive or in DVD and boot your
system with USB Drive
/ DVD & will get below welcome Screen.

Step 2: Click on ‘Install Ubuntu‘ Option

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Step 3: Prepare to Install Ubuntu, make sure your system has enough
free space (atleast 6.4 GB), connected to Internet & power source

Click on Continue…

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Step 4: Installation Type: You can select default option, in which data
on disk will be erased, if you want you’re customize partition table, then
select ‘Something else’ option. If you want encrypt the drive, then select
‘Encrypt the new Ubuntu installation for security‘.
In my case i am creating customize partition table by selecting
‘something else’

Step 5: Create Partitions as per your requirement. In my case i am


creating /boot – 500 MB, swap-2048 MB and / – 10240 MB.

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Click on Install Now…..

Step 6: Select your Respective Time Zone

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Step 7: Select Keyboard Layout

Click on Continue….

Step 8: Set the HostName and User Name with the password.

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Click on Continue….

Step 9: Installation Started as shown below

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Step 10: After the installation is completed, it will ask you to reboot the
Machine.

Step 11: Login prompt after installation – Use same credentials that
you have set during installation
Step 12: Screen after the Entering the Credentials

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

EXPERIMENT2
BASIC LINUX COMMANDS

LINUX, like its predecessor UNIX, is an open source operating system


kernel. Since Linux is protected under the GNU Public License, many
users have imitated and altered Linux source code. Linux programming
is compatible with C++, Perl, Java, and other programming languages.

1) Command : cat
a) To Create a New File:
Synatax : cat > filename
[lab1@lab1-Lenovo-product:~]$ cat>
one.txt Hi
Welcome to IT Lab
Engineering &
Technology Delhi
Pressing Ctrl+z to save the file [2]+ Stopped cat
>one.txt [lab1@lab1-Lenovo-product:~]$
b) To Display the Contents of the File :
Syntax : cat filename
[lab1@lab1-Lenovo-product:~]$ cat
one.txt Hi
Welcome to IT Lab
Engineering &
Technology Delhi

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

[lab1@lab1-Lenovo-product:~]$

2) Command : mkdir
Syntax :mkdir filename
[lab1@lab1-Lenovo-product:~]$ mkdir
programs [lab1@lab1-Lenovo-product:~]$ ls
a.outcollege.txt fir.sh new.txt
second.sh col1.txt coll.txt firs.sh
one pgms college2.txt file.txt
one.txt programs`
[lab1@lab1-Lenovo-product:~]$

3) Command : cd (change directory)


Syntax : cd directory name
[lab1@lab1-Lenovo-product:~]$ cd
programs [lab1@lab1-Lenovo-
product:programs]$ cd .. [lab1@lab1-
Lenovo-product:~]$ cd programs
[lab1@lab1-Lenovo-product:~programs]$
mkdirshellprogram [lab1@lab1-Lenovo-
product:~programs]$ cdshellprogram [lab1@lab1-
Lenovo-product: programs /shellprogram~]$

4) Command : pwd (Print Working Directory)


[lab1@lab1-Lenovo-product: programs /shellprogram~]$ pwd
/home/it/programs/shellprogram
[lab1@lab1-Lenovo-product: programs
/shellprogram~]$ cd [lab1@lab1-Lenovo-product:~]$
pwd
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

/home/it

5) Command : ls (List Files and Directories)


a) ls
[lab1@lab1-Lenovo-product:~]$ ls
a.outcollege2.txt coll.txt fir.sh new.txt one.txt programs
col1.txt college.txt file.txt firs.sh one pgms
second.sh
[lab1@lab1-Lenovo-product:~]$
b) ls –l : Lists Files and Directories in Long Listing
Mode [lab1@lab1-Lenovo-product:~]$ ls -l
total 112
-rwxrwxr-x 1 it it 5890 Jan 29 15:16 a.out
-rw-rw-r-- 1 it it 300 Feb 23 09:55 col1.txt
-rw-rw-r-- 1 it it 603 Feb 23 10:10
college2.txt
-rw-rw-r-- 1 it it 300 Feb 23 09:55
college.txt
-rw-rw-r-- 1 it it 0 Feb 27 12:43 coll.txt
-rw------- 1 it it 129 Feb 19 10:18 file.txt
-rw-rw-r-- 1 it it 132 Mar 6 09:50 fir.sh
-rw-rw-r-- 1 it it 222 Mar 6 10:16 firs.sh
-rw-rw-r-- 1 it it 59 Feb 23 09:47 new.txt
-rw-rw-r-- 1 it it 95 Feb 14 09:46 one
-rw-rw-r-- 1 it it 81 Apr 15 11:44 one.txt
drwxrwxr-x 4 it it 4096 Jan 29 15:45 pgms
drwxrwxr-x 3 it it 4096 Apr 15 11:59 programs
-rw-rw-r-- 1 it it 236 Mar 6 10:05 second.sh

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

[lab1@lab1-Lenovo-product:~]$
c) [lab1@lab1-Lenovo-product:~]$ ls -a
. .bashrc .emacs.d new.txt .swn .xemacs
.. col1.txt file.txt one .swo
.zshrc a.outcollege2.txt fir.sh
one.txt .swp
.bash_history college.txt firs.sh pgms .viminfo
.bash_logout coll.txt .five.sh.swp programs .viminfo.tmp
.bash_profile .emacs .gtkrc second.sh
.viminfz.tmp [lab1@lab1-Lenovo-product:~]$
d) [lab1@lab1-Lenovo-product:~]$ ls –x
a.outcol1.txt college2.txt college.txt coll.txt file.txt fir.sh
firs.sh new.txt one one.txt pgms programs
second.sh [lab1@lab1-Lenovo-product:~]$

6) Command : mv (Move)
a) mv (Move a File to Directory)
Syntax : mv SourceFileDestinationDirectory
[lab1@lab1-Lenovo-product:~]$ mv coll.txt
programs [lab1@lab1-Lenovo-product:~]$ cd
programs [lab1@lab1-Lenovo-product:~]$ ls
coll.txt shellprogram
[lab1@lab1-Lenovo-
product:~]$
b) mv (Move Contents of one File to Another File)
Syntax : mv SourceFileDestinationFile
[lab1@lab1-Lenovo-product:~]$ cat one.txt

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Hi, Welcome to IT Lab


Engineering &
Technology
[lab1@lab1-Lenovo-product:~]$ mv one.txt
new.txt [lab1@lab1-Lenovo-product:~]$ cat
new.txt
Hi, Welcome to CSE Lab
Engineering & Technology
[lab1@lab1-Lenovo-
product:~]$

7) Command : rm (Remove a File)


Syntax : rm filename
[lab1@lab1-Lenovo-product:~]$ ls
a.outcollege2.txt file.txt firs.sh one
programs
col1.txt college.txt fir.sh new.txtpgms
second.sh [lab1@lab1-Lenovo-product:~]$ rm
new.txt [lab1@lab1-Lenovo-product:~]$ ls
a.outcollege2.txt file.txt firs.sh pgms
second.sh col1.txt
college.txt fir.sh one programs
[lab1@lab1-Lenovo-product:~]$

8) Command : rmdir (Remove a Diretory)


Syntax :rmdirDirectoryname
[lab1@lab1-Lenovo-
product:~]$ ls coll.txt
shellprogram
[lab1@lab1-Lenovo-product:~]$
rmdirshellprogram [lab1@lab1-Lenovo-
product:~]$ ls

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

coll.txt
[lab1@lab1-Lenovo-product:~]$

9) Command : rm -rf (Remove a Diretory which is not Empty)


Syntax :rm–rfDirectoryname
[lab1@lab1-Lenovo-product:~]$ rm -rf
programs [lab1@lab1-Lenovo-product:~]$ ls
a.outcollege2.txt file.txt firs.sh pgms
col1.txt college.txt fir.sh one
second.sh
[lab1@lab1-Lenovo-product:~]$

10) Command : echo (Prints the Given


String) a)Syntax : echo “String”
[lab1@lab1-Lenovo-product:~]$ echo "Engineering & Technology"
Engineering & Technology
[lab1@lab1-Lenovo-
product:~]$
b)Syntax : echo –n “String” (Don’t Print a New Line)
[lab1@lab1-Lenovo-product:~]$ echo -n "College of Engineering
&Technology"
Engineering & Technology [lab1@lab1-Lenovo-product:~]$

11) Command : head (Prints required no. of lines in the File Counting
from the Beginning of the File)
Syntax : head –n filename

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

n :Number of Lines to be displayed


[lab1@lab1-Lenovo-product:~]$ cat
one.txt Welcome to College of
Engineering
Delhi
IT
Dept
Computer Practices Laboratory
[lab1@lab1-Lenovo-product:~]$ head -2
one.txt Welcome to College of Engineering
Delhi
[lab1@lab1-Lenovo-product:~]$

12) Command : tail (Prints required no. of lines in the File


Counting from the End of the File)
Syntax : tail –n filename
n :Number of Lines to be displayed
[lab1@lab1-Lenovo-product:~]$ cat
one.txt Welcome to College of
Engineering
Delhi
IT
Dept
Computer Practices Laboratory
[lab1@lab1-Lenovo-product:~]$ tail -2
one.txt IT Dept
Computer Practices
Laboratory [lab1@lab1-
Lenovo-product:~]$
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

13) Command : who (Displays the Users Who Logged into the
System) [lab1@lab1-Lenovo-product:~]$ who
csepts/2 Apr 15 13:34 (192.168.1.21)
itpts/1 Apr 15 15:10 (192.168.1.69)
[lab1@lab1-Lenovo-product:~]$
Command : who am i (Displays the Name of the Current User of
this System)
[lab1@lab1-Lenovo-product:~]$ who
am i itpts/1 Apr 15 15:10
(192.168.1.69)
[lab1@lab1-Lenovo-product:~]$

14) Command : date (Displays the Current Date and


Time) [lab1@lab1-Lenovo-product:~]$ date
Wed Feb 15 15:25:49 IST 2019
[lab1@lab1-Lenovo-product:~]$

15) Command : cal (Displays the


Calendar) [lab1@lab1-Lenovo-
product:~]$ cal
Feb 2019
Su Mo Tu We ThFrSa
1 23 4
5 6 7 8 9 10 11
12 13 14 15 16 17
18
19 20 21 22 23 24
25
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

26 27 28
16) Command : wc (Counts the No. of Chars, Bytes, lines, Chars in the
Longest Line)
[lab1@lab1-Lenovo-product:~]$ wc -m
college.txt 300 college.txt
[lab1@lab1-Lenovo-product:~]$ wc -c
college.txt 300 college.txt
[lab1@lab1-Lenovo-product:~]$ wc -l
college.txt 11 college.txt
[lab1@lab1-Lenovo-product:~]$ wc -L
college.txt 44 college.txt
[lab1@lab1-Lenovo-product:~]$

17) Command : grep (Displays a Line from the file Containing the Given
String)
Syntax :grep “String” filename
Syntax :grep–i “String” filename
i – Ignore Case of the Given String
[lab1@lab1-Lenovo-product:~]$ cat
one.txt Welcome to College of
Engineering
Delhi
IT
Dept
Computer Practices Laboratory
[lab1@lab1-Lenovo-product:~]$ grep "Rcet" one.txt
Welcome to College of Engineering

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

18) Command : Sort (Sorting the Contents of the File)


The sort command is used to order the lines of a file. Various
options can be used to choose the order as well as the field on which a
file is sorted. Without any options, the sort compares entire lines in the
file and outputs them in ASCII order (numbers first, upper case letters,
then lower case letters).
Syntax
sort filename
sort –r filename (sort in the reverse order)
Exampl
e
users.tx
t
jdoe John Doe 4/15/96
lsmith Laura Smith 3/12/96
pchen Paul Chen 1/5/96
jhsu Jake Hsu 4/17/96
sphilip Sue Phillip 4/2/96

[lab1@lab1-Lenovo-product:~]$ sort users.txt


jdoe John Doe 4/15/96
jhsu Jake Hsu 4/17/96
lsmith Laura Smith 3/12/96
pchen Paul Chen 1/5/96
sphilip Sue Phillip 4/2/96

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

19) Command :uniq (Simple Filter to remove


duplicates) uniq filters duplicate adjacent lines from
a file.
Syntax
uniq file [file.new]
Example
Consider the following file and example, in which uniq removes the 4th
line from file and places the

[lab1@lab1-Lenovo-product:~]$
cat> fi 1 2 3 6
4536
7890
7890
[lab1@lab1-Lenovo-product:~]$ uniq
filefile.new [lab1@lab1-Lenovo-
product:~]$cat file.new
1236
4536
7890

20) Command: pipes ( | - redirect the output to one command to


Another Command)
The Linux system allows you to effectively connect two
commands together. This connection is known as a pipe, and it enables
you to take the output from one command and feed it directly into the
input of another
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

command. A pipe is effected by the character |, which is placed


between the two commands.
Example
To make a pipe between the who and wc -l
commands, [lab1@lab1-Lenovo-product:~]$
who | wc –l

5 (number of users logged in the system)

The standard output from the first command is connected directly to the
standard
input of the second command.

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

EXPERIMENT 3
LINUX EDITOR

General Information:
About vi:
vi (pronounced vee-EYE, short for “visual”) provides basic text
editing capabilities. Three aspects of vi make it appealing.
1. vi is supplied with all LINUX systems.
2. vi uses a small amount of memory, which allows efficient operation
when the network is busy.
3. vi uses standard alphanumeric keys for commands.
You can use it on virtually any terminal or workstation in existence
without having to worry about unusual keyboard mappings. As a point
of interest, vi is actually a special mode of another UNIX text editor
called ex. Normally you do not need to use ex except in vi mode.
vi commands are case-sensitive, which means that upper-case
and lower-case commands are not the same command. For example, j
moves the cursor down, but J combines two lines into one line.
The word RETURN represents the action of pressing RETURN
key. ESC indicates pressing the ESCAPE key. Also, sometimes you will
see a keystroke like CTRL-F. CTRL-F means you hold down the key
marked CONTROL or CTRL, and press F. The CTRL key acts in a
manner similar to the SHIFT key.
Starting vi:
To start vi, enter:
vifilename RETURN

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Where filename is the name of the file you want to edit. If the file does
not exist, vi will create it for you. You can also start vi without giving any
filename. In this case, vi will ask for one when you quit or save your
work.
Command Mode and Input Mode:
vi has two modes,
1. command mode
2. input mode
In command mode, characters you type perform actions like
moving the cursor, cutting or copying text, or searching for some
particular text. In input mode, you type to insert or overwrite text. When
you start vi, it is in command mode.
To switch from command to input mode, press the “i” key (you do
not need to press RETURN) Vi lets you insert text beginning at the
current cursor location. To switch back to command mode, press ESC.
You can also use ESC to cancel an unfinished command in command
mode. Unfortunately, vi does not normally indicate which mode you are
in. The next exercise turns on a mode indicator. If you are uncertain
about the current mode, you can press ESC a few times. When vi
beeps, you have returned to command mode.
To Know the Current Mode:
Before you start typing text, the command below activates the
modeline indicator. You are not required to use it, but it tells you
whether you are in command or input mode.
Type:
:setshowmode RETURN
Nothing appears to change. When you are in command mode, there
is

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

no indicator, but if you enter input mode, one will appear in the bottom
right- hand corner of the window.
Line Numbers:
Many vi commands use line numbers, which simply count the
number of RETURN characters in a file. You can cut and copy text by
line number or jump to a certain line. Line numbers
can be useful when you ritive error messages during program
compilation. Frequently compilers will print the line number, so you can
use vi to jump to the appropriate line and look for the error.
Exercise to display the line numbers, enter the following command:
:set number RETURN
This command will immediately display the line numbers in the left
margin of your vi window.
Vi Commands – A Quick View:

Command Meaning

vi F ile Name Open or Create File

Vi Open New File To Be Named

vi -r File Name Recover Crashed File

view F ile Name Open File Read-Only

Edit the /etc/passwd file, setting locks and


Vipw
doing appropriate processing.

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

There are three Command


modes of Mode Insert
operation: Mode Last
Line Mode

Vi Commands – A Quick
Review Vi Commands Used To Edit Files
Positioning The Cursor:

Command Meaning

H Move left one character

J Move down one line

K Move up one line

L Move right one character

W Move right one word

W Move right one word (Past Punctuation)

B Move left one word

B Move left one word (Past Punctuation)

E Move to end of current word

H Move to top of screen

M Move to middle of screen

L Move to bottom on screen

G Go to last line of file


Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

1G Go to first line of file

21G Go to 21st line of file

Table Vi Commands to Edit Files


Appending Commands:

Command Meaning

A Append text after cursor

A Append text at line end

I Insert text before cursor

I Insert text at beginning of line

O Insert line below cursor

O Insert line above cursor

Table: Appending Commands


Example 1:
To enter input mode, press: i
Note that in the bottom right-hand corner, vi indicates that you
are in input mode. Then enter the following text, and remember to press
RETURN at the end of each line.
You can use the special keystrokes if you make a mistake. We
scrambled to strike camp. Water crashed down upon us, far too slow in
foot and hands to do it. “Oh, no,” I said. Our heavens darkened grimly.
Thunder

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

echoed overhead and shook the clouds, even the ground rumbled as
each clap loudly exploded.
Glancing back, I saw an ocean rising behind us. It just wouldn’t stop
raining. Our weathered tent was a poor shelter tonight. As a lightning
bolt flashes over the hills, we made out a small cave on the
mountainside. A safe haven, thought I.Our heavens fell down, but just
up ahead lay safety.
After entering this text, press ESC to return to command mode.
Notice that the mode line clears,
too Example 2:
Move to the line “Our heavens fell...” and press A to append text at the
end of the line. Then type (the symbol -- means a space
character):
--We crawled in, and wept. ESC
Next go to the line “in foot and hand...” and open a new line below it.
Press: o to start open mode, and observe that vi creates a new line for
text. Type: Take a step and fall. ESC
Deleting Text:

Command Meaning

X Delete Character at the cursor

X Delete character to the left of the cursor

Dw Delete word (or part of word to right of cursor)

Dd Delete line containing the cursor

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

D Delete part of line to right of cursor

Dg Delete to end of file

d1G Delete from beginning of file to cursor

:5,10d Delete lines 5 through 10

Commands to Delete Text


Examples:
Try using the cursor movement keys to place the cursor on the word
“hands.” Move the cursor onto the “s.” Press x to delete it. Now let’s
delete the word “loudly.” Move to the beginning of the word. Although
you could press x seven times to delete the word and its trailing space,
it is quicker to delete it by typing dw. Finally, remove the line “It just
wouldn’t stop raining.” Move the cursor anywhere on that line, and type
dd. The line vanishes.
Changing Text:

Command Meaning

CW Change word (or part of word) to right of


cursor
Cc Change line

C Change from cursor to end of line

Substitute string for characters from cursor


S
forward

R Replace character at cursor with one other

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

character

r Return Break line

Insert Mode Commands:

Command Meaning

J Join current line and line below

Transpose character at cursor and character


Xp
to the right

~ Change case of letter (upper or lower )

u or :u Undo previous command

Commands in Insert Mode


Copying and Pasting:

Command Meaning

Y Yank or copy line

Y Yank or copy line

P Put yanked or deleted line below current

P Same as above

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Command Meaning

:w Save changes (write buffer)

:w new file Write buffer to named file

:wq Save changes and quit Vi

:q! Quit without saving changes

Saving Changes and Quitting:

Commands to Save and Quit


Displaying and Hiding Line:

Command Meaning

:set nu Show line numbers

:set nonu Hide line numbers; setting is case sensitive

:set ic Searches should ignore case

:set noic Searches should be case sensitive

:set list Display invisible characters

Commands to Hide and Display a


Line Search and Replace:

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Command Meaning

/string Search for string

?string Search backward for string

N Find next occurrence of string in search


direction
Find previous occurrence of string in search
N
direction

:%s/old/new/g Search and replace

Commands to Search and Replace

Refresh the Screen and Including Files:

Command Meaning

Control-1 Clear (refresh) scrambled screen

:r file name Insert (read) file after cursor

:34r file name Insert file after line 34

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

1.Write a program to implement CPU scheduling for first come first


serve.

import

java.text.ParseException;

public class FCS {

static void findWaitingTime(int processes[], int


n, int bt[], int wt[]) {
wt[0] = 0;
for (int i = 1; i < n; i++) {
wt[i] = bt[i - 1] + wt[i - 1];
}
}
static void findTurnAroundTime(int processes[], int
n, int bt[], int wt[], int tat[]) {
for (int i = 0; i < n; i++) {
tat[i] = bt[i] + wt[i];
}
}
static void findavgTime(int processes[], int n, int
bt[]) { int wt[] = new int[n], tat[] = new int[n];
int total_wt = 0, total_tat = 0;
findWaitingTime(processes, n, bt, wt);
findTurnAroundTime(processes, n, bt, wt,
tat);
System.out.printf("Processes Burst time Waiting"+" time Turn
around
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

time\n");

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


total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
System.out.printf(" %d ", (i + 1));
System.out.printf(" %d ", bt[i]);
System.out.printf(" %d", wt[i]);
System.out.printf(" %d\n", tat[i]);
}
float s = (float)total_wt /(float) n;
int t = total_tat / n;
System.out.printf("Average waiting time = %f", s);
System.out.printf("\n");
System.out.printf("Average turn around time = %d ", t);
}
public static void main(String[] args) throws
ParseException { int processes[] = {1, 2, 3};
int n = processes.length;
int burst_time[] = {10, 5, 8};
findavgTime(processes, n, burst_time);
}
}

Ashish kumar (20318002718)


Operating System GGSIPU

Output
ETCS-304
Operating System GGSIPU ETCS-304

2.Write a program to implement CPU scheduling for Shortest job first.

import

java.util.*; public

class SJF {

static int[][] mat = new int[10][6];

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


{ 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++) {
int temp = mat[j][k];
mat[j][k] = mat[j + 1][k];
mat[j + 1][k] = temp;
}
}
}
}
}

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


{ int temp, val = -1;
mat[0][3] = mat[0][1] + mat[0][2];
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

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;
}
}
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++) {
int tem = mat[val][k];
mat[val][k] =
mat[i][k]; mat[i][k] =
tem;
}
}
}

public static void main(String[]


args) { int num;
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

Scanner sc = new Scanner(System.in);

System.out.println("Enter number of Process: ");


num = sc.nextInt();

System.out.println("...Enter the process


ID..."); for (int i = 0; i < num; i++) {
System.out.println("...Process " + (i + 1) +
"..."); System.out.println("Enter Process Id:
"); mat[i][0] = sc.nextInt();
System.out.println("Enter Arrival Time: ");
mat[i][1] = sc.nextInt();
System.out.println("Enter Burst Time: ");
mat[i][2] = sc.nextInt();
}

System.out.println("Before Arrange...");
System.out.println("Process ID\tArrival Time\tBurst
Time"); for (int i = 0; i < num; i++) {
System.out.printf("%d\t\t%d\t\t%d\n",mat[i][0], mat[i][1], mat[i][2]);
}

arrangeArrival(num, mat);
completionTime(num, mat);

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

System.out.println("Final Result...");
System.out.println("Process ID\tArrival Time\tBurst"
+"
Time\tWaiting Time\tTurnaround
Time"); for (int i = 0; i < num;
i++) {
System.out.printf("%d\t\t%d\t\t%d\t\t%d\t\t%d\n",
mat[i][0], mat[i][1], mat[i][2], mat[i][4], mat[i][5]);
}
sc.close();
}
}

Output
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

3. Write a program to implement Priority Scheduling.

import java.util.Scanner;

public class PS{

public static void main(String args[]) {


Scanner s = new
Scanner(System.in);

int x,n,p[],pp[],bt[],w[],t[],awt,atat,i;

p = new int[10];
pp = new
int[10]; bt =
new int[10]; w
= new int[10]; t
= new int[10];

System.out.print("Enter the number of process


: "); n = s.nextInt();
System.out.print("\n\t Enter burst time : time priorities \n");
for(i=0;i<n;i++)
{
System.out.print("\nProcess["+(i+1)+"]:"
); bt[i] = s.nextInt();
pp[i] = s.nextInt();

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

p[i]=i+1;
}
for(i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(pp[i]>pp[j])
{
x=pp[i];
pp[i]=pp[j]
; pp[j]=x;
x=bt[i];
bt[i]=bt[j];
bt[j]=x;
x=p[i];
p[i]=p[j];
p[j]=x;
}
}
}
w[0]=0;
awt=0;
t[0]=bt[0];
atat=t[0];
for(i=1;i<n;i+
+)

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

{
w[i]=t[i-1];
awt+=w[i];
t[i]=w[i]+bt[i];
atat+=t[i];
}

System.out.print("\n\nProcess \t Burst Time \t Wait Time \t Turn


Around Time Priority \n");
for(i=0;i<n;i++)
System.out.print("\n "+p[i]+"\t\t "+bt[i]+"\t\t "+w[i]+"\t\t "+t[i]+"\t\t
"+pp[i]+"\n");
awt/=n;
atat/=n;
System.out.print("\n Average Wait Time : "+awt);
System.out.print("\n Average Turn Around Time :
"+atat);

}
}

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Output

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

4. Write a program to implement CPU scheduling for Round Robin.

public class RR
{
static void findWaitingTime(int processes[], int
n, int bt[], int wt[], int quantum)
{
int rem_bt[] = new
int[n]; for (int i = 0 ; i < n
; i++)
rem_bt[i] = bt[i];

int t = 0;
while(true
)
{ boolean done =
true; for (int i = 0 ; i <
n; i++)
{
if (rem_bt[i] > 0)
{
done = false; // There is a pending process

if (rem_bt[i] > quantum)


{
t += quantum;
rem_bt[i] -=
quantum;
}
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

else
{
t = t + rem_bt[i];

wt[i] = t - bt[i];
rem_bt[i] = 0;
}
}
}
if (done ==
true) break;
}
}
static void findTurnAroundTime(int processes[], int
n, int bt[], int wt[], int tat[])
{
for (int i = 0; i < n ;
i++) tat[i] = bt[i] +
wt[i];
}
static void findavgTime(int processes[], int n, int bt[], int quantum)
{
int wt[] = new int[n], tat[] = new
int[n]; int total_wt = 0, total_tat = 0;
findWaitingTime(processes, n, bt, wt, quantum);

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

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


System.out.println("Processes " + " Burst time " +
" Waiting time " + " Turn around time");

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


{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
System.out.println(" " + (i+1) + " " + bt[i] +"
" + wt[i] +" " + tat[i]);
}
System.out.println("Average waiting time = "
+ (float)total_wt / (float)n);
System.out.println("Average turn around time = "
+ (float)total_tat / (float)n);
}

public static void main(String[] args)


{
int processes[] = { 1, 2,
3}; int n =
processes.length;
int burst_time[] = {10, 5,
8}; int quantum = 2;
findavgTime(processes, n, burst_time, quantum);

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

}
}

Output
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

5. Write a program to implement Page Replacement Techniques :


LRU, FIFO,
Optimal

import java.io.*;
public class PageReplacementTechniques {
BufferedReader input=new BufferedReader(new
InputStreamReader(System.in));
int n, page[], f, frames[], faults, count;
double rate;

void PageReplacementTechniques() throws


IOException{ System.out.println("Enter
number of pages");
n=Integer.parseInt(input.readLine());
page=new int[n];
System.out.println("Enter number of page frames");
f=Integer.parseInt(input.readLine());
frames=new
int[f]; count=1;

void
reset()
{
int j;
for(j=0;j<f;j++
)

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

frames[j]=0
; faults=0;
count=1;
}

void read() throws IOException


{
int i;
System.out.println("Enter the pages");
for(i=0;i<n;i++)
{
System.out.println("Enter page number "+(i+1));
page[i]=Integer.parseInt(input.readLine());
}
for(i=0;i<f;i++)
frames[i]=-1;
}

void
fifo()
{
int i,j,k=0;
reset();
boolean
found=false;
for(i=0;i<n;i++)
{

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

for(j=0;j<f;j++)
{
if(page[i]==frames[j])
found=true;
}
if(found==false)
{
frames[k]=page[i
]; if(k==f-1)
k=0;
else
k++;
faults++;

}
display();
found=fals
e;
}
System.out.println("Number of page faults = "+faults);
System.out.println("Fault rate = "+(faults*1.0/n));
}

void
lru()
{
int i,j,duration[],max;

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

reset();
duration=new int[f];
boolean
found=false;
for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
duration[j]++
; for(j=0;j<f;j++)
{
if(page[i]==frames[j])
{
found=true;
duration[j]=0
;
}
}
if(found==false)
{
max=0;
for(j=0;j<f;j++
)
{
if(duration[j]>duration[max]
) max=j;
}
frames[max]=page[
i]; duration[max]=0;
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

faults++;
}
display();
found=fals
e;
}
System.out.println("Number of page faults = "+faults);
System.out.println("Fault rate = "+(faults*1.0/n));
}

void
opt()
{
int i,j=0,k,duration[],max,flag[];
reset();
duration=new int[f];
flag=new int[f];
boolean
found=false;

for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
{
flag[j]=0;
duration[j]=n
;
}
for(k=i+1;k<n;k++)
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

{
for(j=0;j<f;j++)
if(page[k]==frames[j]&&flag[j]==0)
{
duration[j]=k
; flag[j]=1;
}
}
for(j=0;j<f;j++)
if(page[i]==frames[j])
found=true
; if(found==false)
{
max=0;
for(j=0;j<f;j++
)
{
if(duration[j]>duration[max]
) max=j;
if(frames[j]<0)
{
max=j
;
break
;
}
}
frames[max]=page[i];
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

faults++;
}
display();
found=fals
e;
}
System.out.println("Number of page faults = "+faults);
System.out.println("Fault rate = "+(faults*1.0/n));
}

void display()
{
int i;
System.out.print("Page frame "+count+"
:"); for(i=0;i<f;i++)
{
if(frames[i]==-1)
System.out.print(" -");
else
System.out.print(" "+frames[i]);
}
System.out.print("\n")
; count++;
}

public static void main(String[] args) throws IOException{

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

int option;
String
choice;
PageReplacementTechniques p=new
PageReplacementTechniques(); p.read();
BufferedReader input=new BufferedReader(new
InputStreamReader(System.in));
do
{
System.out.println("Menu");
System.out.println("1. FIFO");
System.out.println("2. LRU");
System.out.println("3. OPT");
System.out.println("Enter option");
option=Integer.parseInt(input.readLine());
switch(option)
{
case 1: p.fifo();
break;
case 2: p.lru();
break;
case 3: p.opt();
break;
default: System.out.println("Invalid input");
}
System.out.println("Press Y to continue");

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

choice=input.readLine();
}
while(choice.compareToIgnoreCase("y")==
0 );

Output
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

6. Write a program to implement Memory Allocation Techniques :


Best Fir, First Fit, Worst Fit.

import java.io.*;
public class MemoryAllocationTechniques {
BufferedReader input=new BufferedReader(new
InputStreamReader(System.in));
int n, page[], f, frames[], faults, count;
double rate;

static void bestFit(int blockSize[], int m, int processSize[], int n)


{
int allocation[] = new int[n];

for (int i = 0; i < allocation.length;


i++) allocation[i] = -1;

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


{
int bestIdx = -1;
for (int j=0; j<m; j++)
{
if (blockSize[j] >= processSize[i])
{
if (bestIdx == -1)

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

bestIdx = j;
else if (blockSize[bestIdx] >
blockSize[j]) bestIdx = j;
}
}

if (bestIdx != -1)
{
allocation[i] = bestIdx;

blockSize[bestIdx] -= processSize[i];
}
}

System.out.println("\nProcess No.\tProcess Size\tBlock


no."); for (int i = 0; i < n; i++)
{
System.out.print(" " + (i+1) + "\t\t" + processSize[i] +
"\t\t"); if (allocation[i] != -1)
System.out.print(allocation[i] +
1); else
System.out.print("Not
Allocated"); System.out.println();
}
}

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

static void firstFit(int blockSize[], int m, int processSize[], int n)


{
int allocation[] = new int[n];

for (int i = 0; i < allocation.length;


i++) allocation[i] = -1;

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


{
for (int j = 0; j < m; j++)
{
if (blockSize[j] >= processSize[i])
{
allocation[i] = j;

blockSize[j] -= processSize[i];

break;
}
}
}

System.out.println("\nProcess No.\tProcess Size\tBlock


no."); for (int i = 0; i < n; i++)
{

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

System.out.print(" " + (i+1) + "\t\t" +


processSize[i] + "\t\t");
if (allocation[i] != -1)
System.out.print(allocation[i] +
1);
else
System.out.print("Not
Allocated"); System.out.println();
}
}

static void worstFit(int blockSize[], int m, int processSize[], int n)


{
int allocation[] = new int[n];

for (int i = 0; i < allocation.length;


i++) allocation[i] = -1;

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


{
int wstIdx = -1;
for (int j=0; j<m; j++)
{
if (blockSize[j] >= processSize[i])
{
if (wstIdx == -1)

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

wstIdx = j;
else if (blockSize[wstIdx] <
blockSize[j]) wstIdx = j;
}
}

if (wstIdx != -1)
{
allocation[i] = wstIdx;
blockSize[wstIdx] -=
processSize[i];
}
}

System.out.println("\nProcess No.\tProcess Size\tBlock


no."); for (int i = 0; i < n; i++)
{
System.out.print(" " + (i+1) + "\t\t" + processSize[i] +
"\t\t"); if (allocation[i] != -1)
System.out.print(allocation[i] +
1); else
System.out.print("Not
Allocated"); System.out.println();
}
}

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

public static void main(String[] args) throws


IOException{ int option;
String choice;
MemoryAllocationTechniques p=new MemoryAllocationTechniques();
BufferedReader input=new BufferedReader(new
InputStreamReader(System.in));
do
{
System.out.println("blocks = {120, 850, 150, 400, 900} \n
Processes = {183, 512, 96, 386} ");
System.out.println("1. Best Fit");
System.out.println("2. First Fit");
System.out.println("3. Worst Fit");
System.out.println("Enter option");
option=Integer.parseInt(input.readLine());
switch(option)
{
case 1:
int blockSize1[] = {120, 850, 150, 400, 900};
int processSize1[] = {183, 512, 96,
386}; int m1 = blockSize1.length;
int n1 = processSize1.length;
bestFit(blockSize1, m1, processSize1, n1);

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

break;
case
2:
int blockSize2[] = {120, 850, 150, 400, 900};
int processSize2[] = {183, 512, 96,
386}; int m2 = blockSize2.length;
int n2 = processSize2.length;
firstFit(blockSize2, m2, processSize2,
n2); break;
case 3:
int blockSize3[] = {120, 850, 150, 400, 900};
int processSize3[] = {183, 512, 96,
386}; int m3 = blockSize3.length;
int n3 = processSize3.length;
worstFit(blockSize3, m3, processSize3,
n3); break;
default: System.out.println("Invalid input");
}
System.out.println("Press Y to continue");
choice=input.readLine();
}
while(choice.compareToIgnoreCase("y")==0);

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Outpu
t

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

7. Write a program to implement ReadersWriter using Semaphores

import java.util.concurrent.Semaphore;
class RWP {

static Semaphore readLock = new


Semaphore(1); static Semaphore writeLock =
new Semaphore(1); static int readCount = 0;
static class Read implements
Runnable { @Override
public void run()
{ try {
readLock.acquire
(); readCount++;
if (readCount == 1) {
writeLock.acquire(
);
}
readLock.release();
System.out.println("Thread
"+Thread.currentThread().getName() + " is READING");
Thread.sleep(1500);
System.out.println("Thread
"+Thread.currentThread().getName() + " has FINISHED READING");
readLock.acquire
(); readCount--;

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

if(readCount == 0) {
writeLock.release
();
}
readLock.release();
} catch (InterruptedException e) {
System.out.println(e.getMessage()
);
}
}
}

static class Write implements Runnable {


@Override
public void run()
{ try {
writeLock.acquire();
System.out.println("Thread
"+Thread.currentThread().getName() + " is WRITING");
Thread.sleep(2500);
System.out.println("Thread
"+Thread.currentThread().getName() + " has finished WRITING");
writeLock.release();
} catch (InterruptedException e) {
System.out.println(e.getMessage()
);
}
}
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

public static void main(String[] args) throws Exception


{ Read read = new Read();
Write write = new Write();
Thread t1 = new
Thread(read);
t1.setName("thread1");
Thread t2 = new
Thread(read);
t2.setName("thread2");
Thread t3 = new
Thread(write);
t3.setName("thread3");
Thread t4 = new
Thread(read);
t4.setName("thread4");
t1.start();
t3.start();
t2.start();
t4.start();
}
}
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

Output

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

8. Write a program to implement Banker’s Algorithm.


import java.util.*;

class BA
{
static int P = 5;
static int R = 3;
static void calculateNeed(int need[][], int
maxm[][], int allot[][])
{
for (int i = 0 ; i < P ;
i++) for (int j = 0 ; j <
R ; j++)
need[i][j] = maxm[i][j] - allot[i][j];
}

static boolean isSafe(int processes[], int avail[], int


maxm[][], int allot[][])
{
int [][]need = new int[P][R];
calculateNeed(need, maxm,
allot); boolean []finish = new
boolean[P]; int []safeSeq = new
int[P];
int []work = new
int[R]; for (int i = 0; i
< R ; i++)
work[i] = avail[i];
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

int count = 0;
while (count <
P)
{
boolean found = false;
for (int p = 0; p < P;
p++)
{
if (finish[p] == false)
{
int j;
for (j = 0; j < R; j++)
if (need[p][j] >
work[j]) break;
if (j == R)
{
for (int k = 0 ; k < R ;
k++) work[k] +=
allot[p][k];
safeSeq[count++] =
p; finish[p] = true;
found = true;
}
}
}
if (found == false)
{
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304

System.out.print("System is not in safe state");


return false;
}
}
System.out.print("System is in safe state.\nSafe"
+" sequence is: ");
for (int i = 0; i < P ;
i++)
System.out.print(safeSeq[i] + " ");

return true;
}
public static void main(String[] args)
{
int processes[] = {0, 1, 2, 3, 4};
int avail[] = {3, 3, 2};
int maxm[][] = {{7, 5, 3}, {3, 2, 2},{9, 0, 2}, {2, 2, 2}, {4, 3, 3}};
int allot[][] = {{0, 1, 0}, {2, 0, 0}, {3, 0, 2}, {2, 1, 1}, {0, 0, 2}};

isSafe(processes, avail, maxm, allot);


}
}

Ashish kumar (20318002718)


Operating System GGSIPU ETCS-304

Outpu
t

Ashish kumar (20318002718)

You might also like