0% found this document useful (0 votes)
236 views58 pages

Lab Manual: Oriental College of Technology, Bhopal

The document provides information about a lab manual for an Operating Systems course at Oriental College of Technology in Bhopal, India. It includes an index of 12 experiments covering topics like CPU scheduling algorithms, process scheduling mechanisms, and inter-process communication problems. The experiments sections provide the aim, theory, and commands related to each topic. The document also provides descriptions of common Linux directory structures and file/directory handling commands.

Uploaded by

Gaurav Chopra
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)
236 views58 pages

Lab Manual: Oriental College of Technology, Bhopal

The document provides information about a lab manual for an Operating Systems course at Oriental College of Technology in Bhopal, India. It includes an index of 12 experiments covering topics like CPU scheduling algorithms, process scheduling mechanisms, and inter-process communication problems. The experiments sections provide the aim, theory, and commands related to each topic. The document also provides descriptions of common Linux directory structures and file/directory handling commands.

Uploaded by

Gaurav Chopra
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/ 58

ORIENTAL COLLEGE OF TECHNOLOGY,

BHOPAL

DEPARTMENT OF INFORMATION TECHNOLOGY

LAB MANUAL

Programme : BE

Semester : IV

Course Code : IT-4003

Subject Name : OPERATING SYSTEM

Prepared By: Approved By:


Prof.Shadab Pasha Prof . Roopali Soni
INDEX PAGE
S. Objective Experiment Date of
No. Held Submission
1 To study the difference between Microsoft windows
and Linux Operating System.

2 To study the Execution of various file/directory


handling commands.

3 To study the various File Access Permission and


different types users in LINUX

4 To write a C program to implement the CPU


scheduling algorithm for FIRST COME FIRST
SERVE.

5 Write a C program to implement the various process


scheduling mechanisms such as SJF Scheduling.

6 Program to implement non pre-emptive Priority


CPU Scheduling algorithm.

7 To write a C program to implement the CPU


scheduling algorithm of Shortest Remaining Time
First.

8 Program to implement Pre-emptive Priority CPU


Scheduling algorithm
9 Write a C program to implement the various process
scheduling mechanisms such as Round Robin
Scheduling.

10 Program to implement classical inter process


communication problem (Dining
Philosophers).

11 Program to implement classical inter process


communication problem (producer consumer).

12 Program to implement classical inter process


communication problem (Reader Writers).
EXPERIMENT – 1

AIM: To study the difference between Microsoft windows and Linux Operating System.

THEORY:
EXPERIMENT – 2

AIM: To study the Execution of various file/directory handling commands.

THEORY:

The Linux file system is the structure in which all the information on your computer is stored. Files
are organized within a hierarchy of directories. Each directory can contain files, as well as other
directories.

If you were to map out the files and directories in Linux, it would look like an upside-down tree. At
the top is the root directory, which is represented by a single slash ( / ). Below that is a set of common
directories in the Linux system, such as bin, dev, home, lib , and tmp , to name a few. Each of those
directories, as well as directories added to the root, can contain subdirectories.

Some of the Linux directories that may interest you include the following:

 /bin - Contains common Linux user commands, such as ls, sort , date , and chmod .
 /boot - Has the bootable Linux kernel and boot loader configuration files (GRUB).
 /dev - Contains files representing access points to devices on your systems. These include
terminal devices ( tty* ), floppy disks ( fd* ), hard disks ( hd* or sc* ), RAM ( ram* ), and
CD-ROM ( cd* ). (Applications normally access these devices directly through the device
files, but end users rarely access them directly.)
 /etc - Contains administrative configuration files.
 /home - Contains directories assigned to each user with a login account.
 /media - Provides a location for mounting devices, such as remote file systems and removable
media (with directory names of cdrom , floppy , and so on). In Fedora and RHEL, many
removable media are mounted automatically in this directory when the media is inserted (CD
or DVD) or connected (USB pen drives or cameras ).
 /proc - Provides a mechanism for the kernel to send information to processes.
 /root - Represents the root user's home directory.
 /sbin - Contains administrative commands and daemon processes.
 /sys - A /proc -like file system, added with the Linux 2.6 kernel and intended to contain files
for getting hardware status and reflecting the system's device tree as it is seen by the kernel. It
pulls many of its functions from /proc .
 /tmp - Contains temporary files used by applications.
 /usr - Contains user documentation, games , graphical files (X11), libraries (lib), and a variety
of other user and administrative commands and files.
 /var - Contains directories of data used by various applications. In particular, this is where you
would place files that you share as an FTP server ( /var/ftp ) or a Web server ( /var/www ). It
also contains all system log files ( /var/log ). In time, FTP, HTTP, and similar services will
move to the /srv directory to adhere to the Linux Standards Base (
www.freestandards.org/spec ).

COMMAND :

1.Date Command :

This command is used to display the current data and time.

Syntax :

$date
$date +%ch

Options :

a = Abbrevated weekday.
A = Full weekday.
b = Abbrevated month.
B = Full month.
c = Current day and time.
C = Display the century as a decimal number.
d = Day of the month.
D = Day in „mm/dd/yy‟ format
h = Abbrevated month day.
H = Display the hour.
L = Day of the year.
m = Month of the year.
M = Minute.
P = Display AM or PM
S = Seconds
T = HH:MM:SS format
u = Week of the year.
y = Display the year in 2 digit.
Y = Display the full year.
Z = Time zone .

To change the format :


Syntax :
$date „+%H-%M-%S‟

2.Calender Command :

This command is used to display the calendar of the year or the particular month of
calendar year.

Syntax :
a.$cal <year>
b.$cal <month> <year>

Here the first syntax gives the entire calendar for given year & the second Syntax gives
the calendar of reserved month of that year.

3.Echo Command :

This command is used to print the arguments on the screen .

Syntax : $echo <text>

4.Banner Command :

It is used to display the arguments in „#‟ symbol .

Syntax : $banner <arguments>

5.’who’ Command :

It is used to display who are the users connected to our computer currently.

Syntax : $who – option‟s

Options : -

H–Display the output with headers.


b–Display the last booting date or time or when the system was lastely rebooted.

6.’who am i’ Command :

Display the details of the current working directory.

Syntax : $who am i
9.’CLEAR’ Command :

It is used to clear the screen.

Syntax : $clear

10.’MAN’ Command :

It help us to know about the particular command and its options & working. It is like
„help‟ command in windows .

Syntax : $man <command name>

11.LIST Command :

It is used to list all the contents in the current working directory.

Syntax : $ ls – options <arguments>


If the command does not contain any argument means it is working in the Current directory.

Options :
a– used to list all the files including the hidden files.
c– list all the files columnwise.
d- list all the directories.
m- list the files separated by commas.
p- list files include „/‟ to all the directories.
r- list the files in reverse alphabetical order.
f- list the files based on the list modification date.
x-list in column wise sorted order.

DIRECTORY RELATED COMMANDS :

1.Present Working Directory Command :

To print the complete path of the current working directory.

Syntax : $pwd

2.MKDIR Command :

To create or make a new directory in a current directory .

Syntax : $mkdir <directory name>

3.CD Command :

To change or move the directory to the mentioned directory .

Syntax : $cd <directory name.

4.RMDIR Command :
To remove a directory in the current directory & not the current directory itself.
Syntax : $rmdir <directory name>

FILE RELATED COMMANDS :

1.CREATE A FILE :

To create a new file in the current directory we use CAT command.

Syntax : $cat > <filename.


The > symbol is redirectory we use cat command.

2.DISPLAY A FILE :

To display the content of file mentioned we use CAT command without „>‟ operator.

Syntax : $cat <filename.

Options –s = to neglect the warning /error message.

3.COPYING CONTENTS :

To copy the content of one file with another. If file doesnot exist, a new file is created
and if the file exists with some data then it is overwritten.

Syntax : $ cat <filename source> >> <destination filename>


$ cat <source filename> >> <destination filename> it is avoid overwriting.

Options :

-n content of file with numbers included with blank lines.

Syntax :
$cat –n <filename>

4.SORTING A FILE :
To sort the contents in alphabetical order in reverse order.

Syntax :
$sort <filename >

Option : $ sort –r <filename>

5.COPYING CONTENTS FROM ONE FILE TO ANOTHER :


To copy the contents from source to destination file . so that both contents are same.

Syntax :
$cp <source filename> <destination filename>
$cp <source filename path > <destination filename path>

6.MOVE Command :
To completely move the contents from source file to destination file and to remove the
source file.
Syntax :
$ mv <source filename> <destination filename>

7.REMOVE Command :
To permanently remove the file we use this command .

Syntax :
$rm <filename>

8.WORD Command :
To list the content count of no of lines , words, characters .
Syntax :

$wc<filename>

Options :
-c – to display no of characters.
-l – to display only the lines.
-w – to display the no of words.

FILTERS AND PIPES

HEAD : It is used to display the top ten lines of file.

Syntax: $head<filename>

TAIL : This command is used to display the last ten lines of file.

Syntax: $tail<filename>

PAGE : This command shows the page by page a screen full of information is displayed after
which the page command displays a prompt and passes for the user to strike the enter key to
continue scrolling.

Syntax: $ls –a\p

MORE : It also displays the file page by page .To continue scrolling with more command ,
press the space bar key.

Syntax: $more<filename>

SORT : This command is used to sort the data in some order.

Syntax: $sort<filename>

PIPE : It is a mechanism by which the output of one command can be channelled into the
input of another command.

Syntax: $who | wc-l


TR :The tr filter is used to translate one set of characters from the standard inputs to another.

Syntax: $tr “[a-z]” “[A-Z]”

INPUT :

Valid Input-

Valid Output-

Invalid Input-

Invalid Output-

VIVA QUESTION :

1. Which command is used to display the top of the file?


2. Which command is used to remove a directory?
3. Which of the following commands is used to display the directory attributes rather than its
contents?
4. Which command is used to concatenate all files beginning with the string 'emp' and followed
by a non-numeric characters?
5. Which command is used to delete all files in the current directory and all its sub-directories?

EXPERIMENT – 3

AIM:

To study the various File Acess Permission and different types of users in LINUX
THEORY:

File ownership is an important component of LINUX that provides a secure method for storing files.
Every file and directory in LINUX has the following attributes:

 Owner permissions: The owner's permissions determine what actions the owner of the file
can perform on the file.
 Group permissions: The group's permissions determine what actions a user, who is a
member of the group that a file belongs to, can perform on the file.
 Other (world) permissions: The permissions for others indicate what action all other users
can perform on the file.

The permissions can be granted or denied to these three classes of users.

FILE AND DIRECTOEY ACCESS MODES:

1. Read:Grants the capability to read ie. view the contents of the file and directory .

2. Write:Grants the capability to modify, or remove the content of the file and directory .

3. Execute:User with execute permissions can run a file as a program.But in case of directory , it
does not mean anything only traverse permission .

They are represented as :

r W X R __ X r __ X
__
File Permission for the owner Permission of the Permission for the
Type of file group to which the rest of users
files belongs

CHANGING PERMISSIONS:

To change file or directory permissions, you use the chmod (change mode) command. There
are two ways to use chmod: symbolic mode and absolute mode.

Using chmod in symbolic mode:

The easiest way for a beginner to modify file or directory permissions is to use the symbolic
mode. With symbolic permissions you can add, delete, or specify the permission set you want
by using the operators in the following table.

Chmod operator Description


Adds the designated permission(s) to a file or
+
directory.
Removes the designated permission(s) from a file or
-
directory.
= Sets the designated permission(s).

u user

g group

o other

a all

r read

w write

x execute

Using chmod with Absolute Permissions:

The second way to modify permissions with the chmod command is to use a number to
specify each set of permissions for the file.

Each permission is assigned a value, as the following table shows, and the total of each set of
permissions provides a number for that set.

Number Octal Permission Representation Ref

0 No permission ---
1 Execute permission --x
2 Write permission -w-
Execute and write permission: 1 (execute) + 2
3 -wx
(write) = 3
4 Read permission r--
Read and execute permission: 4 (read) + 1
5 r-x
(execute) = 5
6 Read and write permission: 4 (read) + 2 (write) = 6 rw-
All permissions: 4 (read) + 2 (write) + 1 (execute)
7 rw
=7

CHANGING OWNERS AND GROUPS:

While creating an account on Unix, it assigns a owner ID and a group ID to each user. All the
permissions mentioned above are also assigned based on Owner and Groups.
Two commands are available to change the owner and the group of files:

1. chown: The chown command stands for "change owner" and is used to change the
owner of a file.
2. chgrp: The chgrp command stands for "change group" and is used to change the
group of a file.

Changing ownership:

The chown command changes the ownership of a file.

syntax :

$ chown user filelist

The value of user can be either the name of a user on the system or the user id (uid) of a user
on the system.

1.1 Changing Group Ownership:

The chrgp command changes the group ownership of a file.

syntax :

$ chgrp group filelist

INPUT:

Valid input: Create a directory and put some files into it. Now play about with removing
various permissions from yourself on that directory and see what you can and can't do.

Valid output:

Invalid input:

chmode u + g file1
EXPERIMENT – 4

AIM: To write a C program to implement the CPU scheduling algorithm for FIRST COME
FIRST SERVE.

THEORY:

FCFS:
CPU scheduler will decide which process should be given the CPU for its execution.For this
it use different algorithm to choose among the process. one among that algorithm is fcfs
algorithm.
In this algorithm the process which arrive first is given the cpu after finishing its request only
it will allow cpu to execute other process.

ALGORITHM:

Step 1: Start the process


Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU
burst time
Step 4: Set the waiting of the first process as ‘0’ and its burst time as its turn around
time
Step 5: for each process in the Ready Q calculate
(a) Waiting time for process(n)= waiting time of process (n-1) + Burst time of
process(n-1)
(b) Turn around time for Process(n)= waiting time of Process(n)+ Burst time
for process(n)
Step 6: Calculate
(a) Average waiting time = Total waiting Time / Number of process
(b) Average Turnaround time = Total Turnaround Time / Number of process
Step 7: Stop the process
PROGRAM:
INPUT:

OUTPUT:
EXPERIMENT – 5
AIM: Write a C program to implement Shortest Job First Algorithm.

THEORY:

SJF:
This algorithm associates with each process the length of the process's next CPU burst.
When the CPU is available, it is assigned to the process that has the smallest next CPU burst.
If the next CPU bursts of two processes are the same, FCFS scheduling is used.

2 .ALGORITHM:

Step 1: Start the process


Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Start the Ready Q according the shortest Burst time by sorting according to lowest to
highest burst time.
Step 5: Set the waiting time of the first process as ‘0’ and its turnaround time as its burst time.
Step 6: For each process in the ready queue, calculate
(a) Waiting time for process(n)= waiting time of process (n-1) + Burst time of
process(n-1)
(b) Turn around time for Process(n)= waiting time of Process(n)+ Burst time for
process(n)
Step 7: Calculate
(a) Average waiting time = Total waiting Time / Number of process
(b) Average Turnaround time = Total Turnaround Time / Number of process
Step 8: Stop the process
PROGRAM:
INPUT:

OUTPUT:

EXPERIMENT – 6
AIM: To write a C program to implement Non Preemptive Priority Scheduling Algorithm.

THEORY:

PREEMPTIVE PRIORITY:
 Priority scheduling is a non-preemptive algorithm and one of the most common
scheduling algorithms in batch systems.
 Each process is assigned a priority. Process with highest priority is to be executed first
and so on.
 Processes with same priority are executed on first come first served basis.
 Priority can be decided based on memory requirements, time requirements or any
other resource requirement.

Wait time of each process is as follows −

Process Wait Time : Service Time - Arrival Time

P0 9-0=9

P1 6-1=5

P2 14 - 2 = 12

P3 0-0=0

ALGORITHM:

Step:1 Assign the process to ready queue.


Step:2 Assign the process to the CPU according to the priority, higher priority process will
get the CPU first than lower priority process.

Step:3 If two processes have similar priority then use FCFS.

Step:4 If in FCFS both arrival times are same then, SJF is used to break the tie.

Step:5 Repeat the step 1 to 4 until ready queue is empty. Step 6: Calculate Waiting time and
Turnaround time of individual Process.

PROGRAM:
INPUT:
OUTPUT:

EXPERIMENT – 7

AIM: To write a C program to implement the CPU scheduling algorithm of Shortest


Remaining Time First.
THEORY:

SHORTEST REMAINING TIME FIRST:


In this scheduling algorithm, the process with the smallest amount of time remaining until
completion is selected to execute. Since the currently executing process is the one with the
shortest amount of time remaining by definition, and since that time should only reduce as
execution progresses, processes will always run until they complete or a new process is added
that requires a smaller amount of time.

ALGORITHM:

1- Traverse until all process gets completely


executed.
a) Find process with minimum remaining time at
every single time lap.
b) Reduce its time by 1.
c) Check if its remaining time becomes 0
d) Increment the counter of process completion.
e) Completion time of current process =
current_time +1;
e) Calculate waiting time for each completed
process.
wt[i]= Completion time - arrival_time-burst_time
f)Increment time lap by one.
2- Find turnaround time (waiting_time+burst_time).

PROGRAM:
INPUT:
OUTPUT:

EXPERIMENT – 8

AIM: Program to implement Preemptive Priority CPU Scheduling algorithm.

THEORY:

Preemptive Priority scheduling:


Each process in the system if given a priority, then the scheduling must be done according to
the priority of each process. A higher priority job should get CPU whereas lower priority job
can be made to wait. Priority scheduling is necessarily a form of preemptive scheduling
where priority is the basic of preemption.

Example:
Let us consider a set of processes P1, P2, P3 having priorities ranging from 1 to 3. Let us
assume that 1 is the highest priority whereas 3 is the least priority. Let us also assume that p1
arrive first and P3 arrives in the last.
P1 P2 P3 P2 P1

0 1 2 4 8 17

ALGORITHM:

Step 1: Assign the process to ready queue.

Step 2: Assign the process to the CPU according to the arrival time, lower arrival time
process will get the CPU first than higher arrival time process.

Step 3: Assign the process to the CPU according to the priority, higher priority process will
get the CPU first than lower priority process while comparing with the arrival time.

Step 3: If two processes have similar priority then FCFS is used to break the tie.

Step 4: Repeat the step 1 to 3 until ready queue is empty.

Step 5: Calculate Waiting time and Turnaround time of individual Process. Step 6: Calculate
Average waiting time and Average Turnaround time.

PROGRAM:
INPUT:
OUPUT:

EXPERIMENT – 9

AIM: Write a C program to implement the CPU scheduling mechanisms such as Round
Robin Scheduling.

RR :
The round-robin (RR) scheduling algorithm is designed especially for time-sharing systems.
It is similar to FCFS scheduling . A small unit of time, called a time quantum or time slice, is
defined. A time quantum is generally from 10 to 100 milliseconds. The ready queue is treated
as a circular queue.

3.ALGORITHM:

Step 1: Start the process


Step 2: Accept the number of processes in the ready Queue and time quantum (or)
time slice
Step 3: For each process in the ready Q, assign the process id and accept the CPU
burst time
Step 4: Calculate the no. of time slices for each process where
No. of time slice for process(n) = burst time process(n)/time slice
Step 5: If the burst time is less than the time slice then the no. of time slices =1.
Step 6: Consider the ready queue is a circular Q, calculate
(a) Waiting time for process(n) = waiting time of process(n-1)+ burst time of
process(n-1 ) + the time difference in getting the CPU from process(n-1)
(b) Turn around time for process(n) = waiting time of process(n) + burst time
of process(n)+ the time difference in getting CPU from process(n).
Step 7: Calculate
(c) Average waiting time = Total waiting Time / Number of process
(d) Average Turnaround time = Total Turnaround Time / Number of process
Step 8: Stop the process

PROGRAM:
INPUT:
OUTPUT:

EXPERIMENT – 10

AIM Program to implement classical inter process communication problem of dinning


Philosphers.
THEORY:
DINNING PHILOSPHERS PROBLEM:

There are some Philosophers whose work is just thinking and eating. Let there are 5 (for
example) philosophers. They sat at a round table for dinner. To complete dinner each must
need two Forks (spoons). But there are only 5 Forks available (Forks always equal to no. of
Philosophers) on table. They take in such a manner that, first take left Fork and next right
Fork. But problem is they try to take at same time. Since they are trying at same time, Fork 1,
2, 3, 4, 5 taken by Philosopher 1, 2, 3, 4, 5 respectively (since they are left side of each). And
each one tries to ta ke right side Fork. But no one found available Fork. And also that each
one thinks that someone will release the Fork and then I can eat. This continuous waiting
leads to Dead Lock situation.

ALGORITHM:

1. Define the number of philosophers


2. Declare one thread per philosopher
3. Declare one semaphore (represent chopsticks) per philosopher
4. When a philosopher is hungry
1. See if chopsticks on both sides are free
2. Acquire both chopsticks or
3. eat
4. restore the chopsticks
5. If chopsticks aren’t free

Wait till they are available.

PROGRAM:
INPUT:
OUTPUT:

EXPERIMENT – 11

AIM: Program to implement classical inter process communication problem (producer


consumer).

THEORY:

PRODUCER CONSUMER PROBLEM:

Imagine a scenario in which there exists two Destinct processes both operating on a single
shared data area. One process, the Producer inserts information into the data area whilst the
other process, the Consumer, removes information from that same area. In order for the
Producer to insert information into the data area, there must be enough space. The Producer's
sole function is to insert data into the data-area, it is not allowed to remove any data from the
area. Similarly ormation there in the first place. Once again, the sole function of the
Consumer is to remove data from the data area. If no data is present then the Consumer is not
allowed to insert some data of it's own to later be removed by itself.

In short, the Producer relies on the Consumer to make space in the data-area so that it may
insert more information whilst at the same time, the Consumer relies on the Producer to insert
information into the data area so that it may remove that information. It therefore follows that
a mechanism is required to allow the Producer and Consumer to communicate so that they
know when it is safe to attempt to write or read information from the data-area.
ALGORITHM:

Step 1: Start
Step 2: Define the maximum buffer size.
Step 3:Enter the number of producers and consumers.
Step 4: The producer produces the job and put it in the buffer.
Step 5:The consumer takes the job from the buffer.
Step 6:If the buffer is full the producer goes to sleep.
Step 7:If the buffer is empty then consumer goes to sleep.
Step 8:Stop

PROGRAM:
EXPERIMENT – 12

AIM: Program to implement classical inter process communication problem (Reader


Writers).

THEORY:

READER WRITER PROBLEM:

Consider a situation where we have a file shared between many people.

If one of the people tries editing the file, no other person should be reading or writing at the
same time, otherwise changes will not be visible to him/her.
However if some person is reading the file, then others may read it at the same time.
Precisely in OS we call this situation as the readers-writers problem

Problem parameters:

One set of data is shared among a number of processes


Once a writer is ready, it performs its write. Only one writer may write at a time
If a process is writing, no other process can read it
If at least one reader is reading, no other process can write
Readers may not write and only read
Solution when Reader has the Priority over Writer
PROGRAM:
INPUT:

OUTPUT:

You might also like