0% found this document useful (0 votes)
45 views39 pages

OS Workbook CSL303

This document outlines experiments to be performed in an operating systems lab workbook. It includes details about writing shell programming code to perform tasks like checking if a number is even or odd, finding largest of three numbers, and implementing CPU scheduling algorithms. Students are expected to complete the experiments and provide code samples.

Uploaded by

shivam
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)
45 views39 pages

OS Workbook CSL303

This document outlines experiments to be performed in an operating systems lab workbook. It includes details about writing shell programming code to perform tasks like checking if a number is even or odd, finding largest of three numbers, and implementing CPU scheduling algorithms. Students are expected to complete the experiments and provide code samples.

Uploaded by

shivam
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/ 39

Operating System (CSL303) LabWorkbook

Session: 2023-24

Operating System
CSL303

Lab Workbook

Faculty name: Student name:vinay


Roll No.: 21csu380
Semester: 5th
Group:C2

Department of Computer Science and


EngineeringTheNorthCap University
Gurugram- 122001, India
Session2023-24
ii

Operating System (CSL303) Lab Workbook


Session: 2023-24

INDEX
S. Experiment DateofExper DateofSubm COCover Signature
No iment ission ed
To familiarize the students to Linux interface
1
and install Linux.

To write the shell programming code for the


following.
a) Write A Shell Program of Hello World
b) Write a shell program to find factorial of a
number.
2 c) Write a shell program to find gross salary of
an employee.
d) Write a shell program to display the menu
and execute instructions accordingly
(i)List of files (ii)Process Status (iii) Date (iv)
users in program (v) Quit

To write the shell programming code for the


following.
a) Write a shell program to find Fibonacci
series.
3
b) Write a shell program to find largest of three
numbers.
c) Write a shell program to find average of N
numbers

To write the shell programming code for the


following.
a) Write a shell program to check whether a
number is even or odd
b) Write a shell program to find whether a
4
number is prime or not.
c) Write a shell program to find whether a
number is palindrome or not.
d) Write a shell program to type number 1 to 7
and then print its corresponding day of week
iii

Operating Systems (CSL303) Lab Workbook


Session: 2023-24

Implement the following CPU scheduling


Algorithms.
5
i) FCFS with Arrival time
ii)FCFS without Arrival time

Implement the following CPU scheduling


Algorithms.
6  SJF (Non-Preemptive)
 SJTF (shortest remaining time first -
Preemptive SJF)

7 Implement the priority scheduling.

8 Implement the Round Robin scheduling.

Write a program to implement reader/writer


9
problem using semaphore
Write a program to implement Dining
10 Philosopher’s problem using semaphore

Write a program to implement Banker’s


11
algorithm for deadlock avoidance.

Write a program for page replacement policy


12
using a) LRU b) FIFO c) Optimal.
iv

Operating Systems (CSL303) Lab Workbook


Session: 2023-24

Experiment No: 1

Student Name and Roll Number: vinay 21csu380

Semester /Section: 5th

Link to Code:

Date:7/8/23

Faculty Signature:

Marks:

Objective(s):
To familiarize the students to Linux interface.

Outcome:
 The students will understand commands used in Linux.

Problem Statement:

Implement the following things:

 Linux Installation

Background Study:

Cygwin is a open source tool which provides that functionality of the Linux in windows Operating
System. Cygwin is a large collection of GNU and Open Source tools which provide functionality similar to
a Linux distribution on Windows. It is a DLL (cygwin1.dll) which provides substantial POSIX API
functionality.

Question Bank:
v

Operating Systems (CSL303) Lab Workbook


Session: 2023-24

1. What is Linux?

2. How will you List files from a directory?

3. How files in a directory can be removed?

4. How to find out a word in a file?

5. What are wildcards?

Student Work Area


Algorithm/Flowchart/Code/Sample Outputs
vi

Operating Systems (CSL303) Lab Workbook


Session: 2023-24
vii

Operating Systems (CSL303) Lab Workbook


Session: 2023-24

Experiment No: 2

Student Name and Roll Number: vinay

Semester /Section: 5th c2

Link to Code:

Date:7/8/23

Faculty Signature:

Marks:

Objective(s):
To write the shell programming code for the following.

Outcome:
 Student is able to write code in shell programming.

Problem Statement:

a) Write A Shell Program of Hello World

b) Write a shell program to find factorial of a number.

c) Write a shell program to find gross salary of an employee.

d) Write a shell program to display the menu and execute instructions accordingly

 (i)List of files (ii)Process Status (iii) Date (iv) users in program (v) Quit
viii

Operating Systems (CSL303) Lab Workbook


Session: 2023-24

Background Study:

A shell script is a file with a set of commands in it. The shell reads this file and executes the
instructions as if they were input directly on the command line.

A shell is a command-line interpreter and operations such as file manipulation, program execution
and text printing are performed by shell script. So, we will use vi editor to edit our files.

Question Bank:

1. What is a shell?
2. What is the significance of $#?
3. What are the different types of commonly used shells on a typical Linux system?
4. How will you pass and access arguments to a script in Linux?

5. Use sed command to replace the content of the file (emulate tac command)

Student Work Area


Algorithm/Flowchart/Code/Sample Outputs
ix

Operating Systems (CSL303) Lab Workbook


Session: 2023-24
x

Operating Systems (CSL303) Lab Workbook


Session: 2023-24
xi

Operating Systems (CSL303) Lab Workbook


Session: 2023-24
xii

Operating Systems (CSL303) Lab Workbook


Session: 2023-24
xiii

Operating Systems (CSL303) Lab Workbook


Session: 2023-24
xiv

Operating Systems (CSL303) Lab Workbook


Session: 2023-24
xv

Operating Systems (CSL303) Lab Workbook


Session: 2023-24
xvi

Operating Systems (CSL303) Lab Workbook


Session: 2023-24

EXPERIMENT NO. 3

Student Name and Roll Number:

Semester /Section:

Link to Code:

Date:

Faculty Signature:

Marks:

Objective:
To write the shell programming code for the following.

Outcome:
Student is able to write code in shell programming

Problem Statement:
a) Write a shell program to find Fibonacci series.

b) Write a shell program to find largest of three numbers.

c) Write a shell program to find average of N numbers

Background Study:

A shell script is a file with a set of commands in it. The shell reads this file and executes the
instructions as if they were input directly on the command line.
xvii

Operating Systems (CSL303) Lab Workbook


Session: 2023-24

A shell is a command-line interpreter and operations such as file manipulation, program execution
and text printing are performed by shell script. So, we will use vi editor to edit our files.

Question Bank:

1. How to use multi line comments in shell script?


2. What is the difference between soft and hard links?
3. Explain about loops and what are the loops available in LINUX?
4. What are absolute and relative paths.
5. How to debug a shell script.

Student Work Area


Algorithm/Flowchart/Code/Sample Outputs
xviii

Operating System (CSL303) Lab Workbook


Session: 2023-24

EXPERIMENT NO. 4

Student Name and Roll Number:

Semester /Section:

Link to Code:

Date:

Faculty Signature:

Marks:

Objective:
To write the shell programming code for the following.

Outcome:
Student is able to write code in shell programming

Problem Statement:
a) Write a shell program to check whether a number is even or odd

b) Write a shell program to find whether a number is prime or not.

c) Write a shell program to find whether a number is palindrome or not.

d) Write a shell program to type number 1 to 7 and then print its corresponding day of week

Background Study:

A shell script is a file with a set of commands in it. The shell reads this file and executes the
instructions as if they were input directly on the command line.

A shell is a command-line interpreter and operations such as file manipulation, program execution
and text printing is performed by shell script. So, we will use vi editor to edit our files.

Question Bank:
xix

Operating System (CSL303) Lab Workbook


Session: 2022-23

1. What are Zoombie Process?


2. What are different types of variables used in shell script?
3. What are the different types of modes available in Vi editor?
4. What are the different types of permission at file level in shell?
5. How to use comments in shell script.

Student Work Area


Algorithm/Flowchart/Code/Sample output
xx

Operating System (CSL303) Lab Workbook


Session: 2023-24

Experiment No: 5

Student Name and Roll Number:


Semester /Section:

Link to Code:

Date:
Faculty Signature:

Marks:

Objective:
Write a program to implement CPU scheduling for first come first serve approach.

Outcome:
The students will understand the First-cum-first-serve algorithm

Problem Statement:
Implement the following CPU scheduling Algorithms.

i) FCFS with Arrival time


ii) FCFS without Arrival time

Background Study:
FCFS

• The simplest CPU-scheduling algorithm is the first-come, first-served (FCFS) scheduling


algorithm. With this algorithm, processes are assigned the CPU in the order they request it.
• There is a single queue of ready processes.
• The implementation of the FCFS policy is easily managed with a FIFO queue. When a process
enters the ready queue, its PCB is linked onto the tail of the queue.
• The average waiting time under the FCFS policy, however, is often quite long.
Question Bank:

1. Which module gives control of the CPU to the process selected by the short-term scheduler?
a) dispatcher
b) interrupt
c) scheduler
xxi

Operating System (CSL303) Lab Workbook


Session: 2023-24

d) none of the mentioned

2. The processes that are residing in main memory and are ready and waiting to execute are kept on a list
called
a) job queue
b) ready queue
c) execution queue
d) process queue

3. The interval from the time of submission of a process to the time of completion is termed as
a) waiting time
b) turnaround time
c) response time
d) throughput

4. Which scheduling algorithm allocates the CPU first to the process that requests the CPU first?
a) first-come, first-served scheduling
b) shortest job scheduling
c) priority scheduling
d) none of the mentioned

5. In priority scheduling algorithm

a) CPU is allocated to the process with highest priority


b) CPU is allocated to the process with lowest priority
c) equal priority processes cannot be scheduled
d) none of the mentioned
xxii

Operating System (CSL303) Lab Workbook


Session: 2023-24

Student Work Area


Algorithm/Flowchart/Code/Sample Outputs
xxiii

Operating System (CSL303) Lab Workbook


Session: 2023-24

Experiment No: 6

Student Name and Roll Number:


Semester /Section:

Link to Code:

Date:
Faculty Signature:

Marks:

Objective:

Write a program to implement CPU scheduling for shortest job first (Preemptive and Non-Preemptive)

Outcome:
The students will understand the Shortest Job First scheduling mechanism

Problem Statement:
Implement the following CPU scheduling Algorithms.

 SJF (Non-Preemptive)
 SJTF (shortest remaining time first -Preemptive SJF)

Background Study:
 Shortest Job first is having the advantage of a minimum average waiting time .
 This algorithm associates with each process the length of the process next burst time.When
CPU is available it assigned to the process that has the smallest next CPU burst time.if
CPU burst time of two process is same then it follows FCFS.
 It may cause starvation if shorter processes keep coming. This problem can be solved using
the concept of ageing.
 It is practically infeasible as Operating System may not know burst time and therefore may
not sort them.
Question Bank:

1. scheduling algorithm In multilevel feedback


A. processes are not classified into groups
B. a process can move to a different classified ready queue…
C. classification of the ready queue is permanent
D. none of the mentioned
2. Select one which algorithms tend to minimize the process flow time?
A. First come First served
B. Earliest Deadline First
C. Shortest Job First
xxiv

Operating System (CSL303) Lab Workbook


Session: 2023-24

D. Longest Job First


3. The process can be classified into many groups in
A. shortest job scheduling algorithm
B. multilevel queue scheduling algorithm
C. round-robin scheduling algorithm
D. priority scheduling algorithm
4. The turnaround time for short jobs during multiprogramming is usually Shortened and that
for long jobs is slightly ___________
A. Shortened
B. Unchanged
C. Lengthened
D. Shortened
5. Time quantum can be said
A. multilevel queue scheduling algorithm
B. round-robin scheduling algorithm
C. shortest job scheduling algorithm
D. priority scheduling algorithm
xxv

Operating System (CSL303) Lab Workbook


Session: 2023-24

Student Work Area


Algorithm/Flowchart/Code/Sample Outputs
xxvi

Operating System (CSL303) Lab Workbook


Session: 2023-24

Experiment No: 7

Student Name and Roll Number:


Semester /Section:

Link to Code:

Date:
Faculty Signature:

Marks:

Objective:
Write a program to perform priority scheduling among a set of processes.

Outcome:
Student will understand the working of priority scheduling among a set of processes.

Problem Statement:
Implement the priority scheduling.

Background Study:
Priority scheduling is a non-preemptive algorithm and used in batch systems. Each process is assigned a
priority. Process with highest priority is to be executed first and so on.

Question Bank:
1. What are advantages of Priority scheduling?

Sol.Easy to use scheduling method. Processes are executed on the basis of priority so high priority
does not need to wait for long which saves time.

2. What are disadvantages of priority scheduling?

Sol.The major disadvantage of priority scheduling is the process of indefinite blocking or


starvation. This problem appears when a process is ready to be executed but it has to wait for the
long time for execution by CPU because other high priority processes are executed by the CPU.

3.  At the ready queue when a process arrives In priority scheduling algorithm, the priority of this
process is compared with the priority of?
A. currently running process
B. parent process
C. all process
D. init process
4. Differentiate between pre-emptive and non pre-emptive scheduling?
xxvii

Operating System (CSL303) Lab Workbook


Session: 2023-24

Sol.The basic difference between preemptive and non-preemptive scheduling is that in preemptive
scheduling the CPU is allocated to the processes for the limited time. While in Non-preemptive
scheduling, the CPU is allocated to the process till it terminates or switches to waiting state.

Student Work Area


Algorithm/Flowchart/Code/Sample Outputs
xxviii

Operating System (CSL303) Lab Workbook


Session: 2023-24

Experiment No: 8

Student Name and Roll Number:


Semester /Section:

Link to Code:

Date:
Faculty Signature:

Marks:

Objective: Objective

To familiarize the students about CPU scheduling Algorithms

Program Outcome

The students will understand the Round Robin Algorithm.

Problem Statement:
Implement the Round Robin Algorithm.
Background Study:
 In Round Robin each process is assigned a fixed time slot in a cyclic way and this is preemptive. It
has a disadvantage of context switch and have quantum time

Question Bank:

1. What is Preemptive and Non- Preemptive CPU scheduling? Explain with examples.
Sol.Preemptive:
In this resources(CPU Cycle) are allocated to a process for a limited time.
Eg.Examples of preemptive scheduling are Round Robin and Shortest Remaining Time First.

Non-Preemptive
Once resources(CPU Cycle) are allocated to a process, the process holds it till it completes its
burst time or switches to waiting state.
Eg.Examples of non-preemptive scheduling are First Come First Serve and Shortest Job First.
xxix

Operating System (CSL303) Lab Workbook


Session: 2023-24

2. Explain the difference between short term, long term and medium term scheduling.
Sol.Long term:It selects processes from the pool and load them into memory for execution.
Medium term:Process can be reintroduced into the meat and its execution can be continued.
Short term:It selects from among the processes that are ready to execute.

3. Explain the function of Dispatcher and Context Switch mechanism.


Sol.Dispatcher is also responsible for:Context Switching, Switch to user mode, Jumping to
proper location when process again restarted
The only work of scheduler is selection of processes.

4. What are the advantages and disadvantages of Round robin?

Sol.Advantages –

Every process gets an equal share of the CPU.

RR is cyclic in nature, so there is no starvation.

Disadvantages –

Setting the quantum too short, increases the overhead and lowers the CPU efficiency, but setting it too
long may cause poor response to short processes.

Average waiting time under the RR policy is often long.

5. Give the application are of Robin Robin.

Sol.A popular use of the queue data structure is the scheduling problem in the operating system.
Round-robin is one of the simplest scheduling algorithms for processes in an operating system,
which assigns time slices to each process in equal portions and in order, handling all processes
without priority.
xxx

Operating System (CSL303) Lab Workbook


Session: 2023-24

Student Work Area


Algorithm/Flowchart/Code/Sample Outputs
xxxi

Operating System (CSL303) Lab Workbook


Session: 2023-24

Experiment No: 9

Student Name and Roll Number:


Semester /Section:

Link to Code:

Date:
Faculty Signature:

Marks:

Objective: Write a program to implement reader/writer problem using semaphore

Program Outcome

The students will understand the reader/writer problem using semaphore


Problem Statement:
Write a program to implement reader/writer problem using semaphore

Background Study: There is a shared resource which should be accessed by multiple processes. There are
two types of processes in this context. They are reader and writer. Any number of readers can read from the
shared resource simultaneously, but only one writer can write to the shared resource. When a writer is
writing data to the resource, no other process can access the resource. A writer cannot write to the resource if
there are non-zero number of readers accessing the resource at that time.

Question Bank:

1. An un-interruptible unit is known as ____________


a) single
b) atomic
c) static
d) none of the mentioned
2. TestAndSet instruction is executed ____________
a) after a particular process
b) periodically
c) atomically
d) none of the mentioned
3. Semaphore is a/an _______ to solve the critical section problem.
a) hardware for a system
b) special program for a system
c) integer variable
xxxii

Operating System (CSL303) Lab Workbook


Session: 2023-24

d) none of the mentioned


4. What are the two atomic operations permissible on semaphores?
a) wait
b) stop
c) hold
d) none of the mentioned
5. When several processes access the same data concurrently and the outcome of the execution
depends on the particular order in which the access takes place is called ________
a) dynamic condition
b) race condition
c) essential condition
d) critical condition

Student Work Area


Algorithm/Flowchart/Code/Sample Outputs
xxxiii

Operating System (CSL303) Lab Workbook


Session: 2023-24

Experiment No: 10

Student Name and Roll Number:


Semester /Section:

Link to Code:

Date:
Faculty Signature:

Marks:

Objective:

Write a program to implement Dining Philosopher’s problem using semaphore

Outcome:
The students will understand the problem of synchronization among processes and its solution through
Dining Philosopher’s problem using semaphore

Problem Statement:

Write a program to implement Dining Philosopher’s problem using semaphore

Background Study:
Five philosophers, spend their time thinking and eating spaghetti. They eat at a round table with five individual
seats. For eating each philosopher needs two forks (the resources). There are five forks on the table, one left
and one right of each seat. When a philosopher cannot grab both forks it sits and waits. Eating takes random
time, then the philosopher puts the forks down and leaves the dining room. After spending some random time
thinking he again becomes hungry, and the circle repeats itself.

Question Bank:

1. Which one of the following is a synchronization tool?


a) thread
b) pipe
c) semaphore
d) socket
2. A semaphore is a shared integer variable __________
a) that can not drop below zero
b) that can not be more than zero
xxxiv

Operating System (CSL303) Lab Workbook


Session: 2023-24

c) that can not drop below one


d) that can not be more than one
3. The bounded buffer problem is also known as ____________
a) Readers – Writers problem
b) Dining – Philosophers problem
c) Producer – Consumer problem
d) None of the mentioned
4. In the bounded buffer problem ____________
a) there is only one buffer
b) there are n buffers ( n being greater than one but finite)
c) there are infinite buffers
d) the buffer size is bounded
5. To ensure difficulties do not arise in the readers – writers problem _______ are given exclusive
access to the shared object.
a) readers
b) writers
c) readers and writers
d) none of the mentioned

Student Work Area


Algorithm/Flowchart/Code/Sample Outputs
xxxv

Operating System (CSL303) Lab Workbook


Session: 2023-24

Experiment No:11

Student Name and Roll Number:


Semester /Section:

Link to Code:

Date:
Faculty Signature:

Marks:

Objective:
Write a program to implement Banker’s algorithm for deadlock avoidance.

Outcome:
The students will understand how system handles deadlock using Banker’s algorithm for deadlock avoidance
Problem Statement:
Write a program to implement Banker’s algorithm for deadlock avoidance.
Background Study:
The banker’s algorithm is a resource allocation and deadlock avoidance algorithm that tests for safety by
simulating the allocation for predetermined maximum possible amounts of all resources, then makes an “s-
state” check to test for possible activities, before deciding whether allocation should be allowed to continue.
Banker’s algorithm is named so because it is used in banking system to check whether loan can be sanctioned
to a person or not. Suppose there are n number of account holders in a bank and the total sum of their money is
S. If a person applies for a loan then the bank first subtracts the loan amount from the total money that bank has
and if the remaining amount is greater than S then only the loan is sanctioned. It is done because if all the
account holders comes to withdraw their money then the bank can easily do it.

Question Bank:
1. Each request requires that the system consider the _____________ to decide whether the
current request can be satisfied or must wait to avoid a future possible deadlock.
a) resources currently available
b) processes that have previously been in the system
c) resources currently allocated to each process
xxxvi

Operating System (CSL303) Lab Workbook


Session: 2023-24

d) future requests and releases of each process


2. Given a priori information about the ________ number of resources of each type that maybe
requested for each process, it is possible to construct an algorithm that ensures that the
system will never enter a deadlock state.
a) minimum
b) average
c) maximum
d) approximate
3. A deadlock avoidance algorithm dynamically examines the __________ to ensure that a
circular wait condition can never exist.
a) resource allocation state
b) system storage state
c) operating system
d) resources
4. A state is safe, if ____________
a) the system does not crash due to deadlock occurrence
b) the system can allocate resources to each process in some order and still avoid a deadlock
c) the state keeps the system protected and safe
d) all of the mentioned
5. The two ways of aborting processes and eliminating deadlocks are ____________
a) Abort all deadlocked processes
b) Abort all processes
c) Abort one process at a time until the deadlock cycle is eliminated
d) All of the mentioned

Student Work Area


Algorithm/Flowchart/Code/Sample Outputs
xxxvi
i
Operating System (CSL303) Lab Workbook
Session: 2023-24

Experiment No: 12

Student Name and Roll Number:


Semester /Section:

Link to Code:

Date:
Faculty Signature:

Marks:

Objective:
Write a program for page replacement policy using a) LRU b) FIFO c) Optimal.
Outcome:
The students will understand concept of memory management through various page replacement policy
using a) LRU b) FIFO

Problem Statement:
Write a program to implement page replacement policy using a) LRU b) FIFO c) Optimal.

Background Study:
In operating systems that use paging for memory management, page replacement
algorithm are needed to decide which page needed to be replaced when new page comes
in. Whenever a new page is referred and not present in memory, page fault occurs and
Operating System replaces one of the existing pages with newly needed page. Different
page replacement algorithms suggest different ways to decide which page to replace. The
target for all algorithms is to reduce number of page faults.

Question Bank:

1. The main memory accommodates ____________


a) operating system
b) cpu
c) user processes
d) all of the mentioned
xxxvi
ii
Operating System (CSL303) Lab Workbook
Session: 2023-24

2. What is the operating system?


a) in the low memory
b) in the high memory
c) either low or high memory (depending on the location of interrupt vector)
d) none of the mentioned

3. In contiguous memory allocation ____________


a) each process is contained in a single contiguous section of memory
b) all processes are contained in a single contiguous section of memory
c) the memory space is contiguous
d) none of the mentioned

4. The relocation register helps in ____________


a) providing more address space to processes
b) a different address space to processes
c) to protect the address spaces of processes
d) none of the mentioned

5. With relocation and limit registers, each logical address must be _______ the limit register.
a) less than
b) equal to
c) greater than
d) none of the mentioned

Student Work Area


Algorithm/Flowchart/Code/Sample Outputs

You might also like