0% found this document useful (0 votes)
28 views154 pages

Final Lab Manual-Take Print-1

The CS3461 Operating Systems Lab Manual outlines the objectives, outcomes, and experiments for a computer science engineering course under Regulation 2021. It emphasizes the importance of technical education, problem-solving skills, and ethical values in preparing graduates for successful careers. The manual includes a detailed mapping of course outcomes to program outcomes and specific skills, alongside a list of experiments designed to enhance practical knowledge in operating systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views154 pages

Final Lab Manual-Take Print-1

The CS3461 Operating Systems Lab Manual outlines the objectives, outcomes, and experiments for a computer science engineering course under Regulation 2021. It emphasizes the importance of technical education, problem-solving skills, and ethical values in preparing graduates for successful careers. The manual includes a detailed mapping of course outcomes to program outcomes and specific skills, alongside a list of experiments designed to enhance practical knowledge in operating systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 154

CS3461-OPERATING SYSTEMS LAB MANUAL

REGULATION-2021

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

B.E.COMPUTER SCIENCE AND ENGINEERING


CS3461-OPERATING SYSTEMS LAB MANUAL

REGULATION-2021

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

PREPARED BY : Mrs.G.Nithya APPROVED BY:

SIGNATURE: SIGNATURE :

DATE: DATE:
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
ACADEMIC YEAR: 2023 - 2024 (EVEN SEMESTER)
VISION, MISSION, POs, PEOs and PSOs
Vision of the Institution:

We endeavor to impart futuristic technical education of the highest quality to the student community
and to inculcate discipline in them to face the world with self-confidence and thus we prepare them for life as
responsible citizens to uphold human values and to be of services at large. We strive to bring up the
Institution as an Institution of Academic excellence of International standard.

Mission of the Institution:


We transform persons into personalities by the state-of-the-art infrastructure, time consciousness,
quick response and the best academic practices through assessment and advice.

Vision of the Department:


To offer a quality education in computer science and Engineering, encourage life-long learning and
make graduates responsible for society by upholding social values in the field of emerging technology.

Mission of the Department:


To produce graduates with sound technical knowledge and good skills that prepare them for
rewarding career in prominent industries. To promote collaborative learning and research with Industry,
Government and International organizations for continuous knowledge transfer and enhancement. To promote
entrepreneurship and mould the graduates to be leaders by cultivating the spirit of social ethical values.
Programme Educational Objectives (PEOs)

PEO1 - Graduates will have successful careers with high level of technical competency and problem-solving
skills to produce innovative solutions for industrial needs.
PEO2 – Graduates will have good professionalism, team work, effective communication, leadership qualities
and life-long learning for the welfare of mankind. PEO3 – Graduates will be familiar with recent trends in
industry for delivering and implementing innovative system in collaboration.

Program Outcomes (PO)


PO 1:. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals,
and an engineering specialization to the solution of complex engineering problems.
PO 2: Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
PO 3: Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the public
health and safety, and the cultural, societal, and environmental considerations.
PO 4: Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
PO 5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
PO 6: The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
PO 7: Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
PO 8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
theengineering practice.
PO 9: Individual and team work: Function effectively as an individual, and as a member or leader in
diverseteams, and in multidisciplinary settings.

PO 10: Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, and give and receive clear instructions.
PO 11: Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage projects
and in multidisciplinary environments.
PO 12: Life Long Learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
Program Specific Outcome (PSO)

PSO1 :Students will be apply programming skills to develop new software with assured quality.
PSO2 : Students will be ability to demonstrate specific coding skills to improve employability.
PSO3 :Ability to work effectively with various engineering fields as a team to design, build and develop
system applications.

Name of the Faculty Member HOD


DEPARTMENTOFCOMPUTERSCIENCE ANDENGINEERING

CS3461-OPEARTING SYSTEMS LABORATORY

COs Knowledge Course outcomes


level

1. K6 Define and implement UNIX Commands.

2. K5 Compare the performance of various CPU Scheduling Algorithms.

3. K4 Compare and contrast various Memory Allocation Methods.

4. K4 Define File Organization and File Allocation Strategies

5. K6 Implement various Disk Scheduling Algorithms.

List of Experiments Mapping with COs, Pos &PSOs


Exp.No Name of the Experiment C POs PSOs
Os
1. Installation of windows operating 1 1,2,3,4,5,9,10,11,12 1,2,3
system
2. Illustrate UNIX commands and 1 1,2,3,4,5,9,10,11,12 1,2,3
Shell Programming
3. Process Management using System 1 1,2,3,4,5,9,10,11,12 1,2,3
Calls : Fork, Exit, Getpid, Wait,
Close
4. Write C programs to implement the 2 1,2,3,4,5,9,10,11,12 1,2,3
various CPU Scheduling Algorithms
5. Illustrate the inter process 2 1,2,3,4,5,9,10,11,12 1,2,3
communication strategy
6. Implement mutual exclusion by 2 1,2,3,4,5,9,10,11,12 1,2,3
Semaphore
7. Write C programs to avoid Deadlock 3 1,2,3,4,5,9,10,11,12 1,2,3
using Banker's Algorithm
8. Write a C program to Implement 3 1,2,3,4,5,9,10,11,12 1,2,3
Deadlock Detection Algorithm
9. Write C program to implement 3 1,2,3,4,5,9,10,11,12 1,2,3
Threading
10. Implement the paging Technique 4 1,2,3,4,5,9,10,11,12 1,2,3
using C program
11. Write C programs to implement the 4 1,2,3,4,5,9,10,11,12 1,2,3
following Memory Allocation
Methods a. First Fit b. Worst Fit c.
Best Fit
12. Write C programs to implement the 4 1,2,3,4,5,9,10,11,12 1,2,3
various Page Replacement
Algorithms
13. Write C programs to Implement the 5 1,2,3,4,5,9,10,11,12 1,2,3
various File Organization
Techniques
14. Implement the following File 5 1,2,3,4,5,9,10,11,12 1,2,3
Allocation Strategies using C
programs
a. Sequential b. Indexed c. Linked
15. Write C programs for the 5 1,2,3,4,5,9,10,11,12 1,2,3
implementation of various disk
scheduling algorithms
16 Install any guest operating system 1,2,3,4,5,9,10,11,12
like Linux using VMware.
Additional Experiments
17. Shell Programming 4 1,2,3,4,5,9,10,11,12 1,2,3
18. Implementation of Shared Memory 5 1,2,3,4,5,9,10,11,12 1,2,3
using IPC
COURSE OUTCOME Versus PO&PSO MAPPING(DETAILED; HIGH:3; MEDIUM:2;LOW:1):

CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
1 3 1 3 1 1 - - - 1 3 3 2 1 3 3
2 3 1 1 2 2 - - - 3 2 1 1 3 1 2
3 3 3 2 1 2 - - - 3 3 1 2 2 2 2
4 1 2 2 3 2 - - - 3 1 3 1 1 2 1
5 2 2 1 1 3 - - - 1 2 2 3 1 3 3
Avg. 2 2 2 2 2 - - - 2 2 2 2 2 2 2
*ForEntireCourse,PO/PSOMapping;1(Low);2(Medium);3(High)ContributiontoPO/PSO

PO1 Engineering Knowledge PO7 Environment& Sustainability PSO1 Professional Skills


PO2 Problem Analysis PO8 Ethics PSO2 Competency
PO3 Design& Development PO9 Individual& Team Work
PO4 Investigations PO10 Communication Skills
Project Management&
PO5 Modern Tools PO11
Finance
PO6 Engineer& Society PO12 Life Long Learning

JUSTIFICATIONFORMAPPING

SNO PO/PSO JUSTIFICATION


MAPPED
PO1-H Highly mapped as students gain the knowledge of define and implement UNIX
Commands.

PO2-L Slightly mapped as students understand the UNIX Commands.


PO3-L Slightly mapped as the students will be able compare the performance of various CPU
Scheduling Algorithms.
PO4-L Slightly mapped as students will learn the importance of software maintenance and
complexities involved in software evolution.
PO5-M Moderately mapped as students will compare the performance of various CPU
Scheduling Algorithms.
CO1 PO9-M Moderately mapped as the students will be able to explore design contrast various
Memory Allocation Methods.
PO10-H Highly mapped as the students will be able to explore design alternatives to producea
variety of potential design solutions of class model suited to meet functional
requirements.
PO11-H Highly mapped as the students will be able to explore contrast various Memory
Allocation Methods.
PO12-L Slightly implement various Disk Scheduling Algorithms.

PO1-H Highly mapped as students gain the knowledge of define and implement UNIX
Commands.
PO2-H Slightly mapped as students understand the UNIX Commands.

PO3-L Slightly mapped as the students will be able compare the performance of various CPU
Scheduling Algorithms.
PO4-M Slightly mapped as students will learn the importance of software maintenance and
complexities involved in software evolution.
PO5-M Moderately mapped as students will compare the performance of various CPU
Scheduling Algorithms.
PO9-H Moderately mapped as the students will be able to explore design contrast various
Memory Allocation Methods.
PO10-L Highly mapped as the students will be able to explore design alternatives to producea
variety of potential design solutions of class model suited to meet functional
C02 requirements.
PO11-M Highly mapped as the students will be able to explore contrast various Memory
Allocation Methods.
PO12-H Slightly implement various Disk Scheduling Algorithms.
PO1-H Highly mapped as students gain the knowledge of define and implement UNIX
Commands.
PO2-L Slightly mapped as students understand the UNIX Commands.
PO3-L Slightly mapped as the students will be able compare the performance of various CPU
Scheduling Algorithms.
PO4-L Slightly mapped as students will learn the importance of software maintenance and
complexities involved in software evolution.
CO3
PO5-H Moderately mapped as students will compare the performance of various CPU
Scheduling Algorithms.
PO9-H Moderately mapped as the students will be able to explore design contrast various
Memory Allocation Methods.
PO10-M Highly mapped as the students will be able to explore design alternatives to producea
variety of potential design solutions of class model suited to meet functional
requirements.
PO11-L Highly mapped as the students will be able to explore contrast various Memory
Allocation Methods.
PO12-L Slightly implement various Disk Scheduling Algorithms.
PO1-H Highly mapped as students gain the knowledge of define and implement UNIX
Commands.
PO2-M Slightly mapped as students understand the UNIX Commands.

PO3-M Slightly mapped as the students will be able compare the performance of various CPU
Scheduling Algorithms.
PO4-M Slightly mapped as students will learn the importance of software maintenance and
CO4
complexities involved in software evolution.
PO5-L Moderately mapped as students will compare the performance of various CPU
Scheduling Algorithms.
PO9-L Moderately mapped as the students will be able to explore design contrast various
Memory Allocation Methods.
PO10-H Highly mapped as the students will be able to explore design alternatives to producea
variety of potential design solutions of class model suited to meet functional
requirements.
PO11-M Highly mapped as the students will be able to explore contrast various Memory
Allocation Methods.
PO12-M Slightly implement various Disk Scheduling Algorithms.
PO1-H Highly mapped as students gain the knowledge of define and implement UNIX
Commands.
PO2-H Slightly mapped as students understand the UNIX Commands.

PO3-L Slightly mapped as the students will be able compare the performance of various CPU
Scheduling Algorithms.
PO4-L Slightly mapped as students will learn the importance of software maintenance and
complexities involved in software evolution.
PO5-L Moderately mapped as students will compare the performance of various CPU
CO5 Scheduling Algorithms.
PO9-H Moderately mapped as the students will be able to explore design contrast various
Memory Allocation Methods.
PO10-L Highly mapped as the students will be able to explore design alternatives to producea
variety of potential design solutions of class model suited to meet functional
requirements.
PO5-11 Highly mapped as the students will be able to explore contrast various Memory
Allocation Methods.
PO12-M Slightly implement various Disk Scheduling Algorithms.

SNO PO/PSO JUSTIFICATION


MAPPED
PSO1-L Slightly mapped as students understand the concepts of
softwareengineering and software requirements required in building the applications.

PSO2-H Highly mapped as Students should be able to develop and implement the
CO1 solution of real life computingproblems using contemporary technologies.
PSO3-L Slightly should be able to apply ethical principles and commit to professional and
socialresponsibilities.
PSO1-L Slightly mapped as students understand the concepts of
softwareengineering and software requirements required in building the applications.

PSO2-H Highly mapped as Students should be able to develop and implement the
solution of real life computingproblems using contemporary technologies.
CO2
PSO3-L Slightly should be able to apply ethical principles and commit to professional and
socialresponsibilities.

PSO1-L Slightly mapped as students understand the concepts of


softwareengineering and software requirements required in building the applications.

PSO2-H Highly mapped as Students should be able to develop and implement the
solution of real life computingproblems using contemporary technologies.
CO3
PSO3-L Slightly should be able to apply ethical principles and commit to professional and
socialresponsibilities.

PSO1-L Slightly mapped as students understand the concepts of


softwareengineering and software requirements required in building the applications.
PSO2-H Highly mapped as Students should be able to develop and implement the
CO4 solution of real life computingproblems using contemporary technologies.

PSO3-L Slightly should be able to apply ethical principles and commit to professional and
socialresponsibilities.

PSO1-L Slightly mapped as students understand the concepts of


softwareengineering and software requirements required in building the applications.
PSO2-H Highly mapped as Students should be able to develop and implement the
CO5 solution of real life computingproblems using contemporary technologies.
PSO3-L Slightly should be able to apply ethical principles and commit to professional and
socialresponsibilities.

Name of the Faculty Member HOD


CCS36 OPERATING SYSTEMS LABORATORY LT PC
0 0 3 1.5
COURSE OBJECTIVES:
 To install windows operating systems.
 To understand the basics of Unix command and shell programming
 To implement various CPU scheduling algorithms.
 To implement Deadlock Avoidance and Deadlock Detection Algorithms
 To implement Page Replacement Algorithms
 To implement various memory allocation methods.
 To be familiar with File Organization and File Allocation Strategies

EXPERIMENTS:
1. Installation of windows operating system.
2. Illustrate UNIX commands and Shell Programming .
3. Process Management using System Calls : Fork, Exit, Getpid, Wait, Close.
4. Write C programs to implement the various CPU Scheduling Algorithms.
5. Illustrate the inter process communication strategy .
6. Implement mutual exclusion by Semaphore.
7. Write C programs to avoid Deadlock using Banker's Algorithm .
8. Write a C program to Implement Deadlock Detection Algorithm.
9. Write C program to implement Threading.
10. Implement the paging Technique using C program .
11. Write C programs to implement the following Memory Allocation Methods a. First Fit b. Worst Fit c.
Best Fit.
12. Write C programs to implement the various Page Replacement Algorithms .
13. Write C programs to Implement the various File Organization Techniques.
14. Implement the following File Allocation Strategies using C programs a. Sequential b. Indexed c. Linked
15. Write C programs for the implementation of various disk scheduling algorithms .
16. Install any guest operating system like Linux using VMware.

TOTAL:45 PERIODS
COURSEOUTCOMES:
On completion of the course, students will be able to:
CO1: Define and implement UNIX Commands.

CO2: Compare the performance of various CPU Scheduling Algorithms.

CO3: Compare and contrast various Memory Allocation Methods.


CO4: Define File Organization and File Allocation Strategies.

CO5: Implement various Disk Scheduling Algorithms.


LIST OF EXPERIMENTS

S.No Name of the Experiments

1. Installation of windows operating system.

2. Illustrate UNIX commands and Shell Programming .


3. Process Management using System Calls : Fork, Exit, Getpid, Wait, Close.
4. Write C programs to implement the various CPU Scheduling Algorithms.
5. Illustrate the inter process communication strategy .
6. Implement mutual exclusion by Semaphore.
7. Write C programs to avoid Deadlock using Banker's Algorithm .
8. Write a C program to Implement Deadlock Detection Algorithm.
9. Write C program to implement Threading.
10. Implement the paging Technique using C program .
11. Write C programs to implement the following Memory Allocation Methods
a. First Fit b. Worst Fit c. Best Fit.
12. Write C programs to implement the various Page Replacement Algorithms .
13. Write C programs to Implement the various File Organization Techniques.
14. Implement the following File Allocation Strategies using C programs
a. Sequential b. Indexed c. Linked
15. Write C programs for the implementation of various disk scheduling algorithms .
16. Install any guest operating system like Linux using VMware.
Additional Experiments

17. Shell Programming

18. Implementation of Shared Memory using IPC


TABLE OF CONTENTS

S.NO. DATE EXPERIMENT TITLE MARKS SIGN.

1. Installation of windows operating system.


2. Illustrate UNIX commands and Shell Programming .
3. Process Management using System Calls : Fork, Exit,
Getpid, Wait, Close.
4. Write C programs to implement the various CPU
Scheduling Algorithms.
5. Illustrate the inter process communication strategy .
6. Implement mutual exclusion by Semaphore.
7. Write C programs to avoid Deadlock using Banker's
Algorithm .
8. Write a C program to Implement Deadlock Detection
Algorithm.
9. Write C program to implement Threading.
10. Implement the paging Technique using C program .
11. Write C programs to implement the following Memory
Allocation Methods
a. First Fit b. Worst Fit c. Best Fit.
12. Write C programs to implement the various Page
Replacement Algorithms.
13. Write C programs to Implement the various File
Organization Techniques.
14. Implement the following File Allocation Strategies using C
programs
a. Sequential b. Indexed c. Linked
15. Write C programs for the implementation of various disk
scheduling algorithms .
16 Install any guest operating system like Linux using
VMware.

17. Shell Programming


18. Implementation of Shared Memory using IPC
GENERAL INSTRUCTIONS TO THE STUDENTS
1. No food or drink is to be brought into the lab, including gum and candy.

2. No cell phones or electronic devices at the lab stations (i pods, MP3 Players, etc.,).

3. Students must proceed immediately to their assigned position.

4. Students should maintain silence during the Lab session.

5. Students must inspect their position for possible damage and report immediately to the
faculty any damage that may be found.

6. Students must follow the faculty’s instructions explicitly concerning all uses of the lab
equipment.

7. Leave your shoes in the shoes rack before entering into the lab

8. Shut down the computer properly before leaving from the lab.

9. Do not bring college bag inside the lab.

10. Arrange your chairs properly before leaving from the lab

11. Students must wear lab coat during lab session

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 1


SYLLABUS
CS3461 OPERATING SYSTEMS LABORATORY LTPC
0 0 3 1.5

COURSE OBJECTIVES:
 To install windows operating systems.
 To understand the basics of Unix command and shell programming.
 To implement various CPU scheduling algorithms.
 To implement Deadlock Avoidance and Deadlock Detection Algorithms
 To implement Page Replacement Algorithms
 To implement various memory allocation methods.
 To be familiar with File Organization and File Allocation Strategies.

LIST OF EXPERIMENTS:
1. Installation of windows operating system
2. Illustrate UNIX commands and Shell Programming
3. Process Management using System Calls: Fork, Exit, Getpid, Wait, Close
4. Write C programs to implement the various CPU Scheduling Algorithms
5. Illustrate the inter process communication strategy
6. Implement mutual exclusion by Semaphore
7. Write C programs to avoid Deadlock using Banker's Algorithm
8. Write a C program to Implement Deadlock Detection Algorithm
9. Write C program to implement Threading
10. Implement the paging Technique using C program
11. Write C programs to implement the following Memory Allocation Methods
a. First Fit b. Worst Fit c. Best Fit
12. Write C programs to implement the various Page Replacement Algorithms
13. Write C programs to Implement the various File Organization Techniques
14. Implement the following File Allocation Strategies using C programs
a. Sequential b. Indexed c. Linked
15. Write C programs for the implementation of various disk scheduling algorithms
16. Install any guest operating system like Linux using VMware.
TOTAL:45 PERIODS

COURSE OUTCOMES:
At the end of this course, the students will be able to:

CO1 : Define and implement UNIX Commands.


CO2 : Compare the performance of various CPU Scheduling Algorithms.
CO3 : Compare and contrast various Memory Allocation Methods.
CO4 : Define File Organization and File Allocation Strategies.
CO5 : Implement various Disk Scheduling Algorithms.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 2


LIST OF EXPERIMENTS – CO MAPPING
Exp. No. Experiments CO Mapped
1 Installation of Windows Operating System
2 Basics of Unix Commands
3A The Fork System Call
3B The Exit System Call CO1
3C The Getpid System Call
3D Wait System Call
3E Close System Call
4A First Come First Serve Scheduling
4B Shortest Job Fist Scheduling Algorithm
4C Priority Scheduling
4D Round Robin Scheduling
5 Implementation of IPC using PIPE CO2
6 Implementation of Producer Consumer Problem using Semaphore
7 Implementation of Bankers Algorithm for Dead Lock Avoidance
8 Implementation of Deadlock Detection Algorithm
9 Implement Threading & Synchronization Applications
10 Memory Management Scheme using Paging
11A Implementation of First Fit Algorithm
11B Implementation of Worst Fit Algorithm
11C Implementation of Best Fit Algorithm
CO3
12A Implementation of Page Replacement Algorithm (FIFO)
12B Implementation of Page Replacement Algorithm (LRU)
Implementation of Page Replacement Algorithm using Least
12C
Frequently Used Algorithm
Implementation of File Organization Techniques using Single
13A
Level Directory
CO4
Implementation of File Organization Techniques using Two Level
13B
Directory

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 3


Implementation of File Organization Techniques using
13C
Hierarchical Level Directory
13D Implementation of File Organization Techniques Using DAG
14A Implementation of Sequential File Allocation Strategies CO4

14B Implementation of Indexed File Allocation Strategies


14C Implementation of Linked File Allocation Strategies
15A Implementation of FCFS Disk Scheduling Algorithm
15B Implementation of SSTF Disk Scheduling Algorithm CO5
16 Installation of Linux using VMware`
Additional Experiments
17 Shell Programming
CO5
18 Implementation of Shared Memory using IPC CO4

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 4


INDEX
Exp. Page Faculty
Date Experiment Marks
No. No. Signature
Installation of Windows Operating
1
System
2 Basics of Unix Commands
3A The Fork System Call
3B The Exit System Call
3C The Getpid System Call
3D Wait System Call
3E Close System Call
4A First Come First Serve Scheduling
4B Shortest Job Fist Scheduling Algorithm
4C Priority Scheduling
4D Round Robin Scheduling
5 Implementation of IPC using PIPE
Implementation of Producer Consumer
6
Problem using Semaphore
Implementation of Bankers Algorithm for
7
Dead Lock Avoidance
Implementation of Deadlock Detection
8
Algorithm
Implement Threading & Synchronization
9
Applications
Memory Management Scheme using
10
Paging
11A Implementation of First Fit Algorithm
11B Implementation of Worst Fit Algorithm
11C Implementation of Best Fit Algorithm
Implementation of Page Replacement
12A
Algorithm (FIFO)

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 5


Implementation of Page Replacement
12B
Algorithm (LRU)
Implementation of Page Replacement
12C Algorithm using Least Frequently Used
Algorithm
Implementation of File Organization
13A
Techniques using Single Level Directory
Implementation of File Organization
13B
Techniques using Two Level Directory
Implementation of File Organization
13C Techniques using Hierarchical Level
Directory
Implementation of File Organization
13D
Techniques Using DAG
Implementation of Sequential File
14A
Allocation Strategies
Implementation of Indexed File
14B
Allocation Strategies
Implementation of Linked File Allocation
14C
Strategies
Implementation of FCFS Disk
15A
Scheduling Algorithm
Implementation of SSTF Disk
15B
Scheduling Algorithm
16 Installation of Linux using VMware
Additional Experiments
17 Deadlock Avoidance
18 Deadlock Prevention

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 6


Exp. No. 1
Installation of Windows Operating System
Date

AIM:
To install Windows Operating System on computer.

PROCEDURE:
1. To perform a clean installation of Windows 10, download the free official Windows 10
installation media from Microsoft. Download it from here: https://www.microsoft.com/en-
us/software-download/windows10startfresh

2. Click on the "Download Tool Now" button.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 7


3. You can see that the tool is downloaded now. Now, run the downloaded file.

4. Accept the license term. Now, you will be asked to "Give your PC a fresh start." Choose
any one of the options given below. Select what you want to keep.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 8


5. Now, select "Create installation media for another PC" option. See the below image:

6. Select the language, architecture, and edition according to your need. For example, if you
have a laptop or PC with a 64-bit CPU, then you have to install the 64-bit version. If you
have a computer or PC with a 32-bit CPU, then you have to install the 32-bit version. If
you want to install Windows 10 on your current using laptop or PC, check the box "Use
the recommended options for this PC," and it will automatically download the best
compatible version for your current using PC; otherwise, uncheck this box. See the image
below:

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 9


7. Now, you can copy the Windows 10 installation files to a USB drive or burn them to a
DVD. The Windows 10 installation files occupy the space greater than 3 GB so, your USB
drive must be 4 GB or larger in size. The USB drive must be empty because all files in the
USB drive will be erased in this process. You can select the "ISO file" option if you want
to install Windows 10 in a virtual machine. First, download the ISO file and then boot the
downloaded ISO in a virtual machine to install Windows 10 inside that.

8. Now, the installation media is created. Please insert it into your laptop or PC and install
Windows 10. You have to boot to the Windows 10 installer. For the booting process, Click
on the Start menu button and restart your laptop.

9. Now, press and hold Del or F2 button to enter setup. This key may be different in some
computers. Generally, it is displayed as a message on startup that says, "Press [key] to enter
setup."
10. Now, go to the "Boot" option on the above menu bar and select a device from which you
have to boot. You will see the following two option there:
a. For a USB flash drive, select the Removable Devices option.
b. For a disc installation, select the CD-ROM Drive option.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 10


11. Now, save your setting and press the Enter button to confirm the changes. Now, wait for
your PC to restart.
12. Now, the installation is started. Select your language, time, and currency format on the
Windows setup screen and then click "Next" to continue.

13. You may have to click on several "next" buttons, and finally, you will see the installer
screen. See the below image:

14. Click on the install now button and follow the given instructions to install Windows 10 on
your system successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 11


15. Windows 10 is installed successfully. Now, you will see the Activate Windows screen.
You can enter a key or skip it. If installing Windows 10 automatically detects a key
associated with your PC's hardware, you will not see it on your screen.

16. If you have a valid product key for Windows 10, you can paste it here. You can also paste
a valid Windows 7, 8, or 8.1 key here. You will get the advantage of the free Windows 10
upgrade offer on your PC.
17. After that, you will see a new Windows setup screen "Which type of installation do you
want?" Click "Custom" if you want to perform a clean installation. It will remove
everything on your PC. If you want to upgrade your existing installation, click the
"Upgrade" option.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 12


18. Select the hard drive partition where you want to install Windows. It will delete the data
you have in that partition. Make sure that you have backups of any important files before
doing this.

19. In this installation process, your system may restart several times. At the end of the process,
you will get a new Windows 10 as your operating system.

20. Restart your PC after complete installation. It is now ready to work.

RESULT
Thus, the Windows Operating System has been installed successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 13


Exp. No. 2
Basics of Unix Commands
Date

AIM:
To study the basic Shell Commands in UNIX.

GENERAL PURPOSE COMMANDS

1. date command
Syntax: date
Explanation: The date command is used to display the current date with day of the week,
month, day time (24hr clock) and the year.
Example: 12ee01@localhost]:~ $ date
Output : Wed Feb 10 05:05:44 EST 2010
12ee01@localhost]:~ $

2. echo command
Syntax: echo text
Explanation: The echo command is used to print the message on the screen, whatever is
typed on the line.
Example: 12ee01@localhost]:~ $ echo Akshaya College of Engineering and
Technology
Output : Akshaya College of Engineering and Technology
12ee01@localhost]:~ $

3. banner command
Syntax: banner message
Explanation: The banner command is used to print the message in large letters to give the
impression of a banner.
Example: 12ee01@localhost]:~ $ banner UNIX
Output : 12ee01@localhost]:~ $ banner EEE

### ### ###


# # #
### ### ###
# # #
### ### ###
12ee01@localhost]:~ $

4. cal command
Syntax: cal [month] [year]
Explanation: The calendar (cal) command displays the calendar for the specified month
or year.
Example 1: 12ee01@localhost]:~ $ cal
Output : prints the calendar of the current year.
Example 2: 12ee01@localhost]:~ $ cal 2 2005
Output : February 2005

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 14


Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28
12ee01@localhost]:~ $

5. bc command
Syntax: bc
Explanation: The bc (calculator) command offers an online calculator.
Example: 12ee01@localhost]:~ $ bc

Output : bc 1.06.94
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation,
Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
7+5*2
17
(50-10)*2
80
(Press CTRL d to exit the calculator)
12ee01@localhost]:~ $

6. who command
Syntax: who
Explanation: The who command is used to display data about all the users who are
currently logged into the system.

Command line options


-a displays everything about all users
-b displays the date and time the systems were last
rebooted
-d displays all the dead processes
-H displays verbose column headings
-m displays only your own statistics
-q displays only the number of users and their login names

Example: 12ee01@localhost]:~ $ who


Output : acet tty7 2010-02-10 15:34 (:0)
acet pts/0 2010-02-10 05:05 (:0.0)
12ee01@localhost]:~ $

Example: 12ee01@localhost]:~ $ who –a


Output : system boot 2010-02-10 15:34

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 15


run-level 2 2010-02-10 15:34 last=
LOGIN tty4 2010-02-10 15:34 2103 id=4
LOGIN tty2 2010-02-10 15:34 2110 id=2
acet + tty7 2010-02-10 15:34 old 2837 (:0)
acet + pts/0 2010-02-10 05:05 old 3224 (:0.0)
pts/1 2010-02-10 05:05 0 id=/1 term=0 exit=0
12ee01@localhost]:~ $

Example: 12ee01@localhost]:~ $ who –b


Output : system boot 2010-02-10 15:34
12ee01@localhost]:~ $

Example: 12ee01@localhost]:~ $ who –d


Output : pts/1 2010-02-10 05:05 0 id=/1 term=0 exit=0
12ee01@localhost]:~ $

Example: 12ee01@localhost]:~ $ who –H


Output : NAME LINE TIME COMMENT
acet tty7 2010-02-10 15:34 (:0)
acet pts/0 2010-02-10 05:05 (:0.0)
12ee01@localhost]:~ $

Example: 12ee01@localhost]:~ $ who –m


Output : acet pts/0 2010-02-10 05:05 (:0.0)
12ee01@localhost]:~ $

Example: 12ee01@localhost]:~ $ who –q


Output : acet acet
# users=2
12ee01@localhost]:~ $

7. who am i command
Syntax: who am i
Explanation: The “who am i” command displays the login details of the user.
Example: 12ee01@localhost]:~ $ who am i
Output : acet pts/0 2010-02-10 05:05 (:0.0)
12ee01@localhost]:~ $

8. finger command
Syntax: finger [username]
Explanation: The finger command displays information about the user.
Example: 12ee01@localhost]:~ $ finger acet
Output : Login: acet Name: admin
Directory: /home/acet Shell: /bin/bash
On since Wed Feb 10 15:34 (EST) on tty7 from :0
On since Wed Feb 10 05:05 (EST) on pts/0 from :0.0

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 16


No mail.
No Plan.
12ee01@localhost]:~ $

Note: The finger command without any username will display the information about the all the
users who are currently logged in.

9. id command
Syntax: id
Explanation: The id command displays the numerical value that corresponds to the login
name.
i.e. every user is assigned a user id and group id. These ids are displayed in the id command.
Example: 12ee01@localhost]:~ $ id

Output : uid=1000(acet) gid=1000(acet)


groups=4(adm),20(dialout),24(cdrom),46(plugdev),106(lpadmin),121(admin),
122(sambashare),1000(acet)
12ee01@localhost]:~ $

10. tty command


Syntax: tty
Explanation: The tty(teletype) command is used to find the terminal name that is being
used by the user.
Example: 12ee01@localhost]:~ $ tty
Output : /dev/pts/0
12ee01@localhost]:~ $
11. passwd command
Syntax: passwd
Explanation: The passwd command is used to change the password of the user.
Example: 12ee01@localhost]:~ $ passwd

Output : Changing password for acet.


(current) UNIX password: ******
Enter new UNIX password: **********
Retype new UNIX password: **********
passwd: password updated successfully
12ee01@localhost]:~ $

FILE COMMANDS
1. cat command
Syntax: cat > filename
Explanation: The cat command is used to create a new file.
Example: 12ee01@localhost]:~ $ cat > check1
Hello
(Press CTRL d )
12ee01@localhost]:~ $

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 17


Output : 12ee01@localhost]:~ $ cat check1
Hello
12ee01@localhost]:~ $
2. cat command
Syntax: cat filename
Explanation: The cat command is also used to display the contents of a specified file.
Example: 12ee01@localhost]:~ $ cat check2 (check2 is an existing file)

Output : world
12ee01@localhost]:~ $
3.cat command
Syntax: cat file1 file2 file3 > file_out
Explanation: The cat command can also used to concatenate multiple files into a single
file.
Example: 12ee01@localhost]:~ $ cat check1 check2 > check3
Output : 12ee01@localhost]:~ $ cat check3
hello
world
12ee01@localhost]:~ $
4. cp command
Syntax: cp old_file new_file
Explanation: The cp command is used to copy the contents of one file to another.
Example: 12ee01@localhost]:~ $ cp test1.c test2.c
Output : 12ee01@localhost]:~ $ cat test1.c
#include <stdio.h>
int main()
{
printf(“This is a C file…”);;
return 0;
}
12ee01@localhost]:~ $
12ee01@localhost]:~ $ cat test2.c
#include <stdio.h>
int main()
{
printf(“This is a C file…”);;
return 0;
}
12ee01@localhost]:~ $
Options: -i (used to warn the user before overwriting the destination file).
-R (used to copy entire directory structure).

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 18


5. mv command
Syntax: mv old_filename new_filename
Explanation: The mv command is used to move a file from one place to another. It
removes a specified file from its original location and places it in specified location.
Example: 12ee01@localhost]:~ $ mv test1.c test2.c
Output: Moves the contents of the file test1.c to test2.c

6. rm command
Syntax: rm filename
Explanation: The rm command is used to remove or erase an existing file.
Example: 12ee01@localhost]:~ $ rm test1.c
Output : 12ee01@localhost]:~ $ ls
a a.out check2 dma2.c examples.desktop factorial file1 Pictures sqlll.c swap
test2.c Videos akshaya2.txt check1 Desktop dynamic.c f2 f3 file
fork.c Public sum swapptr.c test.c
12ee01@localhost]:~ $

7. ls command
Syntax: ls
Explanation: The ls command is used to view the contents of a directory.
Example: 12ee01@localhost]:~ $ ls
Output : Displays the list of files and sub-directories in the current directory.
Other examples: 12ee01@localhost]:~ $ ls -x
12ee01@localhost]:~ $ ls -t
12ee01@localhost]:~ $ ls –r
12ee01@localhost]:~ $ ls -A
12ee01@localhost]:~ $ ls -h
12ee01@localhost]:~ $ ls –q
12ee01@localhost]:~ $ ls -l

Options: -x (Displays multi-columnar output)


-t (Lists the files and subdirectories in time order)
-r (lists the files and subdirectories in reverse order)
-A (Lists almost all files)
-a (Lists all the files including hidden files)
-h (Lists the names of hidden files also)
-q (Lists file names with nonprintable characters)
-l (Lists permissions, owner, size, modification time etc)

8. Directing output to a file using ‘>’ operator


Syntax: command > filename
Explanation: The ‘>’ operator can be used to send the output of a command to a file.
Example: 12ee01@localhost]:~ $ ls > addition
Output : 12ee01@localhost]:~ $ cat addition
addition
akshaya1.txt

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 19


biggest
check1

9. wc command
Syntax: wc filename
Explanation: The wc command is used to count the number of words lines and characters
in a file.
Example 1: 12ee01@localhost]:~ $ wc check1
Output : 1 1 6 check1
12ee01@localhost]:~ $

Example 2: 12ee01@localhost]:~ $ wc –l check1


Output : 1 check1
12ee01@localhost]:~ $

Example 3: 12ee01@localhost]:~ $ wc –c check1


Output : 6 check1
12ee01@localhost]:~ $
Options: -l (prints only the number of lines)
-w (prints only the number of words)
-c (prints only the number of characters)

10. file command


Syntax: file filename
Explanation: The file command is used to determine the type of file.
Example 1: 12ee01@localhost]:~ $ file check1
Output : check1: ASCII text
12ee01@localhost]:~ $

Example 2: 12ee01@localhost]:~ $ file fork.c

Output : fork.c: ASCII C program text


12ee01@localhost]:~ $

Example 3: 12ee01@localhost]:~ $ file factorial.abw

Output : factorial.abw: XML document text


12ee01@localhost]:~ $

DIRECTORY COMMANDS

1. mkdir command
Syntax: mkdir dirname
Explanation: The mkdir command is used to create an empty directory in a disk.
Example: 12ee01@localhost]:~ $ mkdir akshaya
Output : 12ee01@localhost]:~ $ ls

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 20


a akshaya1.txt biggest check2 Desktop Documents exec.c factorial.abw
fibo.c filechar.c hello Public sumodd system.c akshaya factorial
file filecopy.c Music reverse sum swap Videos
12ee01@localhost]:~ $

2. pwd command
Syntax: pwd
Explanation: The pwd command is provided to know the current working directory. pwd
is the abbreviation for “print working directory” or “present working directory”.
Example 1: 12ee01@localhost]:~ $ pwd
Output : /home/acet
12ee01@localhost]:~ $

Example 2: 12ee01@localhost]:~ $ cd check


acet@ubuntu:~/check$
acet@ubuntu:~/check$ pwd

Output : /home/acet/check
acet@ubuntu:~/check$

3. rmdir command
Syntax: rmdir dirname
Explanation: The rmdir command is used to remove a directory from the disk. The
command deletes only empty directory.
Example 1: 12ee01@localhost]:~ $ rmdir aaa
Output : removes the directory aaa.
12ee01@localhost]:~ $

Example 2: 12ee01@localhost]:~ $ rmdir akshaya


Output : rmdir: failed to remove `akshaya': Directory not empty
12ee01@localhost]:~ $

12ee01@localhost]:~ $ cd akshaya
acet@ubuntu:~/akshaya$ rm f1
acet@ubuntu:~/akshaya$ cd
12ee01@localhost]:~ $ rmdir akshaya
12ee01@localhost]:~ $

12ee01@localhost]:~ $ ls
a aaa akshaya1.txt biggest check2 Desktop Documents exec.c
factorial.abw fibo.c filechar.c hello Public sumodd system.c factorial
file filecopy.c Music reverse sum swap Videos
12ee01@localhost]:~ $

12ee01@localhost]:~ $ cd aaa
acet@ubuntu:~/aaa$

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 21


acet@ubuntu:~/aaa$ cat > f2
hello world
^Z
acet@ubuntu:~/aaa$

acet@ubuntu:~/aaa$ cd
acet@ubuntu:~/aaa$

12ee01@localhost]:~ $ rmdir aaa


rmdir: failed to remove `aaa': Directory not empty
12ee01@localhost]:~ $

12ee01@localhost]:~ $ rm aaa -r
acet@ubuntu:~$
12ee01@localhost]:~ $ ls
a akshaya1.txt biggest check2 Desktop Documents exec.c factorial.abw
fibo.c filechar.c hello Public sumodd system.c factorial file
filecopy.c Music reverse sum swap Videos
12ee01@localhost]:~ $

4. cd command
Syntax: cd dirname
Explanation: The cd command is used to move from one directory to another.
Example: 12ee01@localhost]:~ $ cd akshaya
Output : acet@ubuntu:~/akshaya$
acet@ubuntu:~/akshaya$ ls
acet@ubuntu:~/akshaya$

acet@ubuntu:~/akshaya$ cat > f1


This is a sample file…
(Press CTRL d)
acet@ubuntu:~/akshaya$
acet@ubuntu:~/akshaya$ ls
f1
acet@ubuntu:~/akshaya$

acet@ubuntu:~/akshaya$ cat f1
This is a sample file…
acet@ubuntu:~/akshaya$

acet@ubuntu:~/akshaya$ cd ..
12ee01@localhost]:~ $

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 22


5. PATH command
Syntax: echo $PATH
Explanation: The PATH command is used to specify the current path of the OS. This is
the sequence of directories the shell searches to look for a command.
Example: acet@ubuntu:~/check$ echo $PATH
Output : /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

6. clear command
Syntax: clear
Explanation: The clear command is used to clear the display screen.
Example: 12ee01@localhost]:~ $ clear
Output : The screen is cleared

RESULT
Thus the basic Unix Commands have been successfully executed.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 23


Exp. No. 3A
The Fork System Call
Date
AIM:
To Write a C program using the fork system call.

ALGORITHM:
Step 1: Start the program.
Step 2: Declare the variable pid.
Step 3: Assign p=fork(c).
Step 4: If pid=0, child process is executed and displays child id and child process id.
Step 5: Else parent process is executed and displays parent process id.
Step 6: Stop the program.

PROGRAM:
// FORK SYSTEM CALL
//vi fork.c
#include<stdio.h>
int main()
{
int pid;
pid = fork();
if(pid==0)
{
printf(" Child process is: %d \n ", getpid());
printf(" Parent process is: %d \n ", getppid());
}
else
{
printf(" Parent process is: %d \n ", getpid());
printf(" Parent of parent process is: %d \n ", getppid());
}
return 0;

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 24


}

OUTPUT:
cse23@localhost cse23]$ cc fork.c
cse23@localhost cse23]$ ./a.out
Child process is: 28054
Parent process is: 28053
Parent process is: 28053
Parent of parent process is: 4659

RESULT:
Thus the C program using fork system call was executed and output is verified
successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 25


Exp. No. 3B
The Exit System Call
Date

AIM
To Write a C program using the exit system call.

ALGORITHM
Step 1: Start the program.
Step 2: Call fork() system call.
Step 3: Pass value more than 255 in exit()
Step 4: Check status and exit.
Step 5: Stop the program.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 26


PROGRAM
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main (void)


{
pid_t pid=fork();
if(pid==0)
{
exit(9999);
}
int status;
waitpid(pid, &status,0);;
if(WIFEXITZEDZ(status))
{
int exit_status=WEXITSTATUS(STATUS);
printf(“Exit code:%d\n”,exit_status);
}
return 0;
}

OUTPUT
Exit code:15

RESULT
Thus the C program using exit system call was executed and output is verified
successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 27


Exp. No. 3C
The Getpid System Call
Date
AIM:
To write C program to implement a getpid system call.

ALGORITHM:
Step 1: Start the program.
Step 2: Declare the variable p and pp.
Step 3: Assign p=getpid( ) and pp=getppid( ).
Step 4: Display child and parent processed.
Step 5: Stop the program.

PROGRAM:
// GETPID SYSTEMCALL
// vi getpid.c
# include<stdio.h>
int main()
{
int p, pp;
p = getpid();
pp = getppid();
printf( " Child process id:%d \n ", p);
printf( " Parent process id:%d \n ", pp);
return 0;
}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 28


OUTPUT:

[cse23@localhost cse23]$ cc getpid.c


[cse23@localhost cse23]$ ./a.out
Child process id: 12347
Parent process id: 5723

RESULT:
Thus the C program to implement getpid system call was executed and output is
verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 29


Exp. No. 3D
Wait System Call
Date
AIM:
To write a C program to implement the wait system call.

ALGORITHM:
Step 1: Start the program.
Step 2: If pid=0 then child process executes.
Step 3: If pid ! = 0 then wait() will make the parent process to wait until the child process
completes its execution.
Step 4: Print the status of the parent and child process.
Step 5: Stop the program.

PROGRAM:
// WAIT SYSTEM CALL
// vi wait.c
#include<stdio.h>
main()
{
int i=0,pid;
printf("Ready to fork\n");
pid=fork();
if(pid==0)
{
printf("Child states\n");
for(i=0;i<10;i++)
printf("%d \t",i);
printf("Child ends\n");
}
else
{
wait(0);

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 30


for(i=0;i<10;i++)
printf("%d \t",i);
printf("Parent process end\n"); }}

OUTPUT:
[cse23@localhost cse23]$ cc wait.c
[cse23@localhost cse23]$ ./a.out
Ready to fork
Child states
0 1 2 3 4 5 6 7 8 9 Child ends
0 1 2 3 4 5 6 7 8 9 Parent process end

RESULT:
Thus the C program to implement wait system call was executed and output is verified
successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 31


Exp. No. 3E
Close System Call
Date

AIM
To write a C program to implement the close system call.
ALGORITHM
Step 1: Start the program.
Step 2: Open a file foo.txt.
Step 3: If fd1<0 = 0 then open the file descriptor table.
Step 4: If (close(fd1) < 0) then close the file descriptor table.
Step 5: Stop the program.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 32


PROGRAM
// C program to illustrate close system Call
#include<stdio.h>
#include <fcntl.h>
int main()
{
int fd1 = open("foo.txt", O_RDONLY);
if (fd1 < 0)
{
perror("c1");
exit(1);
}
printf("opened the fd = % d\n", fd1);

// Using close system Call


if (close(fd1) < 0)
{
perror("c1");
exit(1);
}
printf("closed the fd.\n");
}
OUTPUT
opened the fd = 3
closed the fd.

RESULT
Thus the C program to implement close system call was executed and output is
verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 33


Exp. No. 4A
First Come First Serve Scheduling
Date

AIM:
To write a C program to implement FCFS Scheduling.
ALGORITHM
Step 1: Start the program.
Step 2: Declare the variables.
Step 3: Prompt for number of process from the user.
Step 4: Get the process name and burst time for FCFS.
Step 5: Call the average waiting time and total running time.
Step 6: Set the process.
Step 7: Display the Gantt chart.
Step 8: Stop the program.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 34


PROGRAM
// FCFS SCHEDULING
// vi fcfs.c
#include<stdio.h>
int main(){
char procno[100];
float burst[100];
int num=0,i;
float start=0.00,bt=0.00,avgwait=0.00,wait=0.00;
printf("Enter the number of processes:\n");
scanf("%d",&num);
printf("Enter the name and burst time of the process:\n");
for(i=0;i<num;i++){
scanf("%s",&procno[i]);
scanf("\t%f",&burst[i]);
}
printf("\n\t\t Gantt chart \n");
printf("ProcessName StartTime BurstTime \n");
for(i=0;i<num;i++){
bt=start+burst[i];
printf("%c\t\t%f\t%f\n",procno[i],start,bt);
wait=wait+start;
start=start+burst[i]; }
avgwait=wait/num;
printf("Average waiting time of a process= %f\n",avgwait);
printf("Total running time of process= %f\n",start);
return 0;}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 35


OUTPUT:
cse23@localhost cse23]$ cc fcfs.c
[cse23@localhost cse23]$ ./a.out
Enter the number of processes: 3
Enter the name and burst time of the process:
a 3
b 3
c 12
Gantt chart
ProcessName StartTime BurstTime
a 0.000000 3.000000
b 3.000000 6.000000
c 6.000000 18.000000
Average waiting time of a process= 3.000000
Total running time of process= 18.000000

RESULT:
Thus the C program to implement the first come first serve scheduling was executed
and output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 36


Exp. No. 4B
Shortest Job Fist Scheduling Algorithm
Date
AIM:
To write a C program to implement Shortest Job First Scheduling.

ALGORITHM:
Step 1: Start the program.
Step 2: Declare the variables.
Step 3: Prompt for number of process from the user.
Step 4: Get the process name and start name, burst time for shortest path scheduling.
Step 5: Call the average waiting time, total running time and gantt chart.
Step 6: Set the process.
Step 7: Display the gantt chart.
Step 8: Stop the process.

PROGRAM:
// SJF SCHEDULING
// vi sjf.c
#include<stdio.h>
void swap(int j);
char procno[100];
float burst[100];
int main()
{
int num=0,i;
float start=0.00,bt=0.00,avgwait=0.00,wait=0.00;
printf("Enter the number of processes:\n");
scanf("%d",&num);
printf("Enter the process name and burst time in ms:\n");
for(i=0;i<num;i++)
{
scanf("%s",&procno[i]);

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 37


scanf("%f",&burst[i]);
}
for(i=0;i<num;i++)
{
if(burst[i]>burst[i+1])
{
swap(i);
i=-1;
}
}
printf("\n\t\t Gantt chart \n");
printf("ProcessName StartTime BurstTime \n");
for(i=1;i<=num;i++)
{
bt=start+burst[i];
printf("%c\t\t%f\t%f\n",procno[i],start,bt);
wait=wait+start;
start=start+burst[i];
}
avgwait=wait/num;
printf("Average waiting time of a process= %f\n",avgwait);
printf("Total running time of process= %f\n",start);
return 0;
}
void swap(int j)
{
char temp;
float tbt;
temp=procno[j];
tbt=burst[j];
procno[j]=procno[j+1];

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 38


burst[j]=burst[j+1];
procno[j+1]=temp;
burst[j+1]=tbt;
}

OUTPUT:
[cse23@localhost cse23]$ cc sjf.c
[cse23@localhost cse23]$ ./a.out
Enter the number of processes:
4
Enter the process name and burst time in ms:
a 6
b 8
c 7
d 3
Gantt chart
ProcessName StartTime BurstTime
d 0.000000 3.000000
a 3.000000 9.000000
c 9.000000 16.000000
b 16.000000 24.000000
Average waiting time of a process= 7.000000
Total running time of process= 24.000000

RESULT:
Thus the C program to implement the shortest job first scheduling was executed and
output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 39


Exp. No. 4C
Priority Scheduling
Date

AIM:
To write a C program to implement Priority Scheduling.

ALGORITHM:
Step 1: Start the program.
Step 2: Prompt for number of processor from the user.
Step 3: Get the priority process name, burst time and the corresponding priority of the
process.
Step 4: Sort the process according to the priority and allocate the one with highest
priority to be executed first.
Step 5: If number of process has the same priority then FCFS-scheduling algorithm is
used.
Step 6: Calculate the average waiting time and total running time for the processors.
Step 7: Display the result.
Step 8: Stop the program.

PROGRAM:
// PRIORITY SCHEDULING
// vi priority.c
#include<stdio.h>
void swap(int j);
int priority[100];
char procno[100];
float burst[100];
int main()
{
int num,i;
float start=0.00,bt=0.00,sum=0.00,avgwait,wait=0.00;
printf("Enter the number of processes:\n");
scanf("%d",&num);

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 40


printf("Enter the process name,priority and burst time:\n");
for(i=0;i<num;i++)
{
scanf("%s",&procno[i]);
scanf("\t%d",&priority[i]);
scanf("\t%f",&burst[i]);
}
for(i=0;i<num;i++)
{
if(priority[i]>priority[i+1])
{
swap(i);
i=-1;
}
}
printf("\n\t\t Gantt chart \n\n");
printf("ProcessName\tPriority\tStart\tBurst \n");
for(i=1;i<=num;i++)
{
bt=start+burst[i];
printf("%c\t\t\t%d\t\t%f\t%f\n",procno[i],priority[i],start,bt);
wait=wait+start;
start=start+burst[i];
}
avgwait=wait/num;
printf("Average waiting time of a process= %f\n",avgwait);
printf("Total running time of process= %f\n",start);
return 0;
}
void swap(int j)
{

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 41


char temp;
float tbt;
int pri;
temp=procno[j];
tbt=burst[j];
pri=priority[j];
procno[j]=procno[j+1];
priority[j]=priority[j+1];
burst[j]=burst[j+1];
procno[j+1]=temp;
burst[j+1]=tbt;
priority[j+1]=pri;
}

OUTPUT:
[cse23@localhost cse23]$ cc priority.c
[cse23@localhost cse23]$ ./a.out
Enter the number of processes:
5
Enter the process name, priority and burst time:
a 3 10
b 1 1
c 4 2
d 5 1
e 2 5
Gantt chart
Process Name Priority Start Burst
b 1 0.000000 1.000000
e 2 1.000000 6.000000
a 3 6.000000 16.000000
c 4 16.000000 18.000000

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 42


d 5 18.000000 19.000000
Average waiting time of a process= 8.200000
Total running time of process= 19.000000

RESULT:
Thus the C program to implement the priority scheduling was executed and output is
verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 43


Exp. No. 4D
Round Robin Scheduling
Date
AIM:
To write a C program to implement the Round Robin Scheduling.

ALGORITHM:
Step 1: Start the program.
Step 2: Get the number of processes from user.
Step 3: Get the value for burst time for individual process.
Step 4: If the process burst time is less then time quantum then process is released by
CPU.
Step 5: Calculate the average waiting time and turnaround time of process.
Step 6: Display the result.
Step 7: Stop the program.

PROGRAM:
// ROUND ROBIN SCHEDULING
// vi roundrobin.c
#include<stdio.h>
main()
{
int st[10],bt[10],wt[10],tat[10],n,tq;
int i,count=0,swt=0,stat=0,temp,sq=0;
float awt=0.0,atat=0.0;
printf("Enter number of processes:");
scanf("%d",&n);
printf("Enter burst time for sequences:");
for(i=0;i<n;i++)
{
scanf("\n%d",&bt[i]);
st[i]=bt[i];
}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 44


printf("Enter time quantum:");
scanf("%d",&tq);
while(1)
{
for(i=0,count=0;i<n;i++)
{
temp=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]>tq)
st[i]=st[i]-tq;
else
if(st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq=sq+temp;
tat[i]=sq;
}
if(n==count)
break;
}
for(i=0;i<n;i++)
{
wt[i]=tat[i]-bt[i];
swt=swt+wt[i];
stat=stat+tat[i];

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 45


}
awt=(float)swt/n;
atat=(float)stat/n;
printf("\nProcess_no \tBurst time \tWait time \tTurn around time \n");
for(i=0;i<n;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d ",i+1,bt[i],wt[i],tat[i]);
printf("\n Average wait time is %f\t\n Average turnaround time is %f\t\n",awt,atat); }

OUTPUT:
[cse23@localhost cse23]$ cc roundrobin.c
[cse23@localhost cse23]$ ./a.out
Enter number of processes: 4
Enter burst time for sequences: 5
7
3
9
Enter time quantum: 3
Process_no Burst time Wait time Turn around time
1 5 9 14
2 7 14 21
3 3 6 9
4 9 15 24
Average wait time is 11.000000
Average turnaround time is 17.000000

RESULT:
Thus the C program to implement the round robin scheduling was executed and output
is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 46


Exp. No. 5
Implementation of IPC using PIPE
Date
AIM
To write a program to implement the inter process communication using PIPE.

ALGORITHM
Step1: Start the program.
Step2: Initialize the required variables.
Step3: Create a pipe.
Step4: Send a message to the pipe.
Step5: Retrieve the message from the pipe and write it to the standard output.
Step5: Send another message to the pipe.
Step6: Retrieve the message from the pipe and write it to the standard output.
Step7: Stop the program

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 47


PROGRAM
#include<stdio.h>
#include<unistd.h>
int main()
{
int pipefds[2];
int returnstatus;
char writemessages[2][20]={"Hi", "Hello"};
char readmessage[20];
returnstatus = pipe(pipefds);
if (returnstatus == -1)
{
printf("Unable to create pipe\n");
return 1;
}
printf("Writing to pipe - Message 1 is %s\n", writemessages[0]);
write(pipefds[1], writemessages[0], sizeof(writemessages[0]));
read(pipefds[0], readmessage, sizeof(readmessage));
printf("Reading from pipe – Message 1 is %s\n", readmessage);
printf("Writing to pipe - Message 2 is %s\n", writemessages[0]);
write(pipefds[1], writemessages[1], sizeof(writemessages[0]));
read(pipefds[0], readmessage, sizeof(readmessage));
printf("Reading from pipe – Message 2 is %s\n", readmessage);
return 0;
}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 48


OUTPUT
gcc -o simplepipe simplepipe.c
Writing to pipe - Message 1 is Hi
Reading from pipe – Message 1 is Hi
Writing to pipe - Message 2 is Hi
Reading from pipe – Message 2 is Hell

RESULT
Thus the C program to implement inter process communication using PIPE was
executed and output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 49


Exp. No. 6
Implementation of Producer Consumer Problem using Semaphore
Date

AIM:
To write a C program to implement producer consumer problem using semaphore.

ALGORITHM:
Step1: Start the program.
Step2: Declare the semaphores.
Step3: Get the choice from the user.
Step4: If choice is 1, then producer produces the item when buffer is not full.
Step5: If choice is 2, then consumer consumes the item when buffer is not empty.
Step6: If choice is 3, break the process.
Step7: Display the result.
Step8: Stop the program.

PROGRAM:
// PRODUCER CONSUMER PROBLEM
// vi producerconsumer.c
#include<stdio.h>
#include<stdlib.h>
int mutex=1,full=0,empty=3,x=0;
main()
{
int n;
void producer();
void consumer();
int wait(int);
int signal(int);
printf("\n1.PRODUCER\n2.CONSUMER\n3.EXIT\n");
while(1)
{

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 50


printf("\nENTER YOUR CHOICE\n");
scanf("%d",&n);
switch(n)
{
case 1: if((mutex==1)&&(empty!=0))
producer();
else
printf("BUFFER IS FULL");
break;
case 2: if((mutex==1)&&(full!=0))
consumer();
else
printf("BUFFER IS EMPTY");
break;
case 3: exit(0);
break;
}}}
int wait(int s)
{
return(--s);
}
int signal(int s)
{
return(++s); }
void producer()
{
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
x++;
printf("\nproducer produces the item%d",x);

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 51


mutex=signal(mutex); }
void consumer() {
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\n consumer consumes item%d",x);
x--;
mutex=signal(mutex);
}

OUTPUT:
[cse23@localhost cse23]$ cc producerconsumer.c
[cse23@localhost cse23]$ ./a.out
1. PRODUCER
2. CONSUMER
3. EXIT
ENTER YOUR CHOICE 1
producer produces the item1
ENTER YOUR CHOICE 1
producer produces the item2
ENTER YOUR CHOICE 1
producer produces the item3
ENTER YOUR CHOICE 1
BUFFER IS FULL

ENTER YOUR CHOICE 2


consumer consumes item3
ENTER YOUR CHOICE 2
consumer consumes item2
ENTER YOUR CHOICE 2
consumer consumes item1

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 52


ENTER YOUR CHOICE 2
BUFFER IS EMPTY
ENTER YOUR CHOICE 3

RESULT:
Thus the C program to implement the producer consumer problem was executed and
output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 53


Exp. No. 7
Implementation of Bankers Algorithm for Dead Lock Avoidance
Date

AIM
To write a C program to implement for deadlock avoidance using banker’s algorithm

ALGORITHM
Step 1: Start the program.
Step 2: Get the values of resources and processes.
Step 3: Get the avail value.
Step 4: After allocation find the need value.
Step 5: Check whether it is possible to allocate.
Step 6: If it is possible then the system is in safe state.
Step 7: Else system is not in safety state.
Step 8: If the new request comes then check that the system is in safety.
Step 9: Or if not allow the request.
Step 10: Stop the program.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 54


PROGRAM
#include <stdio.h>
#include <stdlib.h>
int main()
{
int Max[10][10], need[10][10], alloc[10][10], avail[10], completed[10], safeSequence[10];
int p, r, i, j, process, count;
count = 0;
printf("Enter the no of processes : ");
scanf("%d", &p);
for(i = 0; i< p; i++)
completed[i] = 0;
printf("\n\nEnter the no of resources : ");
scanf("%d", &r);
printf("\n\nEnter the Max Matrix for each process : ");
for(i = 0; i < p; i++)
{
printf("\nFor process %d : ", i + 1);
for(j = 0; j < r; j++)
scanf("%d", &Max[i][j]);
}
printf("\n\nEnter the allocation for each process : ");
for(i = 0; i < p; i++)
{
printf("\nFor process %d : ",i + 1);
for(j = 0; j < r; j++)
scanf("%d", &alloc[i][j]);
}
printf("\n\nEnter the Available Resources : ");
for(i = 0; i < r; i++)
scanf("%d", &avail[i]);

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 55


for(i = 0; i < p; i++)
for(j = 0; j < r; j++)
need[i][j] = Max[i][j] - alloc[i][j];
do
{
printf("\n Max matrix:\tAllocation matrix:\n");
for(i = 0; i < p; i++)
{
for( j = 0; j < r; j++)
printf("%d ", Max[i][j]);
printf("\t\t");
for( j = 0; j < r; j++)
printf("%d ", alloc[i][j]);
printf("\n");
}
process = -1;
for(i = 0; i < p; i++)
{
if(completed[i] == 0)//if not completed
{
process = i ;
for(j = 0; j < r; j++)
{
if(avail[j] < need[i][j])
{
process = -1;
break;}}}
if(process != -1)
break;
}
if(process != -1)

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 56


{
printf("\nProcess %d runs to completion!", process + 1);
safeSequence[count] = process + 1;
count++;
for(j = 0; j < r; j++)
{
avail[j] += alloc[process][j];
alloc[process][j] = 0;
Max[process][j] = 0;
completed[process] = 1;}}}
while(count != p && process != -1);
if(count == p)
{
printf("\nThe system is in a safe state!!\n");
printf("Safe Sequence : < ");
for( i = 0; i < p; i++)
printf("%d ", safeSequence[i]);
printf(">\n");
}
else
printf("\nThe system is in an unsafe state!!");
}
OUTPUT:
Enter the no of processes:4
Enter the no ofresource classes:3
Enter the total existed resource in each class:3 2 2
Enter the allocated resources:1 0 0 5 1 1 2 1 1 0 0 2
Enter the process making the new request:2
Enter the requested resource:1 1 2
Enter the process which are n blocked or running:process 2:
1 2
process 4:
1 0
process 5:
1 0
Deadlock will occur

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 57


RESULT:
Thus the C program to implement deadlock avoidance using banker’s algorithm was
executed and output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 58


Exp. No. 8
Implementation of Deadlock Detection Algorithm
Date
AIM:
To write a C program to implement Deadlock Detection algorithm

ALGORITHM:
Step 1: Start the Program
Step 2: Obtain the required data through char and in data types.
Step 3: Enter the filename, index block.
Step 4: Print the file name index loop.
Step 5: File is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

PROGRAM:
//Deadlock Detection algorithm implementation

#include <stdio.h>
#include <conio.h>
void main()
{
int found,flag,l,p[4][5],tp,tr,c[4][5],i,j,k=1,m[5],r[5],a[5],temp[5],sum=0;
clrscr();
printf("Enter total no of processes");
scanf("%d",&tp);
printf("Enter total no of resources");
scanf("%d",&tr);
printf("Enter claim (Max. Need) matrix\n");
for(i=1;i<=tp;i++)
{
printf("process %d:\n",i);
for(j=1;j<=tr;j++)
scanf("%d",&c[i][j]);
}
printf("Enter allocation matrix\n");
for(i=1;i<=tp;i++)
{
printf("process %d:\n",i);
for(j=1;j<=tr;j++)
scanf("%d",&p[i][j]);

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 59


}
printf("Enter resource vector (Total resources):\n");
for(i=1;i<=tr;i++)
{
scanf("%d",&r[i]);
}
printf("Enter availability vector (available resources):\n");
for(i=1;i<=tr;i++)
{
scanf("%d",&a[i]);
temp[i]=a[i];
}
for(i=1;i<=tp;i++)
{
sum=0;
for(j=1;j<=tr;j++)
{
sum+=p[i][j];
}
if(sum==0)
{
m[k]=i; k++;
}
}
for(i=1;i<=tp;i++)
{
for(l=1;l<k;l++)
if(i!=m[l])
{
flag=1;
for(j=1;j<=tr;j++)
if(c[i][j]<temp[j])
{
flag=0;
break;
}
}
if(flag==1)
{
m[k]=i;
k++;
for(j=1;j<=tr;j++)
temp[j]+=p[i][j];
}
}
printf("deadlock causing processes are:");

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 60


for(j=1;j<=tp;j++)
{
found=0;
for(i=1;i<k;i++)
{
if(j==m[i])
found=1;
}
if(found==0)
printf("%d\t",j);
}
getch();
}

OUTPUT:

Enter total no. of processes : 4


Enter total no. of resources : 5
Enter claim (Max. Need) matrix : 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 0 1
Enter allocation matrix : 1 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0
Enter resource vector (Total resources) : 2 1 1 2 1
Enter availability vector (available resources) : 0 0 0 0 1
deadlock causing processes are : 2 3

RESULT:

Thus the program was executed successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 61


Exp. No. 9
Implement Threading & Synchronization Applications
Date

AIM
To write a C program to implement the threading and synchronization applications.

ALGORITHM
Step1: Start the program.
Step 2: Enter the page size.
Step 3: Enter the logical memory address.
Step 4: Enter the user data.
Step 5: Enter starting position of each page.
Step 6: Enter data to which mapping address to be found.
Step 7: Calculate and display the physical address for the corresponding logical address.
Step 8: Stop the program

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 62


PROGRAM:
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_t tid[2];
int counter;
void* doSomeThing(void *arg)
{
unsigned long i = 0;
counter += 1;
printf("\n Job %d started\n", counter);
for(i=0; i<(0xFFFFFFFF);i++);
printf("\n Job %d finished\n", counter);
return NULL;
}
int main(void){
int i = 0;
int err;
while(i < 2){
err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL);
if (err != 0)
printf("\ncan't create thread :[%s]", strerror(err));
i++;}
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
return 0;}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 63


OUTPUT

1 2 3 4 5 6 7 8 9 10

RESULT
Thus a C program to implement the threading and synchronization applications
was executed and output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 64


Exp. No. 10
Memory Management Scheme using Paging
Date

AIM:
To write a C program to implement the memory management scheme using paging.

ALGORITHM:
Step1: Start the program.
Step 2: Enter the page size.
Step3: Enter the logical memory address.
Step 3: Enter the user data.
Step 4: Enter starting position of each page.
Step5: Enter data to which mapping address to be found.
Step 5: Calculate and display the physical address for the corresponding logical address.
Step 7: Stop the program.

PROGRAM:
#include<stdio.h>
void main()
{
int a[20],lmem,pmem,ch,psize,str,b[35],c[10];
int i,j,k,INDEX,page,frame,addr;
printf("\nEnter page size: ");
scanf("%d",&psize);
printf("\nEnter logical memory in bytes: ");
scanf("%d",&lmem);
printf("\nEnter physical memory: ");
scanf("%d",&pmem);
printf("\nEnter user data: ");
for(i=0;i<lmem;i++)
scanf("%d",&a[i]);
for(i=0;i<32;i++)

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 65


{
b[i]=-1;
}
for(i=0;i<lmem/psize;i++)
{
printf("\nEnter starting position of each page:");
scanf("%d",&str);
c[i]=str/4;
for(j=str,k=i*psize;j<(str+psize),k<(i*psize)+psize;j++,k++)
{
b[j]=a[k];
}
}
for(i=0;i<pmem;i++)
{
printf("\n%d",b[i]);
}
printf("\nEnter dat to which mapping addr to be found: ");
scanf("%d",&ch);
for(i=0;i<lmem;i++)
{
if(ch==a[i])
{
INDEX=i;
page=INDEX/psize;
frame=c[page];
addr=(frame*psize)+(INDEX%psize);
}
}
printf("\nThe physical addr for %d is %d ",ch,addr);
}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 66


OUTPUT:
[osslab@fosslab ~]$ vi pp.c
[osslab@fosslab ~]$ cc pp.c
[osslab@fosslab ~]$ ./a.out
Enter page size: 4
Enter logical memory in bytes: 3
Enter physical memory: 4
Enter user data: 1
2
3

-1
-1
-1
-1
Enter data to which mapping addr to be found: 3
The physical address of 3 is 11
[osslab@fosslab ~]$

RESULT:
Thus the C program to implement the memory management scheme using paging
algorithm was executed and output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 67


Exp. No. 11A
Implementation of First Fit Algorithm
Date
AIM:
To write a C program to implement the memory management scheme using first fit algorithm.

ALGORITHM:
Step1: Start the program.
Step2: Declare the size.
Step3: Get number of process to be inserted.
Step4: Allocate the first hole that is big enough searching.
Step5: Start at the beginning of the set of holes.
Step6: If not start at the hole that is sharing the previous first fit search end.
Step7: Compare the hole.
Step8: If large enough then stop searching in the procedure.
Step9: Display the value.
Step10: Stop the program.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 68


PROGRAM:
// FIRST FIT ALGORITHM
// vi firstfit.c
#include<stdio.h>
void main()
{
int bsize[10], psize[10], bno, pno, flags[10], allocation[10], i, j;
for(i = 0; i < 10; i++)
{
flags[i] = 0;
allocation[i] = -1;
}
printf("Enter no. of blocks: ");
scanf("%d", &bno);
printf("\nEnter size of each block: ");
for(i = 0; i < bno; i++)
scanf("%d", &bsize[i]);
printf("\nEnter no. of processes: ");
scanf("%d", &pno);
printf("\nEnter size of each process: ");
for(i = 0; i < pno; i++)
scanf("%d", &psize[i]);
//allocation according to first fit logic
for(i = 0; i < pno; i++)
for(j = 0; j < bno; j++)
if(flags[j] == 0 && bsize[j] >= psize[i])
{
allocation[j] = i;
flags[j] = 1;
break;
}
//display allocation details of processes in blocks
printf("\nBlock no.\tsize\t\tprocess no.\t\tsize");
for(i = 0; i < bno; i++)

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 69


{
printf("\n%d\t\t%d\t\t", i+1, bsize[i]);
if(flags[i] == 1)
printf("%d\t\t\t%d",allocation[i]+1,psize[allocation[i]]);
else
printf("Not allocated");
}
}

OUTPUT:

RESULT:
Thus the C program to implement the memory management scheme using first fit
algorithm was executed and output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 70


Exp. No. 11B
Implementation of Worst Fit Algorithm
Date

AIM:
To write a C program to implement the memory management scheme using worst fit algorithm.

ALGORITHM:
Step1: Start the program.
Step2: Declare the size.
Step3: Get number of process to be inserted.
Step4: Allocate the first hole that is big enough searching.
Step5: Start at the beginning of the set of holes.
Step6: If not start at the hole that is sharing the previous first fit search end.
Step7: Compare the hole.
Step8: If large enough then stop searching in the procedure.
Step9: Display the value.
Step10: Stop the program.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 71


PROGRAM:
// WORST FIT ALGORITHM
// vi worstfit.c
#include<stdio.h>
int main()
{
int fragments[10], blocks[10], files[10];
int m, n, number_of_blocks, number_of_files, temp, top = 0;
static int block_arr[10], file_arr[10];
printf("\nEnter the Total Number of Blocks:\t");
scanf("%d",&number_of_blocks);
printf("Enter the Total Number of Files:\t");
scanf("%d",&number_of_files);
printf("\nEnter the Size of the Blocks:\n");
for(m = 0; m < number_of_blocks; m++)
{
printf("Block No.[%d]:\t", m + 1);
scanf("%d", &blocks[m]);
}
printf("Enter the Size of the Files:\n");
for(m = 0; m < number_of_files; m++)
{
printf("File No.[%d]:\t", m + 1);
scanf("%d", &files[m]);
}
for(m = 0; m < number_of_files; m++)
{
for(n = 0; n < number_of_blocks; n++)
{
if(block_arr[n] != 1)
{
temp = blocks[n] - files[m];
if(temp >= 0)
{

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 72


if(top < temp)
{
file_arr[m] = n;
top = temp;
}
}
}
fragments[m] = top;
block_arr[file_arr[m]] = 1;
top = 0;
}
}
printf("\nFile Number\tFile Size\tBlock Number\tBlock Size\tFragment");
for(m = 0; m < number_of_files; m++)
{
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d", m, files[m], file_arr[m], blocks[file_arr[m]],
fragments[m]);
}
printf("\n");
return 0;
}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 73


OUTPUT:

RESULT:
Thus a C program to implement the memory management scheme using worst fit algorithm
was executed and output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 74


Exp. No. 11C
Implementation of Best Fit Algorithm
Date
AIM:
To write a program to implement the memory management scheme using best fit
algorithm.

ALGORITHM:
Step1: Start the process
Step2: Declare the size
Step3: Give the number of processes to be inserted
Step4: Allocate the first block that is big enough searching
Step5: Start at the beginning of the set of blocks
Step6: If not start at the block that is sharing the pervious first fit search end
Step7: Compare the block
Step8: if large enough then stop searching in the procedure
Step9: Display the values
Step10: Stop the process

PROGRAM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
static int bf[max],ff[max];
printf("\n\t Best Fit algorithm");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 75


for(i=1;i<=nb;i++) {printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0) if(lowest>temp)
{
ff[i]=j;
lowest=temp;
}
}
}
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");

for(i=1;i<=nf && ff[i]!=0;i++)


printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 76


getch();
return 0;
}

OUTPUT:

RESULT:
Thus a C program to implement the memory management scheme using best fit
algorithm was executed and output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 77


Exp. No. 12A
Implementation of Page Replacement Algorithm (FIFO)
Date
AIM
To write a program to implement FIFO page replacement algorithm.

ALGORITHM
Step 1: Start the process
Step 2: Declare the size with respect to page length
Step 3: Check the need of replacement from the page to memory
Step 4: Check the need of replacement from old page to new page in memory
Step 5: Forma queue to hold all pages
Step 6: Insert the page require memory into the queue
Step 7: Check for bad replacement and page fault
Step 8: Get the number of processes to be inserted
Step 9: Display the values
Step 10: Stop the process

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 78


PROGRAM:
#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n enter the number of pages:\n");
scanf("%d",&n);
printf("\n enter the page number:\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\n enter the number of frames:\n");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]=-1;
j=0;
printf("\tref string\t page frmaes\n");
for(i=1;i<=n;i++)
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if(avail==0)
{ frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 79


}
printf("page fault is %d",count);
getch();
return 0;
}

OUTPUT:
Enter the number of pages:
4
enter the reference string:
7
2
1
0
enter the number of frames:
3
ref string page frmaes
7 7 -1 -1
2 7 2 -1
1721
0021
page fault is 4

RESULT:

The program for FIFO page replacement was implemented and hence verified

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 80


Exp. No. 12B Implementation of Page Replacement Algorithm (LRU)
Date
AIM
To write a program a program to implement LRU page replacement algorithm.

ALGORITHM
Step 1: Start the process
Step 2: Declare the size
Step 3: Get the number of pages to be inserted
Step 4: Get the value
Step 5: Declare counter and stack
Step 6: Select the least recently used page by counter value
Step 7: Stack them according the selection.
Step 8: Display the values
Step 9: Stop the process

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 81


PROGRAM
#include<stdlib.h>
#include<stdio.h>
#define max 100
#define min 10
int ref[max],count,frame[min],n;
void input()
{
int i,temp;
count=0;
printf("\n\n\tEnter the number of page frames : ");
scanf("%d",&n);
printf("\n\n\tEnter the reference string (-1 for end) : ");
scanf("%d",&temp);
while(temp != -1)
{
ref[count++]=temp;
scanf("%d",&temp);
}
}
void LRU()
{
int i,j,k,stack[min],top=0,fault=0;
system("CLS");
for(i=0;i<count;i++)
{
if(top<n)
stack[top++]=ref[i],fault++;
else
{
for(j=0;j<n;j++)

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 82


if(stack[j]==ref[i])
break;
if(j<n)
{
for(k=j;k<n-1;k++)
stack[k]=stack[k+1];
stack[k]=ref[i];
}
else
{
for(k=0;k<n-1;k++)
stack[k]=stack[k+1];
stack[k]=ref[i];
fault++;
}
}
printf("\n\nAfter inserting %d the stack status is : ",ref[i]);
for(j=0;j<top;j++)
printf("%d ",stack[j]);
}
printf("\n\n\tEnd to inserting the reference string.");
printf("\n\n\tTotal page fault is %d.",fault);
printf("\n\n\tPress any key to continue.");
}
void main()
{
int x;
//freopen("in.cpp","r",stdin);
while(1)
{
printf("\n\n\t-----MENU ---- ");

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 83


printf("\n\t1. Input ");
printf("\n\t2. LRU (Least Recently Used) Algorithm");
printf("\n\t0. Exit.");
printf("\n\n\tEnter your choice.");
scanf("%d",&x);
switch(x)
{
case 1:
input();
break;
case 2:
LRU();
break;
case 0:
exit(0);
}
}
}

OUTPUT:
MENU
1. Input
2. LRU (Least Recently Used) Algorithm
0. Exit.
Enter your choice.1
Enter the number of page frames : 3
Enter the reference string (-1 for end) : 2
0
1
1
-1
MENU
1. Input
2. LRU (Least Recently Used) Algorithm
0. Exit.
Enter your choice.2
After inserting 2 the stack status is : 2

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 84


After inserting 0 the stack status is : 2 0
After inserting 1 the stack status is : 2 0 1
After inserting 1 the stack status is : 2 0 1
End to inserting the reference string.
Total page fault is 3.
Press any key to continue.
MENU
1. Input
2. LRU (Least Recently Used) Algorithm
0. Exit.
Enter your choice.0

RESULT:

The program for LRU page replacement was implanted and hence verified.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 85


Exp. No. 12C Implementation of Page Replacement Algorithm using Least
Date Frequently Used Algorithm
AIM
To write a program to implement LFU page replacement algorithm

ALGORITHM
Step 1: Start the process
Step 2: Declare the size
Step 3: Get the number of pages to be inserted
Step 4: Get the value
Step 5: Declare counter and stack
Step 6: Select the least frequently used page by counter value
Step 7: Stack them according the selection.
Step 8: Display the values
Step 9: Stop the process

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 86


PROGRAM:
#include<stdio.h>
int main()
{
int total_frames, total_pages, hit = 0;
int pages[25], frame[10], arr[25], time[25];
int m, n, page, flag, k, minimum_time, temp;
printf("Enter Total Number of Pages:\t");
scanf("%d", &total_pages);
printf("Enter Total Number of Frames:\t");
scanf("%d", &total_frames);
for(m = 0; m < total_frames; m++)
{
frame[m] = -1;
}
for(m = 0; m < 25; m++)
{
arr[m] = 0;
}
printf("Enter Values of Reference String\n");
for(m = 0; m < total_pages; m++)
{
printf("Enter Value No.[%d]:\t", m + 1);
scanf("%d", &pages[m]);
}
printf("\n");
for(m = 0; m < total_pages; m++)
{
arr[pages[m]]++;
time[pages[m]] = m;
flag = 1;

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 87


k = frame[0];
for(n = 0; n < total_frames; n++)
{
if(frame[n] == -1 || frame[n] == pages[m])
{
if(frame[n] != -1)
{
hit++;
}
flag = 0;
frame[n] = pages[m];
break;
}
if(arr[k] > arr[frame[n]])
{
k = frame[n];
}
}
if(flag)
{
minimum_time = 25;
for(n = 0; n < total_frames; n++)
{
if(arr[frame[n]] == arr[k] && time[frame[n]] < minimum_time)
{
temp = n;
minimum_time = time[frame[n]];
} }
arr[frame[temp]] = 0;
frame[temp] = pages[m];
}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 88


for(n = 0; n < total_frames; n++)
{
printf("%d\t", frame[n]);
}
printf("\n");
}
printf("Page Hit:\t%d\n", hit);
return 0; }

OUTPUT:

RESULT:
Thus the experiment was successfully compiled and executed

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 89


Exp. No. 13A Implementation of File Organization Techniques using Single
Date Level Directory
AIM :
To write a C program to implement File Organization concept using the technique Single
level directory.

ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,index block.
Step 4: Print the file name index loop.
Step 5:Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,count,i,j,mid,cir_x;
char fname[10][20];
clrscr();
initgraph(&gd,&gm,"c:\tc\bgi");
cleardevice();
setbkcolor(GREEN);
puts("Enter no of files do u have?");
scanf("%d",&count);
for(i=0;i<count;i++)
{ cleardevice();
setbkcolor(GREEN);
printf("Enter file %d name",i+1);
scanf("%s",fname[i]);
setfillstyle(1,MAGENTA);
mid=640/count; cir_x=mid/3;
bar3d(270,100,370,150,0,0);
settextstyle(2,0,4);
settextjustify(1,1);
outtextxy(320,125,"Root Directory");
setcolor(BLUE);
for(j=0;j<=i;j++,cir_x+=mid)
{
line(320,150,cir_x,250);
fillellipse(cir_x,250,30,30);

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 90


outtextxy(cir_x,250,fname[j]);
} getch();
}}

OUTPUT

RESULT
Thus files were organized into a single level directory.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 91


Exp. No. 13B Implementation of File Organization Techniques using Two Level
Date Directory
AIM:
To write a C program to implement File Organization concept using the technique two level
directory

ALGORITHM:
Step 1: Start the Program
Step 2: Obtain the required data through char and in datatypes.
Step 3: Enter the filename, index block.
Step 4: Print the file name index loop.
Step 5: File is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

PROGRAM:
#include<stdio.h>
#include<graphics.h>
struct tree_element
{
char name[20];
int x,y,ftype,lx,rx,nc,level;
struct tree_element *link[5];
};
typedef struct tree_element node;
void main()
{
int gd=DETECT,gm;
node *root;
root=NULL;
clrscr();
create(&root,0,"null",0,639,320);
clrscr();

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 92


initgraph(&gd,&gm,"c:\\tc\\bgi");
display(root);
getch(); closegraph();
}
create(node **root,int lev,char *dname,int lx,int rx,int x)
{
int i,gap;
if(*root==NULL)
{
(*root)=(node*)malloc(sizeof(node));
printf("enter name of dir/file(under %s):",dname);
fflush(stdin);
gets((*root)->name);
if(lev==0||lev==1)
(*root)->ftype=1;
else (*root)->ftype=2;
(*root)->level=lev;
(*root)->y=50+lev*50;
(*root)->x=x;
(*root)->lx=lx;
(*root)->rx=rx;
for(i=0;i<5;i++)
(*root)->link[i]=NULL;
if((*root)->ftype==1)
{
if(lev==0||lev==1)
{
if((*root)->level==0)
printf("How many users");
else
printf("hoe many files");
printf("(for%s):",(*root)->name);
scanf("%d",&(*root)->nc);

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 93


}
else (*root)->nc=0;
if((*root)->nc==0)
gap=rxlx;
else
gap=(rx-lx)/(*root)->nc;
for(i=0;i<(*root)->nc;i++)
create(&((*root)->link[i]),lev+1,(*root)->name,lx+gap*i,lx+gap*i+gap,lx+gap*i+gap/2);
}
else (*root)->nc=0; } }
display(node *root)
{
int i; settextstyle(2,0,4);
settextjustify(1,1);
setfillstyle(1,BLUE);
setcolor(14);
if(root!=NULL)
{
for(i=0;i<root->nc;i++)
{
line(root->x,root->y,root->link[i]->x,root->link[i]->y);
}
if(root->ftype==1)
bar3d(root->x-20,root->y-10,root->x+20,root->y+10,0,0);
else
fillellipse(root->x,root->y,20,20);
outtextxy(root->x,root->y,root->name);
for(i=0;i<root->nc;i++)
{
display(root->link[i]);
}}}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 94


OUTPUT:

RESULT
Thus user files have been stored in their respective directories and retrieved
easily.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 95


Exp. No. 13C Implementation of File Organization Techniques using
Date Hierarchical Level Directory
AIM
To write a C program to implement File Organization concept using the technique
hierarchical level directory.

ALGORITHM:

Step 1: Start the Program


Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,index block.
Step 4: Print the file name index loop.
Step 5:Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 96


PROGRAM :
#include<stdio.h>
#include<graphics.h>
struct tree_element
{
char name[20];
int x,y,ftype,lx,rx,nc,level;
struct tree_element *link[5];
};
typedef struct tree_element node;
void main()
{
int gd=DETECT,gm;
node *root;
root=NULL;
clrscr();
create(&root,0,"root",0,639,320);
clrscr();
initgraph(&gd,&gm,"c:\tc\BGI");
display(root); getch(); closegraph();
}
create(node **root,int lev,char *dname,int lx,int rx,int x)
{
int i,gap;
if(*root==NULL)
{ (*root)=(node *)malloc(sizeof(node));
printf("Enter name of dir/file(under %s) : ",dname);
fflush(stdin);
gets((*root)->name);
printf("enter 1 for Dir/2 for file :");
scanf("%d",&(*root)->ftype);

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 97


(*root)->level=lev;
(*root)->y=50+lev*50;
(*root)->x=x;
(*root)->lx=lx;
(*root)->rx=rx;
for(i=0;i<5;i++)
(*root)->link[i]=NULL;
if((*root)->ftype==1)
{
printf("No of sub directories/files(for %s):",(*root)->name);
scanf("%d",&(*root)>nc);
if((*root)->nc==0) gap=rx-lx;
else gap=(rx-lx)/(*root)->nc;
for(i=0;i<(*root)->nc;i++)
create(&((*root)>link[i]),lev+1,(*root)>name,lx+gap*i,lx+gap*i+gap,lx+gap*i+gap/2);
}
else (*root)->nc=0;
}
}
display(node *root)
{
int i;
settextstyle(2,0,4);
settextjustify(1,1);
setfillstyle(1,BLUE);
setcolor(14);
if(root !=NULL)
{
for(i=0;i<root->nc;i++)
{
line(root->x,root->y,root->link[i]->x,root->link[i]->y);

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 98


}
if(root->ftype==1)
bar3d(root->x-20,root->y-10,root->x+20,root>y+10,0,0);
else fillellipse(root->x,root->y,20,20);
outtextxy(root->x,root->y,root->name);
for(i=0;i<root->nc;i++)
{
display(root->link[i]); } } }

OUTPUT:

RESULT:
Thus the program to implement File Organization concept using the technique
hierarchical level directory was executed successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 99


Exp. No. 13D
Implementation of File Organization Techniques Using DAG
Date
AIM
To write a C program to implement File Organization concept using the technique
DAG.

ALGORITHM
Step 1: Start the Program
Step 2: Obtain the required data through char and int datatypes.
Step 3: Enter the filename, index block.
Step 4: Print the file name index loop.
Step 5: File is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 100


PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<string.h>
struct tree_element
{
char name[20];
int x,y,ftype,lx,rx,nc,level;
struct tree_element *link[5];
};
typedef struct tree_element node;
typedef struct
{
char from[20];
char to[20];
}link;
link L[10];
int nofl;
node * root;
void main()
{
int gd=DETECT,gm;
root=NULL;
clrscr();
create(&root,0,"root",0,639,320);
read_links();
clrscr();
initgraph(&gd,&gm,"c:\tc\BGI");
draw_link_lines();
display(root);

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 101


getch();
closegraph();
}
read_links()
{
int i;
printf("how many links");
scanf("%d",&nofl);
for(i=0;i<nofl;i++)
{
printf("File/dir:");
fflush(stdin);
gets(L[i].from);
printf("user name:");
fflush(stdin);
gets(L[i].to);
}
}
draw_link_lines()
{
int i,x1,y1,x2,y2;
for(i=0;i<nofl;i++)
{
search(root,L[i].from,&x1,&y1);
search(root,L[i].to,&x2,&y2);
setcolor(LIGHTGREEN);
setlinestyle(3,0,1);
line(x1,y1,x2,y2);
setcolor(YELLOW);
setlinestyle(0,0,1);
}}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 102


search(node *root,char *s,int *x,int *y)
{
int i;
if(root!=NULL)
{
if(strcmpi(root->name,s)==0)
{
*x=root->x;
*y=root->y;
return;
}
else
{
for(i=0;i<root->nc;i++)
search(root->link[i],s,x,y);
}
}
}
create(node **root,int lev,char *dname,int lx,int rx,int x)
{
int i,gap;
if(*root==NULL)
{
(*root)=(node *)malloc(sizeof(node));
printf("enter name of dir/file(under %s):",dname);
fflush(stdin);
gets((*root)->name);
printf("enter 1 for dir/ 2 for file:");
scanf("%d",&(*root)- >ftype);
(*root)->level=lev;
(*root)->y=50+lev*50;

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 103


(*root)->x=x;
(*root)->lx=lx;
(*root)->rx=rx;
for(i=0;i<5;i++)
(*root)->link[i]=NULL;
if((*root)->ftype==1)
{
printf("no of sub directories /files (for %s):",(*root)->name);
scanf("%d",&(*root)->nc);
if((*root)->nc==0)
gap=rx-lx;
else
gap=(rx-lx)/(*root)->nc;
for(i=0;i<(*root)->nc;i++)
create( & ( (*root)->link[i] ) , lev+1 , (*root)-
>name,lx+gap*i,lx+gap*i+gap,lx+gap*i+gap/2);
}
else
(*root)->nc=0;
}
} /* displays the constructed tree in graphics mode */
display(node *root)
{
int i;
settextstyle(2,0,4);
settextjustify(1,1);
setfillstyle(1,BLUE);
setcolor(14);
if(root !=NULL)
{
for(i=0;i<root->nc;i++)

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 104


{
line(root->x,root->y,root->link[i]->x,root->link[i]->y);
}
if(root->ftype==1)
bar3d(root->x-20,root->y-10,root->x+20,root->y+10,0,0);
else
fillellipse(root->x,root->y,20,20);
outtextxy(root->x,root->y,root- >name);
for(i=0;i<root->nc;i++)
{
display(root->link[i]);
}
}
}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 105


OUTPUT:

RESULT:
Thus the program to implement File Organization concept using the technique DAG was
executed successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 106


Exp. No. 14A
Implementation of Sequential File Allocation Strategies
Date
AIM
To write a C program to implement File Allocation Strategies.

ALGORITHM
Step 1: Start the program.
Step 2: Get the number of files.
Step 3: Get the memory requirement of each file.
Step 4: Allocate the required locations to each in sequential order.
a). Randomly select a location from available location s1= random (100);
b). Check whether the required locations are free from the selected location.
c). Allocate and set flag=1 to the allocated locations.
Step 5: Print the results file no., length, Blocks allocated.
Step 6: Stop the program.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 107


PROGRAM:
#include<stdio.h>
#include<conio.h>
main(){
int f[50],i,st,j,len,c,k;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
X:
printf("\n Enter the starting block & length of file");
scanf("%d%d",&st,&len);
for(j=st;j<(st+len);j++)
if(f[j]==0){
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else{
printf("Block already allocated");
break;}
if(j==(st+len))
printf("\n the file is allocated to disk");
printf("\n if u want to enter more files?(y-1/n-0)");
scanf("%d",&c);
if(c==1)
goto X;
else
exit();
getch(); }

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 108


OUTPUT:

RESULT:
Thus the C program to implement the Sequential file allocation strategies was
executed and output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 109


Exp. No. 14B
Implementation of Indexed File Allocation Strategies
Date
AIM
To write a C program to implement File Allocation Strategies.

ALGORITHM:
Step 1: Start the Program
Step 2: Obtain the required data through char and int datatypes.
Step 3: Enter the filename, index block.
Step 4: Print the file name index loop.
Step 5: Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 110


PROGRAM:
//Indexed File Allocation Program:
#include<stdio.h>
int f[50],i,k,j,inde[50],n,c,count=0,p;
main()
{
clrscr();
for(i=0;i<50;i++)
f[i]=0;
x:
printf("enter index block\t");
scanf("%d",&p);
if(f[p]==0)
{
f[p]=1;
printf("enter no of files on index\t");
scanf("%d",&n);
}
else
{
printf("Block already allocated\n");
goto x;
}
for(i=0;i<n;i++)
scanf("%d",&inde[i]);
for(i=0;i<n;i++)
if(f[inde[i]]==1)
{
printf("Block already allocated");
goto x;
}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 111


for(j=0;j<n;j++)
f[inde[j]]=1;
printf("\n allocated");
printf("\n file indexed");
for(k=0;k<n;k++)
printf("\n %d->%d:%d",p,inde[k],f[inde[k]]);
printf(" Enter 1 to enter more files and 0 to exit\t");
scanf("%d",&c);
if(c==1)
goto x;
else
exit();
getch();
}

OUTPUT:

RESULT:
Thus the C program to implement the Indexed file allocation strategies was executed
and output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 112


Exp. No. 14C
Implementation of Linked File Allocation Strategies
Date
AIM
To write a C program to implement Linked File Allocation Strategies.

ALGORITHM:
Step 1: Start the Program
Step 2: Obtain the required data through char and int datatypes.
Step 3: Enter the filename, starting block ending block.
Step 4: Print the free block using loop.
Step 5: ‟for‟ loop is created to print the file utilization of linked type of entered type.
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 113


PROGRAM
//Linked File Allocation Program:
#include<STDIO.H>
main()
{
int f[50],p,i,j,k,a,st,len,n,c;
for(i=0;i<50;i++)
f[i]=0;
printf("Enter how many blocks that are already allocated");
scanf("%d",&p);
printf("\nEnter the blocks no.s that are already allocated");
for(i=0;i<p;i++)
{
scanf("%d",&a);
f[a]=1;
}
X:
printf("Enter the starting index block & length");
scanf("%d%d",&st,&len);
k=len;
for(j=st;j<(k+st);j++)
{
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("\n %d->file is already allocated",j);
k++;

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 114


}
}
printf("\n If u want to enter one more file? (yes-1/no-0)");
scanf("%d",&c);
if(c==1)
goto X;
}
OUTPUT:

RESULT:
Thus the C program to implement the Linked file allocation strategies was executed
and output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 115


Exp. No. 15A
Implementation of FCFS Disk Scheduling Algorithm
Date
AIM
To write a C program to implement FCFS Disk Scheduling Algorithm.

ALGORITHM:
Step 1: Start the program.
Step 2: Declare the variables.
Step 3: Prompt for current position.
Step 4: Get the number of requests for FCFS.
Step 5: Get the request order.
Step 6: Calculate the absolute value.
Step 7: Display the total head movement.
Step 8: Stop the program.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 116


PROGRAM
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,n,req[50],mov=0,cp;
printf("enter the current position\n");
scanf("%d",&cp);
printf("enter the number of requests\n");
scanf("%d",&n);
printf("enter the request order\n");
for(i=0;i<n;i++)
{
scanf("%d",&req[i]);
}
mov=mov+abs(cp-req[0]); // abs is used to calculate the absolute value
printf("%d -> %d",cp,req[0]);
for(i=1;i<n;i++)
{
mov=mov+abs(req[i]-req[i-1]);
printf(" -> %d",req[i]);
}
printf("\n");
printf("total head movement = %d\n",mov);
}

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 117


OUTPUT

RESULT
Thus a C program to implement FCFS Disk Scheduling Algorithm was executed and
output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 118


Exp. No. 15B
Implementation of SSTF Disk Scheduling Algorithm
Date
AIM
To write a C program to implement SSTF Disk Scheduling Algorithm.

ALGORITHM:
Step 1: Start the program.
Step 2: Declare the variables.
Step 3: Prompt for current position.
Step 4: Get the number of requests for SSTF.
Step 5: Get the request order.
Step 6: Calculate distance of each request from current position.
Step 7: Find the nearest request.
Step 8: Change the current position value to next request.
Step 9: Display the total head movement.
Step 10: Stop the program.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 119


PROGRAM
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,n,k,req[50],mov=0,cp,index[50],min,a[50],j=0,mini,cp1;
printf("enter the current position\n");
scanf("%d",&cp);
printf("enter the number of requests\n");
scanf("%d",&n);
cp1=cp;
printf("enter the request order\n");
for(i=0;i<n;i++)
{
scanf("%d",&req[i]);
}
for(k=0;k<n;k++)
{
for(i=0;i<n;i++)
{
index[i]=abs(cp-req[i]); // calculate distance of each request from current position
}
// to find the nearest request
min=index[0];
mini=0;
for(i=1;i<n;i++)
{
if(min>index[i])
{
min=index[i];
mini=i;
}
}
a[j]=req[mini];
j++;
cp=req[mini]; // change the current position value to next request
req[mini]=999;
} // the request that is processed its value is changed so that it is not processed again
printf("Sequence is : ");
printf("%d",cp1);
mov=mov+abs(cp1-a[0]); // head movement
printf(" -> %d",a[0]);
for(i=1;i<n;i++)
{
mov=mov+abs(a[i]-a[i-1]); ///head movement

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 120


printf(" -> %d",a[i]);
}
printf("\n");
printf("total head movement = %d\n",mov);
}

OUTPUT

RESULT
Thus a C program to implement SSTF Disk Scheduling Algorithm was executed and
output is verified successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 121


Exp. No. 16
Installation of Linux using VMware
Date

AIM:
To install Ubuntu Operating System using VMWare.

PROCEDURE:
1) Download & Install VMWare Player.
2) Download Ubuntu by choosing the option of downloading it onto a CD or USB stick.
Remember to choose either 32-bit or 64-bit.
 http://www.ubuntu.com/download/desktop

3) Open the VMWare player application. MAKE SURE TO RUN THE PROGRAM AS AN
ADMINISTRATOR. Click on Create a New Virtual Machine.

4) Choose install from Installer disc image file (iso) and browse for the Ubuntu .iso you just
downloaded. Click Next.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 122


5) Enter the required information then click Next.

6) Enter a name you wish to use for the virtual machine, or you may leave it as is. Click Next.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 123


7) Leave the next box as is and click Next.

8) Click Finish to finalize your virtual machine.

9) If you are prompted to install VMWare tools, then go ahead and do so.
 Installing VMWare tools will support faster graphics performance along with additional
benefits.
 More information located here

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 124


10) You should see this:

11) Once fully installed install the VMWare Client Tools driver.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 125


12) After successfully installing the driver, your new virtual machine should be fully set up!
 We will test our virtual machine by using Ubuntu to communicate with the ‘maegrad’ server.

Testing our VM with SSH


1) Open the Terminal in Ubuntu.

2) Open the Terminal in Ubuntu.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 126


3) Now we can remotely connect to a linux server using SSH
 Type:
ssh username@servername
ssh [email protected]
Press Enter.
 Enter your password when prompted to do so.
Note: You may be prompted to verify the authenticity of the server you want to connect to.
 Do so by typing ‘yes’ when prompted.

4) If you want X11 forwarding to run for a specific host during your current ssh session do this:
 Type:
ssh -X username@servername
ssh -X [email protected]
Press Enter.
 Enter your password when prompted to do so.
 Note: This command will only enable X11 forwarding for your current session that you are
connected to the maegrad server.
5) Congratulations - you have a Linux VM running!

RESULT
Thus, the Ubuntu Operating System has been installed successfully using VMWare.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 127


CONTENT BEYOND SYLLABUS
Exp. No. 17
Shell Programming
Date

AIM :
To write a program to display the Fibonacci series.

ALGORITHM:

Step 1: Initialize n1& n2 as 0 & 1.

Step 2: enter the limit for Fibonacci.

Step 3: initialize variable as 0

Step 4: Print the Fibonacci series n1 and n2.

Step 5: While the var number is lesser than lim-2

Step 6: Calculate n3=n1+n2.

Step 7: Set n1=n2 and n2=n3

Step 8: Increment var by 1 and print n2

Step 9: stop the program.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 128


PROGRAM:

echo " ENTER THE LIMIT FOR FIBONNACI SERIES"


read lim
n1=0
n2=1
var=0
echo "FIBONACCI SERIES IS "
echo "$n1"
echo "$n2"
while [ $var -lt `expr $lim - 2` ]
do
n3=`expr $n1 + $n2 `
n1=`expr $n2 `
n2=`expr $n3 `
var=`expr $var + 1 `
echo "$n2"
done

OUTPUT :
Enter the limit for Fibonacci:
5
The Fibonacci series is:
0
1
1
2
3

RESULT:
Thus the program has been executed successfully.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 129


Exp. No. 18
Implementation of Shared Memory using IPC
Date

AIM:

To implement the inter-process communication using shared memory.

ALGORITHM:

Step 1: Create a C file using nano editor.


Step 2: Declare a array name fd[2] of int type.
Step 3: Declare a variable of character type named string and store some string inside it.
Step 4:Use pipe system call to communicate among proccesses.
Step 5:If the parent wants to receive data from the child, it should close fd1, and the child
should close fd0. If the parent wants to send data to the child, it should close fd0,
and the child should close fd1.

PROGRAM:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void)
{ int fd[2], nbytes;
pid_t childpid;
char string[] = "Hello, world!\n";
char readbuffer[80];
pipe(fd);
if((childpid = fork()) == -1)
{
perror("fork");
exit(1);
}
if(childpid == 0)
{
/* Child process closes up input side of pipe */
close(fd[0]);
/* Send "string" through the output side of pipe */
write(fd[1], string, (strlen(string)+1));
exit(0);
}
else
{
/* Parent process closes up output side of pipe */

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 130


close(fd[1]);
/* Read in a string from the pipe */
nbytes = read(fd[0], readbuffer, sizeof(readbuffer));
printf("Received string: %s", readbuffer);
}
return(0);
}

OUTPUT:
Hello World

RESULT:
Thus the program has been executed successfully and the output is verified.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 131


VIVA QUESTIONS
1) What is an operating system?
The operating system is a software program that facilitates computer hardware to communicate
and operate with the computer software. It is the most important part of a computer system without
it computer is just like a box.

2) What is the main purpose of an operating system?


There are two main purposes of an operating system:
o It is designed to make sure that a computer system performs well by managing its
computational activities.
o It provides an environment for the development and execution of programs.

3) What are the different operating systems?


o Batched operating systems
o Distributed operating systems
o Timesharing operating systems
o Multi-programmed operating systems
o Real-time operating systems

4) What is a socket?
A socket is used to make connection between two applications. Endpoints of the connection are
called socket.

5) What is a real-time system?


Real-time system is used in the case when rigid-time requirements have been placed on the
operation of a processor. It contains a well defined and fixed time constraints.

6) What is kernel?
Kernel is the core and most important part of a computer operating system which provides basic
services for all parts of the OS.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 132


7) What is monolithic kernel?
A monolithic kernel is a kernel which includes all operating system code is in single executable
image.

8) What do you mean by a process?


An executing program is known as process. There are two types of processes:
o Operating System Processes
o User Processes

9) What are the different states of a process?


A list of different states of process:
o New Process
o Running Process
o Waiting Process
o Ready Process
o Terminated Process

10) What is the difference between micro kernel and macro kernel?
Micro kernel: micro kernel is the kernel which runs minimal performance affecting services for
operating system. In micro kernel operating system all other operations are performed by
processor.
Macro Kernel: Macro Kernel is a combination of micro and monolithic kernel.

11) What is the concept of reentrancy?


It is a very useful memory saving technique that is used for multi-programmed time sharing
systems. It provides functionality that multiple users can share a single copy of program during
the same period.
It has two key aspects:
o The program code cannot modify itself.
o The local data for each user process must be stored separately.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 133


12) What is the difference between process and program?
A program while running or executing is known as a process.

13) What is the use of paging in operating system?


Paging is used to solve the external fragmentation problem in operating system. This technique
ensures that the data you need is available as quickly as possible.

14) What is the concept of demand paging?


Demand paging specifies that if an area of memory is not currently being used, it is swapped to
disk to make room for an application's need.

15) What is the advantage of a multiprocessor system?


As many processors are increased, you will get the considerable increment in throughput. It is cost
effective also because they can share resources. So, the overall reliability increases.

16) What is virtual memory?


Virtual memory is a very useful memory management technique which enables processes to
execute outside of memory. This technique is especially used when an executing program cannot
fit in the physical memory.

17) What is thrashing?


Thrashing is a phenomenon in virtual memory scheme when the processor spends most of its time
in swapping pages, rather than executing instructions.

18) What are the four necessary and sufficient conditions behind the
deadlock?These are the 4 conditions:
1) Mutual Exclusion Condition: It specifies that the resources involved are non-sharable.
2) Hold and Wait Condition: It specifies that there must be a process that is holding a resource
already allocated to it while waiting for additional resource that are currently being held by other
processes.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 134


3) No-Preemptive Condition: Resources cannot be taken away while they are being used by
processes.
4) Circular Wait Condition: It is an explanation of the second condition. It specifies that the
processes in the system form a circular list or a chain where each process in the chain is waiting
for a resource held by next process in the chain.

19) What is a thread?


A thread is a basic unit of CPU utilization. It consists of a thread ID, program counter, register set
and a stack.

20) What is FCFS?


FCFS stands for First Come, First Served. It is a type of scheduling algorithm. In this scheme, if a
process requests the CPU first, it is allocated to the CPU first. Its implementation is managed by a
FIFO queue.

21) What is SMP?


SMP stands for Symmetric MultiProcessing. It is the most common type of multiple processor
system. In SMP, each processor runs an identical copy of the operating system, and these copies
communicate with one another when required.

22) What is RAID? What are the different RAID levels?


RAID stands for Redundant Array of Independent Disks. It is used to store the same data
redundantly to improve the overall performance.
Following are the different RAID levels:
RAID 0 - Stripped Disk Array without fault tolerance
RAID 1 - Mirroring and duplexing
RAID 2 - Memory-style error-correcting codes
RAID 3 - Bit-interleaved Parity
RAID 4 - Block-interleaved Parity
RAID 5 - Block-interleaved distributed Parity
RAID 6 - P+Q Redundancy

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 135


23) What is deadlock? Explain.
Deadlock is a specific situation or condition where two processes are waiting for each other to
complete so that they can start. But this situation causes hang for both of them.

24) Which are the necessary conditions to achieve a deadlock?


There are 4 necessary conditions to achieve a deadlock:
o Mutual Exclusion: At least one resource must be held in a non-sharable mode. If any other
process requests this resource, then that process must wait for the resource to be released.
o Hold and Wait: A process must be simultaneously holding at least one resource and
waiting for at least one resource that is currently being held by some other process.
o No preemption: Once a process is holding a resource ( i.e. once its request has been
granted ), then that resource cannot be taken away from that process until the process
voluntarily releases it.
o Circular Wait: A set of processes { P0, P1, P2, . . ., PN } must exist such that every P[ i ]
is waiting for P[ ( i + 1 ) % ( N + 1 ) ].

25) What is Banker's algorithm?


Banker's algorithm is used to avoid deadlock. It is the one of deadlock-avoidance method. It is
named as Banker's algorithm on the banking system where bank never allocates available cash in
such a manner that it can no longer satisfy the requirements of all of its customers.

26) What is the difference between logical address space and physical address space?
Logical address space specifies the address that is generated by CPU. On the other hand physical
address space specifies the address that is seen by the memory unit.

27) What is fragmentation?


Fragmentation is a phenomenon of memory wastage. It reduces the capacity and performance
because space is used inefficiently.

28) How many types of fragmentation occur in Operating System?


There are two types of fragmentation:

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 136


o Internal fragmentation: It is occurred when we deal with the systems that have fixed size
allocation units.
o External fragmentation: It is occurred when we deal with systems that have variable-size
allocation units.

29) What is spooling?


Spooling is a process in which data is temporarily gathered to be used and executed by a device,
program or the system. It is associated with printing. When different applications send output to
the printer at the same time, spooling keeps these all jobs into a disk file and queues them
accordingly to the printer.

30) What is the difference between internal commands and external commands?
Internal commands are the built-in part of the operating system while external commands are the
separate file programs that are stored in a separate folder or directory.

31) What is semaphore?


Semaphore is a protected variable or abstract data type that is used to lock the resource being used.
The value of the semaphore indicates the status of a common resource.
There are two types of semaphore:
o Binary semaphores
o Counting semaphores

32) What is a binary Semaphore?


Binary semaphore takes only 0 and 1 as value and used to implement mutual exclusion and
synchronize concurrent processes.

33) What is Belady's Anomaly?


Belady's Anomaly is also called FIFO anomaly. Usually, on increasing the number of frames
allocated to a process virtual memory, the process execution is faster, because fewer page faults
occur. Sometimes, the reverse happens, i.e., the execution time increases even when more frames

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 137


are allocated to the process. This is Belady's Anomaly. This is true for certain page reference
patterns.

34) What is starvation in Operating System?


Starvation is Resource management problem. In this problem, a waiting process does not get the
resources it needs for a long time because the resources are being allocated to other processes.

35) What is aging in Operating System?


Aging is a technique used to avoid the starvation in resource scheduling system.

36) What are the advantages of multithreaded programming?


A list of advantages of multithreaded programming:
o Enhance the responsiveness to the users.
o Resource sharing within the process.
o Economical
o Completely utilize the multiprocessing architecture.

37) What is the difference between logical and physical address space?
Logical address specifies the address which is generated by the CPU whereas physical address
specifies to the address which is seen by the memory unit.
After fragmentation

38) What are overlays?


Overlays make a process to be larger than the amount of memory allocated to it. It ensures that
only important instructions and data at any given time are kept in memory.

39) When does trashing occur?


Thrashing specifies an instance of high paging activity. This happens when it is spending more
time paging instead of executing.

40) What are the various disk-scheduling algorithms?

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 138


c. SCAN Scheduling
d. C-SCAN Scheduling
e. LOOK scheduling

41) What do you meant by short term scheduler


The selection process is carried out by the short term scheduler or CPU scheduler. The scheduler
selects the process form the process in memory that is ready to execute and allocates the CPU to
the process.

42) Define Copy-on-write.


Copy-on-write finds its main use in virtual memory operating systems; when a process creates a
copy of itself, the pages in memory that might be modified by either the process or its copy are
marked copy-on- write.

43) What is the various page replacement algorithms used for page replacement?
 FIFO page replacement
 Optimal page replacement
 LRU page replacement
 LRU approximation page replacement
 Counting based page replacement
 Page buffering algorithm.
44) Define TLB.
Translation Look-Aside Buffer, a table in the processors memory that contains information about
the pages in memory the processor has accessed recently. The TLB enables faster computing
because it allows the address processing to take place independent of the normal address-
translation pipeline.

45) Define Pre paging.


It is an attempt to prevent the high level of initial paging. This strategy is to bring into memory at
one time all the pages the will be needed.
Example: - Solaris uses pre paging.

R2021 / CSE / CS3461 – OPERATING SYSTEMS LABORATORY / II YEAR / IV SEM / 139

You might also like