SlideShare a Scribd company logo
DEPARTMENT OF COMPUTER SCIENCE AND
BUSINESS SYSTEMS
AL3452 OPERATING SYSTEMS (BLENDED)
MANUAL
FOR IV SEMESTER B.TECH. DEGREE COURSE
[REGULATION-2021]
As per the prescribed syllabus by
ANNA UNIVERSITY CHENNAI - 600025
R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/1
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS
SYSTEMS
MANUAL
SUBJECT CODE : AL3452
SUBJECT NAME : OPERATING SYSTEMS
REGULATION : 2021
ACADEMIC YEAR : 2023-2024
YEAR / SEMESTER : II / IV
BATCH : 2022 – 2026
Prepared by: Verified by: Approved by:
Name: Name: Name:
Date: Date: Date:
R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/2
COLLEGE VISION
Emerge as a Premier Institute, producing globally competent
engineers.
COLLEGE MISSION
IM1: Achieve Academic diligence through effective and innovative
teaching-learning processes, using ICT Tools.
IM2: Make students employable through rigorous career guidance and
training programs.
IM3: Strengthen Industry Institute Interaction through MOUs and
Collaborations.
IM4: Promote Research & Development by inculcating creative
thinking through innovative projects incubation.
R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/3
VISION AND MISSION OF THE DEPARTMENT
VISION
To create skilled, industry ready professionals in the domain of
Computer Science and Business Systems who could make a positive
contribution to society through an understanding of information
technology.
MISSION
DM 1 : To foster student talent and enable them to compete worldwide
through innovative teaching, research, and consultancy.
DM 2 : To regulate prospectus to reflect changing industry demands.
DM 3 : To instill a variety of skill sets that adhere to industry standards
and to uphold moral principles.
DM 4 : To develop professional ethics and life skills in individuals
which lead them to serve the society.
R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/4
PROGRAM EDUCATIONAL OBJECTIVES (PEO)
PEO 1 : To guarantee that graduates will be adept in applying the core knowledge of basic
sciences, math, computer science, and business systems for the applications pertinent to
diverse streams of engineering and technology.
PEO 2 : To enhance graduates fundamental competencies to apply computer science and
data analytics tools knowledge to store, retrieve, deploy, and analyse data in the context of
corporate enterprise.
PEO 3 : To help graduates enter the workforce, establish themselves as professionals, and
satisfy the diverse demands of business, academia, and research by putting their technical
expertise and leadership abilities to use.
PEO 4: Entrepreneurs: To provide graduates with entrepreneurial abilities and traits that
will enable them to comprehend how businesses run, recognise business issues, look for
business possibilities, and become ready to manage businesses successfully.
PROGRAM SPECIFIC OBJECTIVES (PSO)
PSO 1 : To develop, pick, and use relevant methods, resources, contemporary engineering
tools, and business tools, such as data analytics and prediction, for complicated
engineering operations and business solutions and to develop domain-specific approaches
for decision-making in a number of important real-world problem domains.
PSO 2 : To be able to use management techniques and entrepreneurial skills to find,
evaluate, and create business opportunities with clever business ideas and to manage
complex IT projects with an awareness of risk management procedures, operational
ramifications, and ethical, financial, and environmental considerations
R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/5
PROGRAM OUTCOMES (POs)
PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering problems.
PO2: 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.
PO3: 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.
PO4: 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.
PO5: 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.
PO6: 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.
PO7: 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.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO9: Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
PO10: 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.
PO11: 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.
PO12: 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.
R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/6
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.
COURSE OUTCOMES
At the end of this course, the students will be able to:
CO1: Implement the installation process of windows OS in a step by step procedure,
and implement UNIX commands.
CO2: Implement various CPU Scheduling Algorithms, and understand Semaphore,
Deadlock Avoidance and Deadlock Detection Algorithms.
CO3: Understand the purpose of Memory Allocation Methods in a computer and can
compare and contrast between the various memory allocation methods.
CO4: Develop and define File Organization and File Allocation Strategies to improve
the performance of a computer.
CO5: Implement various Disk Scheduling Algorithms to minimize the seek time and
rotational latency, thereby improving the overall performance of the system.
CO – PO & PSO MAPPING
SNO
PO1
PO2
PO3
PO4
PO5
PO6
PO7
PO8
PO9
PO10
PO11
PO12
PSO1
PSO2
CO1 3 1 1 1 - - - - - - - - 1 -
CO2 3 3 3 1 - - - - - - - - 1 -
CO3 3 3 3 3 - - - - - - - - 1 -
CO4 3 3 3 3 - - - - - - - - 1 -
CO5 3 3 3 3 - - - - - - - - 1 -
Avg 3 2.6 2.6 2.2 - - - - - - - - 1 -
R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/7
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/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/8
SYLLABUS R – 2021
A L3452 OPERATING SYSTEMS
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
TOTAL:30 PERIODS
COURSE OUTCOMES:
At the end of this course, the students will be able to:
CO1: Implement the installation process of windows OS in a step by step procedure,and implement UNIX
commands.
CO2: Implement various CPU Scheduling Algorithms, and understand Semaphore, Deadlock Avoidance and
Deadlock Detection Algorithms.
CO3: Understand the purpose of Memory Allocation Methods in a computer and can compare and contrast
between the various memory allocation methods.
CO4: Develop and define File Organization and File Allocation Strategies to improve the performance of a
computer.
CO5: Implement various Disk Scheduling Algorithms to minimize the seek time and rotational latency,
thereby improving the overall performance of the system.
L T P C
3 0 2 4
R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/9
LIST OF EXPERIMENTS - CO MAPPING
EXP.NO TITLE OF THE PROGRAM CO’S
1 Installation of Windows Operating System CO1
2A Basics of Unix Commands CO1
2B Shell Programming (Even or Odd) CO1
2C Shell Programming (Biggest of Two Numbers) CO1
2D Shell Programming (Biggest of Three Numbers) CO1
2E Shell Programming (Factorial of a Number) CO1
2F Shell Programming (Fibonacci Series) CO1
3A The Fork System Call CO1
3B The Exit System Call CO1
3C The Getpid System Call CO1
3D Wait System Call CO1
3E Close System Call CO1
4A First Come First Serve Scheduling CO2
4B Shortest Job Fist Scheduling Algorithm CO2
4C Priority Scheduling CO2
4D Round Robin Scheduling CO2
5 Implementation of IPC using PIPE CO2
6 Implementation of Producer Consumer Problem using Semaphore CO2
7 Implementation of Bankers Algorithm for Dead Lock Avoidance CO2
8 Implementation of Deadlock Detection Algorithm CO2
9 Implement Threading & Synchronization Applications CO2
10 Memory Management Scheme using Paging CO3
11A Implementation of First Fit Algorithm CO3
11B Implementation of Worst Fit Algorithm CO3
11C Implementation of Best Fit Algorithm CO3
R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/10
12A Implementation of Page Replacement Algorithm (FIFO) CO3
12B Implementation of Page Replacement Algorithm (LRU) CO3
12C
Implementation of Page Replacement Algorithm using Least
Frequently Used Algorithm
CO3
13A
Implementation of File Organization Techniques using Single Level
Directory
CO4
13B
Implementation of File Organization Techniques using Two Level
Directory
CO4
13C
Implementation of File Organization Techniques using Hierarchical
Level Directory
CO4
13D Implementation of File Organization Techniques Using DAG CO4
14A Implementation of Sequential File Allocation Strategies CO4
14B Implementation of Indexed File Allocation Strategies CO4
14C Implementation of Linked File Allocation Strategies CO4
15A Implementation of FCFS Disk Scheduling Algorithm CO5
15B Implementation of SSTF Disk Scheduling Algorithm CO5
CONTENT BEYOND THE SYLLABUS
16 UNIX Editors CO1
17 IPC Shared Memory CO3
R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/11
INDEX
S.No. Date Name Of The Experiment Page No Marks Faculty
Sign
1 Installation of Windows Operating System
2A Basics of Unix Commands
2B Shell Programming (Even or Odd)
2C Shell Programming (Biggest of Two Numbers)
2D Shell Programming (Biggest of Three Numbers)
2E Shell Programming (Factorial of a Number)
2F Shell Programming (Fibonacci Series)
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
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
R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/12
12A Implementation of Page Replacement
Algorithm (FIFO)
12B Implementation of Page Replacement
Algorithm (LRU)
12C Implementation of Page Replacement
Algorithm using Least Frequently Used Algorithm
13A Implementation of File Organization
Techniques using Single Level Directory
13B Implementation of File Organization
Techniques using Two Level Directory
13C
Implementation of File Organization
Techniques using Hierarchical Level Directory
13D Implementation of File Organization
Techniques Using DAG
14A Implementation of Sequential File Allocation
Strategies
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
CONTENT BEYOND THE SYLLABUS
16 UNIX Editors
17 IPC Shared Memory
EX. 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.
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.
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:
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.
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.
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.
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.
VIVA-VOCE QUESTIONS
1) What are the minimum hardware requirements for installing Windows 10?
The minimum hardware requirements for Windows 10 include a 1 GHz or faster
processor, 1 GB (32-bit) or 2 GB (64-bit) RAM, 16 GB (32-bit) or 20 GB (64-bit) of free hard disk
space, and a DirectX 9 graphics device with WDDM 1.0 or higher driver.
2) How can you boot from a Windows installation media (DVD/USB)?
You need to access the BIOS or UEFI firmware settings during the system startup and
set the boot order to prioritize the DVD/USB drive. Save the changes and restart the computer with
the installation media inserted.
3) What is the purpose of the Windows Setup program?
The Windows Setup program guides users through the process of installing or
upgrading the Windows operating system. It allows users to choose installation options, partition
the disk, and install device drivers.
4) Explain the difference between an upgrade and a clean installation.
An upgrade installs a new version of Windows while preserving user files, settings,
and applications. A clean installation involves formatting the existing disk and installing Windows
from scratch, resulting in the loss of all data on the drive.
5) What is the importance of device drivers during the Windows installation process?
Device drivers enable communication between the operating system and hardware
components. During installation, Windows Setup installs generic drivers to facilitate the installation
process, and later, you may need to install specific drivers for optimal hardware functionality.
6) Describe the steps involved in partitioning the hard disk during Windows installation.
Windows installation allows you to create, delete, and format partitions. You can
create new partitions, select an existing partition for installation, or let Windows create the
necessary partitions automatically. It's crucial to choose the right partition for installation to avoid
data loss.
7) What is the purpose of the Product Key during Windows installation?
The Product Key is a unique alphanumeric code that verifies the legitimacy of the
Windows copy being installed. It is required during installation to activate and validate the
operating system.
8) How can you customize the installation options during the Windows Setup process?
Windows Setup provides customization options such as selecting the installation
location, choosing between an upgrade or clean install, configuring user accounts, and specifying
regional settings. Users can tailor these options according to their preferences and requirements.
EX. NO: 2a 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
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:
Output : acet
12ee01@localhost]:~ $ who
tty7 2010-02-10 15:34 (:0)
acet pts/0 2010-02-10 05:05 (:0.0)
12ee01@localhost]:~ $
Example:
Output :
12ee01@localhost]:~ $ who –a
system boot 2010-02-10 15:34
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
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]:~ $
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
3.cat command
12ee01@localhost]:~ $
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).
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
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
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$
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]:~ $
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.
EX. NO: 2(B) SHELL PROGRAMMING (EVEN OR ODD)
DATE:
AIM:
To write a program to find whether a number is even or odd using shell programming
ALGORITHM:
STEP 1: Read the input number.
STEP 2: Perform modular division on input number by 2.
STEP 3: If remainder is 0 print the number is even.
STEP 4: Else print number is odd.
STEP 5: Stop the program.
PROGRAM
echo "enter the number"
read num
echo "enter the number"
read num
if [ `expr $num % 2` -eq 0 ]
then
echo "number is even"
else
echo "number is odd"
OUTPUT:
Enter the number: 5
The number is odd.
RESULT:
Thus the program has been executed successfully.
EX. NO: 2(C) SHELL PROGRAMMING (BIGGEST OF TWO NUMBERS)
DATE:
AIM :
To write a program to find biggest in two numbers.
ALGORITHM :
STEP 1: Read The Two Numbers.
STEP 2: If Value Of A Is Greater Than B Is Big.
STEP 3: Else Print B Is Big.
STEP 4: Stop The Program.
PROGRAM:
echo "enter the number"
read a b
if [ $a -gt $b ]
then
echo "A is big"
else
echo "B is big"
fi
OUTPUT:
RESULT:
Thus the program has been executed successfully.
EX. NO: 2(D) SHELL PROGRAMMING (BIGGEST OF THREE NUMBERS)
DATE:
AIM:
To Write a Program to Find Biggest In Three Numbers.
ALGORITHM:
STEP 1: Read The Three Numbers.
STEP 2: If A Is Greater Than B And A Is Greater Than C Then Print A Is Big.
STEP 3: Else If B is greater Than C Then C Is Big.
STEP 4: Else Print C Is Big.
STEP 5: Stop The Program.
PROGRAM:
echo "enter three numbers"
read a b c
if [ $a -gt $b ] && [ $a -gt $c ]
then
echo "A is big"
else if [ $b -gt $c ]
then
echo "B is big"
else
echo "C is big"
fi
fi
OUTPUT:
RESULT:
Thus the program has been executed successfully.
EX. NO: 2(E) SHELL PROGRAMMING (FACTORIAL OF NUMBER)
DATE:
AIM:
To find a factorial of a number using shell script.
ALGORITHM:
Step 1: read a number.
Step 2: Initialize fact as 1.
Step 3: Initialize I as 1.
Step 4: While I is lesser than or equal to no.
Step 5: Multiply the value of I and fact and assign to fact increment the value of I by 1.
Step 6: print the result.
Step 7: Stop the program.
PROGRAM:
echo "enter the number"
read n
fact=1
i=1
while [ $i -le $n ]
do
fact=`expr $i * $fact`
i=`expr $i + 1`
done
echo "the fcatorial number of $ni is $fact
OUTPUT:
RESULT:
Thus the program has been executed successfully.
EX. NO: 2(F) SHELL PROGRAMMING (FIBONACCI SERIES)
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.
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 :
RESULT:
Thus the program has been executed successfully
VIVA-VOCE QUESTIONS
1) What is the shell in Unix?
The shell is the command-line interpreter in Unix-like operating systems. It takes commands from
the user and executes them by interacting with the kernel.
2) How do you display the current working directory in Unix?
The pwd command is used to display the current working directory.
3) What is the purpose of the ls command?
The ls command is used to list the contents of a directory.
4) How can you navigate to the home directory quickly?
The cd command without any arguments takes you to the home directory. For example, cd or cd ~.
5) Explain the use of the cp command.
The cp command is used to copy files or directories. For example, cp file1.txt file2.txt copies the
contents of file1.txt to file2.txt.
6) How do you create a new directory in Unix?
The mkdir command is used to create a new directory. For example, mkdir my_directory creates a
new directory named my_directory.
7) What is the purpose of the rm command?
The rm command is used to remove or delete files or directories. For example, rm file.txt deletes
the file named file.txt.
8) How can you display the contents of a file in Unix?
The cat command is used to display the contents of a file. For example, cat filename.txt shows the
contents of filename.txt.
9) Explain the use of the man command.
The man command is used to display the manual or documentation for other Unix commands. For
example, man ls shows the manual for the ls command.
10) How can you find files in Unix based on their names?
The find command is used to search for files and directories based on various criteria, including
their names. For example, find /path/to/search -name filename.txt searches for a file named filename.txt in
the specified path.
EX. 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;
}
OUTPUT:
RESULT:
Thus the C program using fork system call was executed and output is verified
successfully.
EX. 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.
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:%dn”,exit_status);
}
return 0;
}
OUTPUT
RESULT
Thus the C program using exit system call was executed and output is verified successfully.
EX. 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;
}
OUTPUT:
RESULT:
Thus the C program to implement getpid system call was executed and output is verified
successfully.
EX. 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 forkn");
pid=fork();
if(pid==0)
{
printf("Child statesn");
for(i=0;i<10;i++)
printf("%d t",i);
printf("Child endsn");
}
else
{
wait(0);
for(i=0;i<10;i++)
printf("%d t",i);
printf("Parent process endn"); }}
OUTPUT:
RESULT:
Thus the C program to implement wait system call was executed and output is verified
successfully.
EX. 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.
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 = % dn", fd1);
// Using close system Call
if (close(fd1) < 0)
{
perror("c1");
exit(1);
}
printf("closed the fd.n");
}
OUTPUT
RESULT
Thus the C program to implement close system call was executed and output is verified
successfully.
VIVA-VOCE QUESTIONS
1) What is a system call?
A system call is a mechanism by which a program requests a service from the operating system
kernel. It provides a way for user-level applications to interact with the operating system to perform tasks
such as file operations, process control, memory management, and input/output operations.
2) How are system calls different from regular function calls?
System calls involve a switch from user mode to kernel mode, allowing the program to request
privileged services from the operating system. Regular function calls, on the other hand, execute within the
user mode without the need for a mode switch.
3) Can you give examples of common system calls?
fork() for creating a new process
open() for opening a file
read() and write() for reading from and writing to files
4) What is the purpose of CPU scheduling?
The primary purpose of CPU scheduling is to maximize the utilization of the CPU and minimize the
turnaround time, waiting time, and response time for processes.
5) What is a CPU burst?
A CPU burst is the amount of time a process uses the CPU without being interrupted by the
operating system. It consists of a sequence of instructions that the process executes in a single run on the
CPU.
6) What is preemptive scheduling?
Preemptive scheduling allows the operating system to interrupt a currently running process to start
or resume another, usually with a higher priority. It ensures that no process monopolizes the CPU for an
extended period.
7) What is a deadlock?
A deadlock is a state in a computer system where two or more processes are unable to proceed
because each is waiting for the other to release a resource, resulting in a circular waiting condition.
8) Explain the necessary conditions for a deadlock to occur.
Deadlock requires four necessary conditions: mutual exclusion, hold and wait, no preemption, and
circular wait. If all these conditions hold simultaneously, a deadlock can occur.
9) How does mutual exclusion contribute to deadlock?
Mutual exclusion means that only one process can use a resource at a time. If a process holds a
resource and requests another while keeping the first one, it can lead to a situation where multiple
processes are waiting for each other to release resources, causing a deadlock.
10) What is the hold and wait condition in deadlock?
The hold and wait condition occur when a process holds one resource while waiting for another. If
multiple processes are holding resources and waiting for additional ones, it can lead to a deadlock.
EX. 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.
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("ntt Gantt chart n");
printf("ProcessName StartTime BurstTime n");
for(i=0;i<num;i++){
bt=start+burst[i];
printf("%ctt%ft%fn",procno[i],start,bt);
wait=wait+start;
start=start+burst[i]; }
avgwait=wait/num;
printf("Average waiting time of a process= %fn",avgwait);
printf("Total running time of process= %fn",start);
return 0;}
OUTPUT:
RESULT:
Thus the C program to implement the first come first serve scheduling was executed and
output is verified successfully.
EX. NO: 4B. SHORTEST JOB FIRST 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]);
scanf("%f",&burst[i]);
}
for(i=0;i<num;i++)
{
if(burst[i]>burst[i+1])
{
swap(i);
i=-1;
}
}
printf("ntt Gantt chart n");
printf("ProcessName StartTime BurstTime n");
for(i=1;i<=num;i++)
{
bt=start+burst[i];
printf("%ctt%ft%fn",procno[i],start,bt);
wait=wait+start;
start=start+burst[i];
}
avgwait=wait/num;
printf("Average waiting time of a process= %fn",avgwait);
printf("Total running time of process= %fn",start);
return 0;
}
void swap(int j)
{
char temp;
float tbt;
temp=procno[j];
tbt=burst[j];
procno[j]=procno[j+1];
burst[j]=burst[j+1];
procno[j+1]=temp;
burst[j+1]=tbt;
}
OUTPUT:
RESULT:
Thus the C program to implement the shortest job first scheduling was executed and output is
verified successfully.
EX. 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);
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("ntt Gantt chart nn");
printf("ProcessNametPrioritytStarttBurst n");
for(i=1;i<=num;i++)
{
bt=start+burst[i];
printf("%cttt%dtt%ft%fn",procno[i],priority[i],start,bt);
wait=wait+start;
start=start+burst[i];
}
avgwait=wait/num;
printf("Average waiting time of a process= %fn",avgwait);
printf("Total running time of process= %fn",start);
return 0;
}
void swap(int j)
{
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:
RESULT:
Thus the C program to implement the priority scheduling was executed and output is verified
successfully.
EX. 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];
}
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];
}
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%dtt%dtt%dtt%d ",i+1,bt[i],wt[i],tat[i]);
printf("n Average wait time is %ftn Average turnaround time is %ftn",awt,atat); }
OUTPUT:
RESULT:
Thus the C program to implement the round robin scheduling was executed and output is
verified successfully.
VIVA-VOCE QUESTIONS
1) What is CPU scheduling?
CPU scheduling is the process by which the operating system manages the execution of processes in a
computer system. It determines which process should run next, allocates CPU time to that process, and
ensures fair and efficient utilization of the CPU.
2) What is the purpose of CPU scheduling?
The primary purpose of CPU scheduling is to maximize the utilization of the CPU and minimize the
turnaround time, waiting time, and response time for processes.
3) What is a CPU burst?
A CPU burst is the amount of time a process uses the CPU without being interrupted by the operating
system. It consists of a sequence of instructions that the process executes in a single run on the CPU.
4) What is preemptive scheduling?
Preemptive scheduling allows the operating system to interrupt a currently running process to start or
resume another, usually with a higher priority. It ensures that no process monopolizes the CPU for an
extended period.
5) Explain the difference between preemptive and non-preemptive scheduling.
In preemptive scheduling, a running process can be interrupted and moved to the ready queue, allowing
another process to start. In non-preemptive scheduling, a running process cannot be interrupted, and it
continues until it voluntarily releases the CPU.
6) What is turnaround time in CPU scheduling?
Turnaround time is the total time taken by a process to complete execution, including both waiting time
and execution time. It is a measure of the overall efficiency of the CPU scheduling algorithm.
7) Describe the First-Come-First-Serve (FCFS) scheduling algorithm.
FCFS is a non-preemptive scheduling algorithm where processes are executed in the order they arrive in
the ready queue. It suffers from the "convoy effect" and may result in a long average waiting time.
8) What is the Shortest Job Next (SJN) scheduling algorithm?
SJN, also known as Shortest Job First (SJF), selects the process with the smallest total remaining
processing time. It can be preemptive (Shortest Remaining Time First - SRTF) or non-preemptive.
9) Explain the Round Robin (RR) scheduling algorithm.
Round Robin is a preemptive scheduling algorithm where each process is assigned a fixed time slice
(quantum) to execute before moving to the next process in the ready queue. It provides fair sharing of the
CPU.
10) What is priority scheduling?
Priority scheduling assigns priority levels to processes, and the process with the highest priority is selected
for execution first. It can be preemptive or non-preemptive, and it helps in giving preference to more
critical or important tasks
EX. 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
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 pipen");
return 1;
}
printf("Writing to pipe - Message 1 is %sn", writemessages[0]);
write(pipefds[1], writemessages[0], sizeof(writemessages[0]));
read(pipefds[0], readmessage, sizeof(readmessage));
printf("Reading from pipe – Message 1 is %sn", readmessage);
printf("Writing to pipe - Message 2 is %sn", writemessages[0]);
write(pipefds[1], writemessages[1], sizeof(writemessages[0]));
read(pipefds[0], readmessage, sizeof(readmessage));
printf("Reading from pipe – Message 2 is %sn", readmessage);
return 0;
}
OUTPUT
RESULT
Thus the C program to implement inter process communication using PIPE was executed
and output is verified successfully.
VIVA-VOCE QUESTIONS
1) What is Inter-Process Communication (IPC)?
IPC refers to mechanisms that allow processes to communicate and exchange data with each other.
It enables coordination and data sharing between processes running concurrently in a computer system.
2) What is a pipe in the context of IPC?
In the context of IPC, a pipe is a unidirectional communication channel that allows data to be
transmitted between two processes. One process writes to the pipe, and the other process reads from it.
3) How is a pipe created in Unix?
The pipe() system call is used to create a pipe in Unix. It returns two file descriptors: one for
writing to the pipe (fd[1]) and one for reading from the pipe (fd[0]).
4) Explain the relationship between the writing and reading ends of a pipe.
The writing end of the pipe (fd[1]) is used by one process to write data into the pipe, and the
reading end (fd[0]) is used by another process to read that data. It forms a unidirectional communication
channel.
5) How can data be transferred between processes using a pipe?
One process writes data into the writing end of the pipe (fd[1]), and another process reads from the
reading end of the pipe (fd[0]). The data is transferred from the writer to the reader through the pipe.
6) What happens if a process writes to a pipe that is full?
If a process attempts to write to a full pipe, it will be blocked until space is available. This blocking
mechanism ensures synchronization between the writer and the reader.
7) How does a process close a pipe after using it?
A process can close a pipe by using the close() system call on both the reading and writing ends of
the pipe (fd[0] and fd[1]). This indicates that the process has finished using the pipe.
8) Can a pipe be used for communication between non-related processes?
No, a pipe is typically used for communication between related processes, such as a parent and its
child processes. For communication between unrelated processes, other IPC mechanisms like named pipes
or message queues may be more suitable.
9) How can you implement a simple command pipeline using pipes?
A command pipeline can be implemented by creating multiple processes, connecting the output of
one process to the input of the next using pipes. For example, command1 | command2.
10) What is the difference between a named pipe (FIFO) and an unnamed pipe?
An unnamed pipe is created using the pipe() system call and exists in the file system as an unnamed
file. A named pipe (FIFO) is created using the mkfifo() system call and has a name associated with it,
allowing unrelated processes to communicate.
EX. 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.PRODUCERn2.CONSUMERn3.EXITn");
while(1)
{
printf("nENTER YOUR CHOICEn");
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);
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:
RESULT:
Thus the C program to implement the producer consumer problem was executed and output
is verified successfully.
VIVA-VOCE QUESTIONS
1) What is the Producer-Consumer problem?
The Producer-Consumer problem is a classic synchronization problem where there are two types of
processes, producers, and consumers, that share a common, fixed-size buffer as a communication medium.
The challenge is to ensure that the producers do not produce items if the buffer is full, and consumers do
not consume items if the buffer is empty.
2) How can semaphores be used to solve the Producer-Consumer problem?
Semaphores can be used to synchronize access to the shared buffer. Two semaphores, one for
controlling access to the critical section (mutex) and another for tracking the number of available slots in
the buffer, are commonly used.
3) Explain the role of the mutex semaphore in the Producer-Consumer problem.
The mutex (mutual exclusion) semaphore ensures that only one process (either a producer or a
consumer) can access the critical section, i.e., modify the buffer, at any given time. It prevents race
conditions.
4) What does the counting semaphore represent in the Producer-Consumer problem?
The counting semaphore represents the number of available slots in the buffer. It is decremented by
producers when they add items to the buffer and incremented by consumers when they remove items. This
semaphore helps in tracking the fullness of the buffer.
5) How can you initialize the semaphores for solving the Producer-Consumer problem?
The mutex semaphore is initialized to 1, and the counting semaphore is initialized to the maximum
buffer size, indicating that the buffer is initially empty.
6) How is mutual exclusion achieved using semaphores?
Mutual exclusion is achieved by using the mutex semaphore. Before entering the critical section
(modifying the buffer), a process must acquire the mutex semaphore. After completing the critical section,
it releases the mutex semaphore.
7) Explain how a producer adds an item to the buffer using semaphores.
The producer must first acquire the mutex semaphore. Once acquired, it checks if there is space in
the buffer (counting semaphore is greater than 0). If there is space, it adds an item to the buffer, decrements
the counting semaphore, and releases the mutex semaphore.
8) How does a consumer remove an item from the buffer using semaphores?
Similar to the producer, the consumer must acquire the mutex semaphore before entering the
critical section. Once acquired, it checks if there are items in the buffer (counting semaphore is less than
the buffer size). If there are items, it removes one, increments the counting semaphore, and releases the
mutex semaphore.
9) What is the purpose of using semaphores in the Producer-Consumer problem?
Semaphores are used to provide synchronization and mutual exclusion, ensuring that the shared
buffer is accessed in a controlled manner. They help prevent race conditions and ensure the correct
functioning of producers and consumers.
10) Can semaphores alone solve the Producer-Consumer problem?
Yes, semaphores provide a powerful mechanism for solving synchronization problems, including the
Producer-Consumer problem. They help in coordinating the activities of producers and consumers and
ensure that the buffer is accessed safely.
EX. 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.
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("nnEnter the no of resources : ");
scanf("%d", &r);
printf("nnEnter 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("nnEnter 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("nnEnter the Available Resources : ");
for(i = 0; i < r; i++)
scanf("%d", &avail[i]);
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("tt");
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)
{
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:
RESULT:
Thus the C program to implement deadlock avoidance using banker’s algorithm was
executed and output is verified successfully.
VIVA-VOCE QUESTIONS
1) What is the Banker's Algorithm?
The Banker's Algorithm is a deadlock avoidance algorithm used in operating systems to determine whether
granting a resource request from a process would leave the system in a safe state or risk entering a
deadlock.
2) What are the essential data structures used in the Banker's Algorithm?
The essential data structures include the available vector, the maximum matrix, the allocation matrix, and
the need matrix.
3) Explain the available vector in the Banker's Algorithm.
The available vector represents the number of available instances of each resource in the system. It is a
one-dimensional array with the same number of elements as there are types of resources.
4) What is the maximum matrix in the context of the Banker's Algorithm?
The maximum matrix specifies the maximum demand of each process for each resource type. It is a two-
dimensional matrix where each row corresponds to a process, and each column corresponds to a resource
type.
5) What does the allocation matrix represent?
The allocation matrix indicates the number of resources of each type currently allocated to each process.
Like the maximum matrix, it is a two-dimensional matrix with rows representing processes and columns
representing resource types.
6) Explain the need matrix in the context of the Banker's Algorithm.
The need matrix represents the remaining needs of each process for each resource type to complete its
execution. It is calculated by subtracting the allocation matrix from the maximum matrix.
7) How does the Banker's Algorithm assess whether a resource request can be granted?
The Banker's Algorithm assesses a resource request by temporarily modifying the state of the system,
checking if the resulting state is safe. If the system remains in a safe state after granting the request, it is
deemed acceptable; otherwise, the request is denied.
8) What is a safe state in the Banker's Algorithm?
A safe state is a state in which there exists a sequence of processes that can complete their execution
without causing a deadlock. The Banker's Algorithm aims to ensure that the system remains in a safe state
after any sequence of resource requests.
9) How does the Banker's Algorithm handle resource requests?
When a process makes a resource request, the algorithm first checks if the request can be granted without
violating the system's safety. If so, the resources are allocated, and the system's state is updated. If not, the
request is denied, and the system remains unchanged.
10) What is the role of the safety algorithm in the Banker's Algorithm?
The safety algorithm is used to determine whether the system is in a safe state. It simulates the allocation of
resources for each process's maximum needs and checks if a safe execution sequence exists.
EX. 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) matrixn");
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 matrixn");
for(i=1;i<=tp;i++)
{
printf("process %d:n",i);
for(j=1;j<=tr;j++)
scanf("%d",&p[i][j]);
}
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:");
for(j=1;j<=tp;j++)
{
found=0;
for(i=1;i<k;i++)
{
if(j==m[i])
found=1;
}
if(found==0)
printf("%dt",j);
}
getch();
}
OUTPUT:
RESULT:
Thus the program was executed successfully.
VIVA-VOCE QUESTIONS
1) What is deadlock detection?
Deadlock detection is a mechanism used in operating systems to identify whether a system is in a deadlock
state where processes are unable to proceed because each is waiting for the other to release resources.
2) Why is deadlock detection necessary?
Deadlock detection is necessary to identify and resolve deadlocks that may occur in a system. It allows the
operating system to take corrective actions, such as terminating processes or releasing resources, to break
the deadlock and restore system functionality.
3) What are the commonly used approaches for deadlock detection?
 Periodic polling
 Wait-Die and Wound-Wait Schemes.
4) How does the periodic polling approach work for deadlock detection?
In periodic polling, the operating system checks the state of the system at regular intervals to identify any
potential deadlocks. It involves examining the resource allocation graph or other data structures to
determine if a cycle exists, indicating a deadlock.
5) What is the resource allocation graph, and how is it used in deadlock detection?
The resource allocation graph is a directed graph that represents the allocation of resources to processes
and the relationships between them. Deadlocks can be detected by finding cycles in this graph, indicating
circular waiting.
6) Explain the Wait-Die and Wound-Wait deadlock detection schemes.
Wait-Die Scheme: In this scheme, older transactions (processes) are allowed to wait for resources, but
younger transactions requesting resources held by older ones are aborted.
Wound-Wait Scheme: Older transactions requesting resources held by younger transactions are allowed to
wait, while younger transactions requesting resources held by older ones are aborted.
7) How does the operating system identify a deadlock using the Wait-Die and Wound-Wait schemes?
When a process requests a resource, the operating system checks the age of the requesting process and the
age of the process holding the resource. Based on the scheme (Wait-Die or Wound-Wait), the system
decides whether to allow the waiting or to abort the requesting process to break the potential deadlock.
8) Can deadlock detection prevent deadlocks from occurring?
No, deadlock detection cannot prevent deadlocks. It can only identify and resolve existing deadlocks.
Prevention techniques, such as deadlock avoidance using the Banker's Algorithm, aim to eliminate the
conditions that lead to deadlocks.
9) What are the advantages of deadlock detection over prevention?
Deadlock detection has the advantage of not requiring prior knowledge of resource usage patterns. It can
handle dynamic and unpredictable scenarios but comes with the cost of periodic checks and potential
delays in detecting deadlocks.
10) How does the operating system resolve a deadlock after detection?
After detecting a deadlock, the operating system can take various actions, including terminating one or
more processes involved in the deadlock, releasing resources held by these processes, or rolling back the
execution state to a safe point.
EX. 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
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 startedn", counter);
for(i=0; i<(0xFFFFFFFF);i++);
printf("n Job %d finishedn", 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;}
OUTPUT
RESULT
Thus a C program to implement the threading and synchronization applications was
executed and output is verified successfully.
VIVA-VOCE QUESTIONS
1) What is a thread?
A thread is the smallest unit of execution within a process. It represents an independent flow of control and
shares resources, such as memory space and file descriptors, with other threads within the same process.
2) Why do we use threads in programming?
Threads are used in programming to achieve parallelism, responsiveness, and efficient resource utilization.
They allow multiple tasks to execute concurrently within a single process, improving overall system
performance.
3) How is threading different from multiprocessing?
Threading involves multiple threads within the same process sharing the same resources, while
multiprocessing involves multiple independent processes, each with its own resources.
4) Explain the concept of thread synchronization.
Thread synchronization is the coordination of multiple threads to ensure that they access shared resources
in a mutually exclusive and orderly manner, preventing race conditions and maintaining data consistency.
5) What is a critical section?
A critical section is a part of the code where shared resources are accessed and modified by multiple
threads. It needs to be protected to prevent conflicts and ensure the correct functioning of the program.
6) How can you implement thread synchronization?
Thread synchronization can be implemented using synchronization primitives like mutexes, semaphores,
and condition variables. These mechanisms ensure exclusive access to critical sections and coordinate
thread activities.
7) What is a mutex?
A mutex (short for mutual exclusion) is a synchronization primitive that provides exclusive access to a
shared resource. It allows only one thread to enter the critical section at a time.
8) Explain the concept of a semaphore.
A semaphore is a synchronization primitive that maintains a counter. It is used to control access to a shared
resource by multiple threads and allows a specified number of threads to access the resource
simultaneously.
9) What is the purpose of a condition variable?
A condition variable is used for signaling and coordinating threads. It allows threads to wait until a certain
condition is met, and it can be used in conjunction with mutexes to ensure orderly access to shared
resources.
10) How do you create and manage threads in a programming language that supports
multithreading?
The process of creating and managing threads depends on the programming language and its threading
library. Generally, it involves creating thread objects, defining thread functions, starting threads, and
managing synchronization.
EX. 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++)
{
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);
}
OUTPUT:
RESULT:
Thus the C program to implement the memory management scheme using paging algorithm
was executed and output is verified successfully.
VIVA-VOCE QUESTIONS
1) What is paging in the context of memory management?
Paging is a memory management scheme that allows a computer's physical memory to be non-contiguous.
It divides the physical memory into fixed-size blocks called "frames" and logically divides the process's
virtual memory into fixed-size blocks called "pages."
2) How does paging help overcome the limitations of contiguous memory allocation?
Paging allows processes to be loaded into non-contiguous physical memory locations. It eliminates the
need for a contiguous block of memory, making better use of available memory space and simplifying
memory allocation.
3) What is a page table?
A page table is a data structure used in paging systems to map virtual addresses to corresponding physical
addresses. It contains entries that specify the frame number in physical memory for each page in the
process's virtual address space.
4) How is the size of a page determined in a paging system?
The size of a page is determined by the hardware and is typically a power of 2, such as 4 KB or 8 KB. The
page size affects the granularity of memory allocation and can impact system performance.
5) Explain the concept of a page fault.
A page fault occurs when a program attempts to access a page that is not currently in physical memory.
The operating system must then bring the required page into memory from secondary storage, updating the
page table accordingly.
6) What is the role of the page table in handling a page fault?
The page table is consulted to find the frame number of the required page. If the page is not in physical
memory (a page fault occurs), the operating system uses the page table to determine the location of the
page on the secondary storage device and brings it into physical memory.
7) How does the operating system keep track of which pages are currently in physical memory?
The operating system uses a valid/invalid bit in each page table entry to indicate whether a page is
currently in physical memory (valid) or not (invalid). During a page fault, the operating system sets the
valid bit accordingly.
8) What is the significance of the page frame number in a page table entry?
The page frame number in a page table entry indicates the location in physical memory where the
corresponding page is stored. It is used to translate virtual addresses to physical addresses.
9) Explain the term "translation lookaside buffer" (TLB) in the context of paging.
The TLB is a small, high-speed cache that stores recently used page table entries. It helps improve the
speed of address translation by providing a quick lookup for virtual-to-physical address mapping without
always accessing the main page table.
10) How does a two-level page table differ from a single-level page table?
A two-level page table is hierarchical, with a top-level page table that points to multiple smaller second-
level page tables. This hierarchical structure helps manage large address spaces more efficiently than a
single-level page table.
EX. 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.
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.tsizettprocess no.ttsize");
for(i = 0; i < bno; i++)
{
printf("n%dtt%dtt", i+1, bsize[i]);
if(flags[i] == 1)
printf("%dttt%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.
EX. 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.
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)
{
if(top < temp)
{
file_arr[m] = n;
top = temp;
}
}
}
fragments[m] = top;
block_arr[file_arr[m]] = 1;
top = 0;
}
}
printf("nFile NumbertFile SizetBlock NumbertBlock SizetFragment");
for(m = 0; m < number_of_files; m++)
{
printf("n%dtt%dtt%dtt%dtt%d", m, files[m], file_arr[m], blocks[file_arr[m]], fragments[m]);
}
printf("n");
return 0;
}
OUTPUT:
RESULT:
Thus a C program to implement the memory management scheme using worst fit algorithm was
executed and output is verified successfully.
.
EX. 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("nt 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");
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%dtt%dtt%dtt%dtt%d",i,f[i],ff[i],b[ff[i]],frag[i]);
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.
VIVA-VOCE QUESTIONS
1) What is the First-Fit memory allocation algorithm?
In the First-Fit algorithm, the first available block of memory that is large enough to accommodate
the process is allocated. It starts searching for free memory from the beginning of the memory space.
2) Explain the advantage of the First-Fit algorithm.
The advantage of the First-Fit algorithm is simplicity and efficiency. It quickly allocates the first
block that fits the process's size.
3) What is the disadvantage of the First-Fit algorithm?
The primary disadvantage is that it may lead to internal fragmentation, as the allocated block might
be larger than the actual size of the process.
4) How does the Best-Fit memory allocation algorithm work?
In the Best-Fit algorithm, the smallest available block that can accommodate the process is
allocated. It involves searching the entire memory space to find the block with the minimum size.
5) What is the advantage of the Best-Fit algorithm?
The advantage of the Best-Fit algorithm is that it aims to minimize internal fragmentation by
selecting the smallest available block that fits the process.
6) What is the disadvantage of the Best-Fit algorithm?
The primary disadvantage is that it may lead to more external fragmentation, as small blocks are
allocated, leaving scattered free memory.
7) How does the Worst-Fit memory allocation algorithm function?
In the Worst-Fit algorithm, the largest available block of memory is allocated to the process. It
involves searching for the maximum-sized block in the entire memory space.
8) What is the advantage of the Worst-Fit algorithm?
The advantage of the Worst-Fit algorithm is that it can lead to fewer allocations, reducing the
likelihood of fragmentation.
9) What is the disadvantage of the Worst-Fit algorithm?
The primary disadvantage is that it may result in significant internal fragmentation, as large blocks
are allocated even if the process is smaller.
10) How do these algorithms handle cases where there is no suitable block for allocation?
In such cases, the process is typically placed in a waiting queue until a suitable block becomes
available, or it may lead to memory compaction or swapping to create larger contiguous blocks.
EX. 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
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 stringt page frmaesn");
for(i=1;i<=n;i++)
{
printf("%dtt",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("%dt",frame[k]);
}
printf("n");
}
printf("page fault is %d",count);
getch();
return 0;
}
OUTPUT:
RESULT:
The program for FIFO page replacement was implemented and hence verified
EX. 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
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("nntEnter the number of page frames : ");
scanf("%d",&n);
printf("nntEnter 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++)
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("nnAfter inserting %d the stack status is : ",ref[i]);
for(j=0;j<top;j++)
printf("%d ",stack[j]);
}
printf("nntEnd to inserting the reference string.");
printf("nntTotal page fault is %d.",fault);
printf("nntPress any key to continue.");
}
void main()
{
int x;
//freopen("in.cpp","r",stdin);
while(1)
{
printf("nnt-----MENU ---- ");
printf("nt1. Input ");
printf("nt2. LRU (Least Recently Used) Algorithm");
printf("nt0. Exit.");
printf("nntEnter your choice.");
scanf("%d",&x);
switch(x)
{
case 1:
input();
break;
case 2:
LRU();
break;
case 0:
exit(0);
}
}
}
OUTPUT:
RESULT:
The program for LRU page replacement was implanted and hence verified.
EX. NO: 12C. IMPLEMENT PAGE REPLACEMENT ALGORITHM USING LEAST
FREQUENTLY USED ALGORITHM
DATE:
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
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 Stringn");
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;
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];
}
for(n = 0; n < total_frames; n++)
{
printf("%dt", frame[n]);
}
printf("n");
}
printf("Page Hit:t%dn", hit);
return 0; }
OUTPUT:
RESULT:
Thus the experiment was successfully compiled and executed
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab
Student manual CSBS (2).pdf for operating systems lab

More Related Content

Similar to Student manual CSBS (2).pdf for operating systems lab

B tech cse syllabus - MITAOE
B tech cse syllabus - MITAOEB tech cse syllabus - MITAOE
B tech cse syllabus - MITAOE
MITAcademy1
 
M.Sc.Syllabus 17 Nov 2022 (1).pdf
M.Sc.Syllabus 17 Nov 2022 (1).pdfM.Sc.Syllabus 17 Nov 2022 (1).pdf
M.Sc.Syllabus 17 Nov 2022 (1).pdf
hsingh5201
 
Digital System Design with FPGAs Lab Manual.pdf
Digital System Design with FPGAs Lab Manual.pdfDigital System Design with FPGAs Lab Manual.pdf
Digital System Design with FPGAs Lab Manual.pdf
AmairullahKhanLodhi1
 
Presentation on po pshjhhjhekhhkkhkhjpeo
Presentation on po pshjhhjhekhhkkhkhjpeoPresentation on po pshjhhjhekhhkkhkhjpeo
Presentation on po pshjhhjhekhhkkhkhjpeo
epandhari
 
B tech information technology syllabus - MITAOE
B tech information technology syllabus - MITAOEB tech information technology syllabus - MITAOE
B tech information technology syllabus - MITAOE
MITAcademy1
 
01.B.E. CSE final.doc
01.B.E. CSE final.doc01.B.E. CSE final.doc
01.B.E. CSE final.doc
tsajuraj
 
2017 BE CSE Syllabus Anna University Affiliated Colleges
2017 BE CSE Syllabus Anna University Affiliated Colleges2017 BE CSE Syllabus Anna University Affiliated Colleges
2017 BE CSE Syllabus Anna University Affiliated Colleges
Fatima Michael College of Engineering and Technology
 
B Tech Civil Engineering Syllabus at MITAOE
B Tech Civil Engineering Syllabus at MITAOEB Tech Civil Engineering Syllabus at MITAOE
B Tech Civil Engineering Syllabus at MITAOE
MITAcademy1
 
IT6511 Networks Laboratory
IT6511 Networks LaboratoryIT6511 Networks Laboratory
IT6511 Networks Laboratory
gayathridevprasad
 
CO PO MAPPING CO3I DMS 22319
CO PO MAPPING CO3I DMS 22319CO PO MAPPING CO3I DMS 22319
CO PO MAPPING CO3I DMS 22319
ARVIND SARDAR
 
2017 b.e.-cse
2017 b.e.-cse2017 b.e.-cse
2017 b.e.-cse
Sheik Mohideen
 
CO PO MAPPING CO3I DMS 22319
CO PO MAPPING CO3I DMS 22319CO PO MAPPING CO3I DMS 22319
CO PO MAPPING CO3I DMS 22319
ARVIND SARDAR
 
DBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTS
DBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTSDBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTS
DBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTS
meghagarg110
 
Ade manual with co po-18scheme
Ade manual with co po-18schemeAde manual with co po-18scheme
Ade manual with co po-18scheme
AMC Engineering College
 
Dbms lab manual
Dbms lab manualDbms lab manual
Dbms lab manual
ArthyR3
 
B tech mechanical engineering syllabus - MITAOE
B tech mechanical engineering syllabus - MITAOEB tech mechanical engineering syllabus - MITAOE
B tech mechanical engineering syllabus - MITAOE
MITAcademy1
 
Outcome Based Education (OBE) - A practitioner's experience
Outcome Based Education (OBE) - A  practitioner's experienceOutcome Based Education (OBE) - A  practitioner's experience
Outcome Based Education (OBE) - A practitioner's experience
Ravindra Dastikop
 
Cs8581 networks lab manual 2017
Cs8581 networks lab manual   2017Cs8581 networks lab manual   2017
Cs8581 networks lab manual 2017
Kayathri Devi D
 
OBE_PPT_CE.pptx
OBE_PPT_CE.pptxOBE_PPT_CE.pptx
OBE_PPT_CE.pptx
satishkolluru1
 

Similar to Student manual CSBS (2).pdf for operating systems lab (20)

B tech cse syllabus - MITAOE
B tech cse syllabus - MITAOEB tech cse syllabus - MITAOE
B tech cse syllabus - MITAOE
 
M.Sc.Syllabus 17 Nov 2022 (1).pdf
M.Sc.Syllabus 17 Nov 2022 (1).pdfM.Sc.Syllabus 17 Nov 2022 (1).pdf
M.Sc.Syllabus 17 Nov 2022 (1).pdf
 
Digital System Design with FPGAs Lab Manual.pdf
Digital System Design with FPGAs Lab Manual.pdfDigital System Design with FPGAs Lab Manual.pdf
Digital System Design with FPGAs Lab Manual.pdf
 
Presentation on po pshjhhjhekhhkkhkhjpeo
Presentation on po pshjhhjhekhhkkhkhjpeoPresentation on po pshjhhjhekhhkkhkhjpeo
Presentation on po pshjhhjhekhhkkhkhjpeo
 
B tech information technology syllabus - MITAOE
B tech information technology syllabus - MITAOEB tech information technology syllabus - MITAOE
B tech information technology syllabus - MITAOE
 
01.b.e. cse final
01.b.e. cse final01.b.e. cse final
01.b.e. cse final
 
01.B.E. CSE final.doc
01.B.E. CSE final.doc01.B.E. CSE final.doc
01.B.E. CSE final.doc
 
2017 BE CSE Syllabus Anna University Affiliated Colleges
2017 BE CSE Syllabus Anna University Affiliated Colleges2017 BE CSE Syllabus Anna University Affiliated Colleges
2017 BE CSE Syllabus Anna University Affiliated Colleges
 
B Tech Civil Engineering Syllabus at MITAOE
B Tech Civil Engineering Syllabus at MITAOEB Tech Civil Engineering Syllabus at MITAOE
B Tech Civil Engineering Syllabus at MITAOE
 
IT6511 Networks Laboratory
IT6511 Networks LaboratoryIT6511 Networks Laboratory
IT6511 Networks Laboratory
 
CO PO MAPPING CO3I DMS 22319
CO PO MAPPING CO3I DMS 22319CO PO MAPPING CO3I DMS 22319
CO PO MAPPING CO3I DMS 22319
 
2017 b.e.-cse
2017 b.e.-cse2017 b.e.-cse
2017 b.e.-cse
 
CO PO MAPPING CO3I DMS 22319
CO PO MAPPING CO3I DMS 22319CO PO MAPPING CO3I DMS 22319
CO PO MAPPING CO3I DMS 22319
 
DBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTS
DBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTSDBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTS
DBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTS
 
Ade manual with co po-18scheme
Ade manual with co po-18schemeAde manual with co po-18scheme
Ade manual with co po-18scheme
 
Dbms lab manual
Dbms lab manualDbms lab manual
Dbms lab manual
 
B tech mechanical engineering syllabus - MITAOE
B tech mechanical engineering syllabus - MITAOEB tech mechanical engineering syllabus - MITAOE
B tech mechanical engineering syllabus - MITAOE
 
Outcome Based Education (OBE) - A practitioner's experience
Outcome Based Education (OBE) - A  practitioner's experienceOutcome Based Education (OBE) - A  practitioner's experience
Outcome Based Education (OBE) - A practitioner's experience
 
Cs8581 networks lab manual 2017
Cs8581 networks lab manual   2017Cs8581 networks lab manual   2017
Cs8581 networks lab manual 2017
 
OBE_PPT_CE.pptx
OBE_PPT_CE.pptxOBE_PPT_CE.pptx
OBE_PPT_CE.pptx
 

Recently uploaded

Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
top1002
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 

Recently uploaded (20)

Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 

Student manual CSBS (2).pdf for operating systems lab

  • 1. DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS AL3452 OPERATING SYSTEMS (BLENDED) MANUAL FOR IV SEMESTER B.TECH. DEGREE COURSE [REGULATION-2021] As per the prescribed syllabus by ANNA UNIVERSITY CHENNAI - 600025
  • 2. R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/1 DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS MANUAL SUBJECT CODE : AL3452 SUBJECT NAME : OPERATING SYSTEMS REGULATION : 2021 ACADEMIC YEAR : 2023-2024 YEAR / SEMESTER : II / IV BATCH : 2022 – 2026 Prepared by: Verified by: Approved by: Name: Name: Name: Date: Date: Date:
  • 3. R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/2 COLLEGE VISION Emerge as a Premier Institute, producing globally competent engineers. COLLEGE MISSION IM1: Achieve Academic diligence through effective and innovative teaching-learning processes, using ICT Tools. IM2: Make students employable through rigorous career guidance and training programs. IM3: Strengthen Industry Institute Interaction through MOUs and Collaborations. IM4: Promote Research & Development by inculcating creative thinking through innovative projects incubation.
  • 4. R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/3 VISION AND MISSION OF THE DEPARTMENT VISION To create skilled, industry ready professionals in the domain of Computer Science and Business Systems who could make a positive contribution to society through an understanding of information technology. MISSION DM 1 : To foster student talent and enable them to compete worldwide through innovative teaching, research, and consultancy. DM 2 : To regulate prospectus to reflect changing industry demands. DM 3 : To instill a variety of skill sets that adhere to industry standards and to uphold moral principles. DM 4 : To develop professional ethics and life skills in individuals which lead them to serve the society.
  • 5. R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/4 PROGRAM EDUCATIONAL OBJECTIVES (PEO) PEO 1 : To guarantee that graduates will be adept in applying the core knowledge of basic sciences, math, computer science, and business systems for the applications pertinent to diverse streams of engineering and technology. PEO 2 : To enhance graduates fundamental competencies to apply computer science and data analytics tools knowledge to store, retrieve, deploy, and analyse data in the context of corporate enterprise. PEO 3 : To help graduates enter the workforce, establish themselves as professionals, and satisfy the diverse demands of business, academia, and research by putting their technical expertise and leadership abilities to use. PEO 4: Entrepreneurs: To provide graduates with entrepreneurial abilities and traits that will enable them to comprehend how businesses run, recognise business issues, look for business possibilities, and become ready to manage businesses successfully. PROGRAM SPECIFIC OBJECTIVES (PSO) PSO 1 : To develop, pick, and use relevant methods, resources, contemporary engineering tools, and business tools, such as data analytics and prediction, for complicated engineering operations and business solutions and to develop domain-specific approaches for decision-making in a number of important real-world problem domains. PSO 2 : To be able to use management techniques and entrepreneurial skills to find, evaluate, and create business opportunities with clever business ideas and to manage complex IT projects with an awareness of risk management procedures, operational ramifications, and ethical, financial, and environmental considerations
  • 6. R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/5 PROGRAM OUTCOMES (POs) PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an engineering specialization to the solution of complex engineering problems. PO2: 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. PO3: 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. PO4: 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. PO5: 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. PO6: 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. PO7: 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. PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering practice. PO9: Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams, and in multidisciplinary settings. PO10: 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. PO11: 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. PO12: 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.
  • 7. R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/6 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. COURSE OUTCOMES At the end of this course, the students will be able to: CO1: Implement the installation process of windows OS in a step by step procedure, and implement UNIX commands. CO2: Implement various CPU Scheduling Algorithms, and understand Semaphore, Deadlock Avoidance and Deadlock Detection Algorithms. CO3: Understand the purpose of Memory Allocation Methods in a computer and can compare and contrast between the various memory allocation methods. CO4: Develop and define File Organization and File Allocation Strategies to improve the performance of a computer. CO5: Implement various Disk Scheduling Algorithms to minimize the seek time and rotational latency, thereby improving the overall performance of the system. CO – PO & PSO MAPPING SNO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 CO1 3 1 1 1 - - - - - - - - 1 - CO2 3 3 3 1 - - - - - - - - 1 - CO3 3 3 3 3 - - - - - - - - 1 - CO4 3 3 3 3 - - - - - - - - 1 - CO5 3 3 3 3 - - - - - - - - 1 - Avg 3 2.6 2.6 2.2 - - - - - - - - 1 -
  • 8. R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/7 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.
  • 9. R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/8 SYLLABUS R – 2021 A L3452 OPERATING SYSTEMS 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 TOTAL:30 PERIODS COURSE OUTCOMES: At the end of this course, the students will be able to: CO1: Implement the installation process of windows OS in a step by step procedure,and implement UNIX commands. CO2: Implement various CPU Scheduling Algorithms, and understand Semaphore, Deadlock Avoidance and Deadlock Detection Algorithms. CO3: Understand the purpose of Memory Allocation Methods in a computer and can compare and contrast between the various memory allocation methods. CO4: Develop and define File Organization and File Allocation Strategies to improve the performance of a computer. CO5: Implement various Disk Scheduling Algorithms to minimize the seek time and rotational latency, thereby improving the overall performance of the system. L T P C 3 0 2 4
  • 10. R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/9 LIST OF EXPERIMENTS - CO MAPPING EXP.NO TITLE OF THE PROGRAM CO’S 1 Installation of Windows Operating System CO1 2A Basics of Unix Commands CO1 2B Shell Programming (Even or Odd) CO1 2C Shell Programming (Biggest of Two Numbers) CO1 2D Shell Programming (Biggest of Three Numbers) CO1 2E Shell Programming (Factorial of a Number) CO1 2F Shell Programming (Fibonacci Series) CO1 3A The Fork System Call CO1 3B The Exit System Call CO1 3C The Getpid System Call CO1 3D Wait System Call CO1 3E Close System Call CO1 4A First Come First Serve Scheduling CO2 4B Shortest Job Fist Scheduling Algorithm CO2 4C Priority Scheduling CO2 4D Round Robin Scheduling CO2 5 Implementation of IPC using PIPE CO2 6 Implementation of Producer Consumer Problem using Semaphore CO2 7 Implementation of Bankers Algorithm for Dead Lock Avoidance CO2 8 Implementation of Deadlock Detection Algorithm CO2 9 Implement Threading & Synchronization Applications CO2 10 Memory Management Scheme using Paging CO3 11A Implementation of First Fit Algorithm CO3 11B Implementation of Worst Fit Algorithm CO3 11C Implementation of Best Fit Algorithm CO3
  • 11. R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/10 12A Implementation of Page Replacement Algorithm (FIFO) CO3 12B Implementation of Page Replacement Algorithm (LRU) CO3 12C Implementation of Page Replacement Algorithm using Least Frequently Used Algorithm CO3 13A Implementation of File Organization Techniques using Single Level Directory CO4 13B Implementation of File Organization Techniques using Two Level Directory CO4 13C Implementation of File Organization Techniques using Hierarchical Level Directory CO4 13D Implementation of File Organization Techniques Using DAG CO4 14A Implementation of Sequential File Allocation Strategies CO4 14B Implementation of Indexed File Allocation Strategies CO4 14C Implementation of Linked File Allocation Strategies CO4 15A Implementation of FCFS Disk Scheduling Algorithm CO5 15B Implementation of SSTF Disk Scheduling Algorithm CO5 CONTENT BEYOND THE SYLLABUS 16 UNIX Editors CO1 17 IPC Shared Memory CO3
  • 12. R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/11 INDEX S.No. Date Name Of The Experiment Page No Marks Faculty Sign 1 Installation of Windows Operating System 2A Basics of Unix Commands 2B Shell Programming (Even or Odd) 2C Shell Programming (Biggest of Two Numbers) 2D Shell Programming (Biggest of Three Numbers) 2E Shell Programming (Factorial of a Number) 2F Shell Programming (Fibonacci Series) 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 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
  • 13. R2021/ CSBS/ AL3452 OPERATING SYSTEMS/ IIYEAR/IV SEM/12 12A Implementation of Page Replacement Algorithm (FIFO) 12B Implementation of Page Replacement Algorithm (LRU) 12C Implementation of Page Replacement Algorithm using Least Frequently Used Algorithm 13A Implementation of File Organization Techniques using Single Level Directory 13B Implementation of File Organization Techniques using Two Level Directory 13C Implementation of File Organization Techniques using Hierarchical Level Directory 13D Implementation of File Organization Techniques Using DAG 14A Implementation of Sequential File Allocation Strategies 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 CONTENT BEYOND THE SYLLABUS 16 UNIX Editors 17 IPC Shared Memory
  • 14. EX. 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. 3. You can see that the tool is downloaded now. Now, run the downloaded file.
  • 15. 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. 5. Now, select "Create installation media for another PC" option. See the below image:
  • 16. 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: 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.
  • 17. 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. 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:
  • 18. 14. Click on the install now button and follow the given instructions to install Windows 10 on your system successfully. 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.
  • 19. 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.
  • 20. VIVA-VOCE QUESTIONS 1) What are the minimum hardware requirements for installing Windows 10? The minimum hardware requirements for Windows 10 include a 1 GHz or faster processor, 1 GB (32-bit) or 2 GB (64-bit) RAM, 16 GB (32-bit) or 20 GB (64-bit) of free hard disk space, and a DirectX 9 graphics device with WDDM 1.0 or higher driver. 2) How can you boot from a Windows installation media (DVD/USB)? You need to access the BIOS or UEFI firmware settings during the system startup and set the boot order to prioritize the DVD/USB drive. Save the changes and restart the computer with the installation media inserted. 3) What is the purpose of the Windows Setup program? The Windows Setup program guides users through the process of installing or upgrading the Windows operating system. It allows users to choose installation options, partition the disk, and install device drivers. 4) Explain the difference between an upgrade and a clean installation. An upgrade installs a new version of Windows while preserving user files, settings, and applications. A clean installation involves formatting the existing disk and installing Windows from scratch, resulting in the loss of all data on the drive. 5) What is the importance of device drivers during the Windows installation process? Device drivers enable communication between the operating system and hardware components. During installation, Windows Setup installs generic drivers to facilitate the installation process, and later, you may need to install specific drivers for optimal hardware functionality. 6) Describe the steps involved in partitioning the hard disk during Windows installation. Windows installation allows you to create, delete, and format partitions. You can create new partitions, select an existing partition for installation, or let Windows create the necessary partitions automatically. It's crucial to choose the right partition for installation to avoid data loss. 7) What is the purpose of the Product Key during Windows installation? The Product Key is a unique alphanumeric code that verifies the legitimacy of the Windows copy being installed. It is required during installation to activate and validate the operating system. 8) How can you customize the installation options during the Windows Setup process? Windows Setup provides customization options such as selecting the installation location, choosing between an upgrade or clean install, configuring user accounts, and specifying regional settings. Users can tailor these options according to their preferences and requirements.
  • 21. EX. NO: 2a 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
  • 22. 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: Output : acet 12ee01@localhost]:~ $ who tty7 2010-02-10 15:34 (:0) acet pts/0 2010-02-10 05:05 (:0.0) 12ee01@localhost]:~ $ Example: Output : 12ee01@localhost]:~ $ who –a system boot 2010-02-10 15:34 run-level 2 2010-02-10 15:34 last= LOGIN tty4 2010-02-10 15:34 2103 id=4
  • 23. 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 No mail. No Plan. 12ee01@localhost]:~ $
  • 24. 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]:~ $ Output : 12ee01@localhost]:~ $ cat check1 Hello 12ee01@localhost]:~ $ 2. cat command
  • 25. 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 3.cat command 12ee01@localhost]:~ $ 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). 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
  • 26. 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 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]:~ $
  • 27. 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 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]:~ $
  • 28. 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$ 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:~$
  • 29. 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]:~ $ 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.
  • 30. EX. NO: 2(B) SHELL PROGRAMMING (EVEN OR ODD) DATE: AIM: To write a program to find whether a number is even or odd using shell programming ALGORITHM: STEP 1: Read the input number. STEP 2: Perform modular division on input number by 2. STEP 3: If remainder is 0 print the number is even. STEP 4: Else print number is odd. STEP 5: Stop the program. PROGRAM echo "enter the number" read num echo "enter the number" read num if [ `expr $num % 2` -eq 0 ] then echo "number is even" else echo "number is odd" OUTPUT: Enter the number: 5 The number is odd. RESULT: Thus the program has been executed successfully.
  • 31. EX. NO: 2(C) SHELL PROGRAMMING (BIGGEST OF TWO NUMBERS) DATE: AIM : To write a program to find biggest in two numbers. ALGORITHM : STEP 1: Read The Two Numbers. STEP 2: If Value Of A Is Greater Than B Is Big. STEP 3: Else Print B Is Big. STEP 4: Stop The Program. PROGRAM: echo "enter the number" read a b if [ $a -gt $b ] then echo "A is big" else echo "B is big" fi OUTPUT: RESULT: Thus the program has been executed successfully.
  • 32. EX. NO: 2(D) SHELL PROGRAMMING (BIGGEST OF THREE NUMBERS) DATE: AIM: To Write a Program to Find Biggest In Three Numbers. ALGORITHM: STEP 1: Read The Three Numbers. STEP 2: If A Is Greater Than B And A Is Greater Than C Then Print A Is Big. STEP 3: Else If B is greater Than C Then C Is Big. STEP 4: Else Print C Is Big. STEP 5: Stop The Program. PROGRAM: echo "enter three numbers" read a b c if [ $a -gt $b ] && [ $a -gt $c ] then echo "A is big" else if [ $b -gt $c ] then echo "B is big" else echo "C is big" fi fi OUTPUT: RESULT: Thus the program has been executed successfully.
  • 33. EX. NO: 2(E) SHELL PROGRAMMING (FACTORIAL OF NUMBER) DATE: AIM: To find a factorial of a number using shell script. ALGORITHM: Step 1: read a number. Step 2: Initialize fact as 1. Step 3: Initialize I as 1. Step 4: While I is lesser than or equal to no. Step 5: Multiply the value of I and fact and assign to fact increment the value of I by 1. Step 6: print the result. Step 7: Stop the program. PROGRAM: echo "enter the number" read n fact=1 i=1 while [ $i -le $n ] do fact=`expr $i * $fact` i=`expr $i + 1` done echo "the fcatorial number of $ni is $fact OUTPUT: RESULT: Thus the program has been executed successfully.
  • 34. EX. NO: 2(F) SHELL PROGRAMMING (FIBONACCI SERIES) 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.
  • 35. 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 : RESULT: Thus the program has been executed successfully
  • 36. VIVA-VOCE QUESTIONS 1) What is the shell in Unix? The shell is the command-line interpreter in Unix-like operating systems. It takes commands from the user and executes them by interacting with the kernel. 2) How do you display the current working directory in Unix? The pwd command is used to display the current working directory. 3) What is the purpose of the ls command? The ls command is used to list the contents of a directory. 4) How can you navigate to the home directory quickly? The cd command without any arguments takes you to the home directory. For example, cd or cd ~. 5) Explain the use of the cp command. The cp command is used to copy files or directories. For example, cp file1.txt file2.txt copies the contents of file1.txt to file2.txt. 6) How do you create a new directory in Unix? The mkdir command is used to create a new directory. For example, mkdir my_directory creates a new directory named my_directory. 7) What is the purpose of the rm command? The rm command is used to remove or delete files or directories. For example, rm file.txt deletes the file named file.txt. 8) How can you display the contents of a file in Unix? The cat command is used to display the contents of a file. For example, cat filename.txt shows the contents of filename.txt. 9) Explain the use of the man command. The man command is used to display the manual or documentation for other Unix commands. For example, man ls shows the manual for the ls command. 10) How can you find files in Unix based on their names? The find command is used to search for files and directories based on various criteria, including their names. For example, find /path/to/search -name filename.txt searches for a file named filename.txt in the specified path.
  • 37. EX. 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; }
  • 38. OUTPUT: RESULT: Thus the C program using fork system call was executed and output is verified successfully.
  • 39. EX. 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.
  • 40. 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:%dn”,exit_status); } return 0; } OUTPUT RESULT Thus the C program using exit system call was executed and output is verified successfully.
  • 41. EX. 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; }
  • 42. OUTPUT: RESULT: Thus the C program to implement getpid system call was executed and output is verified successfully.
  • 43. EX. 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 forkn"); pid=fork(); if(pid==0) { printf("Child statesn"); for(i=0;i<10;i++) printf("%d t",i); printf("Child endsn"); } else
  • 44. { wait(0); for(i=0;i<10;i++) printf("%d t",i); printf("Parent process endn"); }} OUTPUT: RESULT: Thus the C program to implement wait system call was executed and output is verified successfully.
  • 45. EX. 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.
  • 46. 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 = % dn", fd1); // Using close system Call if (close(fd1) < 0) { perror("c1"); exit(1); } printf("closed the fd.n"); } OUTPUT RESULT Thus the C program to implement close system call was executed and output is verified successfully.
  • 47. VIVA-VOCE QUESTIONS 1) What is a system call? A system call is a mechanism by which a program requests a service from the operating system kernel. It provides a way for user-level applications to interact with the operating system to perform tasks such as file operations, process control, memory management, and input/output operations. 2) How are system calls different from regular function calls? System calls involve a switch from user mode to kernel mode, allowing the program to request privileged services from the operating system. Regular function calls, on the other hand, execute within the user mode without the need for a mode switch. 3) Can you give examples of common system calls? fork() for creating a new process open() for opening a file read() and write() for reading from and writing to files 4) What is the purpose of CPU scheduling? The primary purpose of CPU scheduling is to maximize the utilization of the CPU and minimize the turnaround time, waiting time, and response time for processes. 5) What is a CPU burst? A CPU burst is the amount of time a process uses the CPU without being interrupted by the operating system. It consists of a sequence of instructions that the process executes in a single run on the CPU. 6) What is preemptive scheduling? Preemptive scheduling allows the operating system to interrupt a currently running process to start or resume another, usually with a higher priority. It ensures that no process monopolizes the CPU for an extended period. 7) What is a deadlock? A deadlock is a state in a computer system where two or more processes are unable to proceed because each is waiting for the other to release a resource, resulting in a circular waiting condition. 8) Explain the necessary conditions for a deadlock to occur. Deadlock requires four necessary conditions: mutual exclusion, hold and wait, no preemption, and circular wait. If all these conditions hold simultaneously, a deadlock can occur. 9) How does mutual exclusion contribute to deadlock? Mutual exclusion means that only one process can use a resource at a time. If a process holds a resource and requests another while keeping the first one, it can lead to a situation where multiple processes are waiting for each other to release resources, causing a deadlock. 10) What is the hold and wait condition in deadlock? The hold and wait condition occur when a process holds one resource while waiting for another. If multiple processes are holding resources and waiting for additional ones, it can lead to a deadlock.
  • 48. EX. 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.
  • 49. 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("ntt Gantt chart n"); printf("ProcessName StartTime BurstTime n"); for(i=0;i<num;i++){ bt=start+burst[i]; printf("%ctt%ft%fn",procno[i],start,bt); wait=wait+start; start=start+burst[i]; } avgwait=wait/num; printf("Average waiting time of a process= %fn",avgwait); printf("Total running time of process= %fn",start); return 0;}
  • 50. OUTPUT: RESULT: Thus the C program to implement the first come first serve scheduling was executed and output is verified successfully.
  • 51. EX. NO: 4B. SHORTEST JOB FIRST 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]);
  • 52. scanf("%f",&burst[i]); } for(i=0;i<num;i++) { if(burst[i]>burst[i+1]) { swap(i); i=-1; } } printf("ntt Gantt chart n"); printf("ProcessName StartTime BurstTime n"); for(i=1;i<=num;i++) { bt=start+burst[i]; printf("%ctt%ft%fn",procno[i],start,bt); wait=wait+start; start=start+burst[i]; } avgwait=wait/num; printf("Average waiting time of a process= %fn",avgwait); printf("Total running time of process= %fn",start); return 0; } void swap(int j) { char temp; float tbt; temp=procno[j]; tbt=burst[j]; procno[j]=procno[j+1]; burst[j]=burst[j+1];
  • 53. procno[j+1]=temp; burst[j+1]=tbt; } OUTPUT: RESULT: Thus the C program to implement the shortest job first scheduling was executed and output is verified successfully.
  • 54. EX. 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); printf("Enter the process name,priority and burst time:n"); for(i=0;i<num;i++)
  • 55. { 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("ntt Gantt chart nn"); printf("ProcessNametPrioritytStarttBurst n"); for(i=1;i<=num;i++) { bt=start+burst[i]; printf("%cttt%dtt%ft%fn",procno[i],priority[i],start,bt); wait=wait+start; start=start+burst[i]; } avgwait=wait/num; printf("Average waiting time of a process= %fn",avgwait); printf("Total running time of process= %fn",start); return 0; } void swap(int j) { char temp; float tbt; int pri;
  • 57. RESULT: Thus the C program to implement the priority scheduling was executed and output is verified successfully.
  • 58. EX. 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]; } printf("Enter time quantum:"); scanf("%d",&tq);
  • 60. printf("nProcess_no tBurst time tWait time tTurn around time n"); for(i=0;i<n;i++) printf("n%dtt%dtt%dtt%d ",i+1,bt[i],wt[i],tat[i]); printf("n Average wait time is %ftn Average turnaround time is %ftn",awt,atat); } OUTPUT: RESULT: Thus the C program to implement the round robin scheduling was executed and output is verified successfully.
  • 61. VIVA-VOCE QUESTIONS 1) What is CPU scheduling? CPU scheduling is the process by which the operating system manages the execution of processes in a computer system. It determines which process should run next, allocates CPU time to that process, and ensures fair and efficient utilization of the CPU. 2) What is the purpose of CPU scheduling? The primary purpose of CPU scheduling is to maximize the utilization of the CPU and minimize the turnaround time, waiting time, and response time for processes. 3) What is a CPU burst? A CPU burst is the amount of time a process uses the CPU without being interrupted by the operating system. It consists of a sequence of instructions that the process executes in a single run on the CPU. 4) What is preemptive scheduling? Preemptive scheduling allows the operating system to interrupt a currently running process to start or resume another, usually with a higher priority. It ensures that no process monopolizes the CPU for an extended period. 5) Explain the difference between preemptive and non-preemptive scheduling. In preemptive scheduling, a running process can be interrupted and moved to the ready queue, allowing another process to start. In non-preemptive scheduling, a running process cannot be interrupted, and it continues until it voluntarily releases the CPU. 6) What is turnaround time in CPU scheduling? Turnaround time is the total time taken by a process to complete execution, including both waiting time and execution time. It is a measure of the overall efficiency of the CPU scheduling algorithm. 7) Describe the First-Come-First-Serve (FCFS) scheduling algorithm. FCFS is a non-preemptive scheduling algorithm where processes are executed in the order they arrive in the ready queue. It suffers from the "convoy effect" and may result in a long average waiting time. 8) What is the Shortest Job Next (SJN) scheduling algorithm? SJN, also known as Shortest Job First (SJF), selects the process with the smallest total remaining processing time. It can be preemptive (Shortest Remaining Time First - SRTF) or non-preemptive. 9) Explain the Round Robin (RR) scheduling algorithm. Round Robin is a preemptive scheduling algorithm where each process is assigned a fixed time slice (quantum) to execute before moving to the next process in the ready queue. It provides fair sharing of the CPU. 10) What is priority scheduling? Priority scheduling assigns priority levels to processes, and the process with the highest priority is selected for execution first. It can be preemptive or non-preemptive, and it helps in giving preference to more critical or important tasks
  • 62. EX. 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
  • 63. 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 pipen"); return 1; } printf("Writing to pipe - Message 1 is %sn", writemessages[0]); write(pipefds[1], writemessages[0], sizeof(writemessages[0])); read(pipefds[0], readmessage, sizeof(readmessage)); printf("Reading from pipe – Message 1 is %sn", readmessage); printf("Writing to pipe - Message 2 is %sn", writemessages[0]); write(pipefds[1], writemessages[1], sizeof(writemessages[0])); read(pipefds[0], readmessage, sizeof(readmessage)); printf("Reading from pipe – Message 2 is %sn", readmessage); return 0; }
  • 64. OUTPUT RESULT Thus the C program to implement inter process communication using PIPE was executed and output is verified successfully.
  • 65. VIVA-VOCE QUESTIONS 1) What is Inter-Process Communication (IPC)? IPC refers to mechanisms that allow processes to communicate and exchange data with each other. It enables coordination and data sharing between processes running concurrently in a computer system. 2) What is a pipe in the context of IPC? In the context of IPC, a pipe is a unidirectional communication channel that allows data to be transmitted between two processes. One process writes to the pipe, and the other process reads from it. 3) How is a pipe created in Unix? The pipe() system call is used to create a pipe in Unix. It returns two file descriptors: one for writing to the pipe (fd[1]) and one for reading from the pipe (fd[0]). 4) Explain the relationship between the writing and reading ends of a pipe. The writing end of the pipe (fd[1]) is used by one process to write data into the pipe, and the reading end (fd[0]) is used by another process to read that data. It forms a unidirectional communication channel. 5) How can data be transferred between processes using a pipe? One process writes data into the writing end of the pipe (fd[1]), and another process reads from the reading end of the pipe (fd[0]). The data is transferred from the writer to the reader through the pipe. 6) What happens if a process writes to a pipe that is full? If a process attempts to write to a full pipe, it will be blocked until space is available. This blocking mechanism ensures synchronization between the writer and the reader. 7) How does a process close a pipe after using it? A process can close a pipe by using the close() system call on both the reading and writing ends of the pipe (fd[0] and fd[1]). This indicates that the process has finished using the pipe. 8) Can a pipe be used for communication between non-related processes? No, a pipe is typically used for communication between related processes, such as a parent and its child processes. For communication between unrelated processes, other IPC mechanisms like named pipes or message queues may be more suitable. 9) How can you implement a simple command pipeline using pipes? A command pipeline can be implemented by creating multiple processes, connecting the output of one process to the input of the next using pipes. For example, command1 | command2. 10) What is the difference between a named pipe (FIFO) and an unnamed pipe? An unnamed pipe is created using the pipe() system call and exists in the file system as an unnamed file. A named pipe (FIFO) is created using the mkfifo() system call and has a name associated with it, allowing unrelated processes to communicate.
  • 66. EX. 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.PRODUCERn2.CONSUMERn3.EXITn"); while(1)
  • 67. { printf("nENTER YOUR CHOICEn"); 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);
  • 68. 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: RESULT: Thus the C program to implement the producer consumer problem was executed and output is verified successfully.
  • 69. VIVA-VOCE QUESTIONS 1) What is the Producer-Consumer problem? The Producer-Consumer problem is a classic synchronization problem where there are two types of processes, producers, and consumers, that share a common, fixed-size buffer as a communication medium. The challenge is to ensure that the producers do not produce items if the buffer is full, and consumers do not consume items if the buffer is empty. 2) How can semaphores be used to solve the Producer-Consumer problem? Semaphores can be used to synchronize access to the shared buffer. Two semaphores, one for controlling access to the critical section (mutex) and another for tracking the number of available slots in the buffer, are commonly used. 3) Explain the role of the mutex semaphore in the Producer-Consumer problem. The mutex (mutual exclusion) semaphore ensures that only one process (either a producer or a consumer) can access the critical section, i.e., modify the buffer, at any given time. It prevents race conditions. 4) What does the counting semaphore represent in the Producer-Consumer problem? The counting semaphore represents the number of available slots in the buffer. It is decremented by producers when they add items to the buffer and incremented by consumers when they remove items. This semaphore helps in tracking the fullness of the buffer. 5) How can you initialize the semaphores for solving the Producer-Consumer problem? The mutex semaphore is initialized to 1, and the counting semaphore is initialized to the maximum buffer size, indicating that the buffer is initially empty. 6) How is mutual exclusion achieved using semaphores? Mutual exclusion is achieved by using the mutex semaphore. Before entering the critical section (modifying the buffer), a process must acquire the mutex semaphore. After completing the critical section, it releases the mutex semaphore. 7) Explain how a producer adds an item to the buffer using semaphores. The producer must first acquire the mutex semaphore. Once acquired, it checks if there is space in the buffer (counting semaphore is greater than 0). If there is space, it adds an item to the buffer, decrements the counting semaphore, and releases the mutex semaphore. 8) How does a consumer remove an item from the buffer using semaphores? Similar to the producer, the consumer must acquire the mutex semaphore before entering the critical section. Once acquired, it checks if there are items in the buffer (counting semaphore is less than the buffer size). If there are items, it removes one, increments the counting semaphore, and releases the mutex semaphore. 9) What is the purpose of using semaphores in the Producer-Consumer problem? Semaphores are used to provide synchronization and mutual exclusion, ensuring that the shared buffer is accessed in a controlled manner. They help prevent race conditions and ensure the correct functioning of producers and consumers. 10) Can semaphores alone solve the Producer-Consumer problem? Yes, semaphores provide a powerful mechanism for solving synchronization problems, including the Producer-Consumer problem. They help in coordinating the activities of producers and consumers and ensure that the buffer is accessed safely.
  • 70. EX. 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.
  • 71. 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("nnEnter the no of resources : "); scanf("%d", &r); printf("nnEnter 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("nnEnter 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("nnEnter the Available Resources : "); for(i = 0; i < r; i++) scanf("%d", &avail[i]);
  • 72. 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("tt"); 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) {
  • 73. 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: RESULT: Thus the C program to implement deadlock avoidance using banker’s algorithm was executed and output is verified successfully.
  • 74. VIVA-VOCE QUESTIONS 1) What is the Banker's Algorithm? The Banker's Algorithm is a deadlock avoidance algorithm used in operating systems to determine whether granting a resource request from a process would leave the system in a safe state or risk entering a deadlock. 2) What are the essential data structures used in the Banker's Algorithm? The essential data structures include the available vector, the maximum matrix, the allocation matrix, and the need matrix. 3) Explain the available vector in the Banker's Algorithm. The available vector represents the number of available instances of each resource in the system. It is a one-dimensional array with the same number of elements as there are types of resources. 4) What is the maximum matrix in the context of the Banker's Algorithm? The maximum matrix specifies the maximum demand of each process for each resource type. It is a two- dimensional matrix where each row corresponds to a process, and each column corresponds to a resource type. 5) What does the allocation matrix represent? The allocation matrix indicates the number of resources of each type currently allocated to each process. Like the maximum matrix, it is a two-dimensional matrix with rows representing processes and columns representing resource types. 6) Explain the need matrix in the context of the Banker's Algorithm. The need matrix represents the remaining needs of each process for each resource type to complete its execution. It is calculated by subtracting the allocation matrix from the maximum matrix. 7) How does the Banker's Algorithm assess whether a resource request can be granted? The Banker's Algorithm assesses a resource request by temporarily modifying the state of the system, checking if the resulting state is safe. If the system remains in a safe state after granting the request, it is deemed acceptable; otherwise, the request is denied. 8) What is a safe state in the Banker's Algorithm? A safe state is a state in which there exists a sequence of processes that can complete their execution without causing a deadlock. The Banker's Algorithm aims to ensure that the system remains in a safe state after any sequence of resource requests. 9) How does the Banker's Algorithm handle resource requests? When a process makes a resource request, the algorithm first checks if the request can be granted without violating the system's safety. If so, the resources are allocated, and the system's state is updated. If not, the request is denied, and the system remains unchanged. 10) What is the role of the safety algorithm in the Banker's Algorithm? The safety algorithm is used to determine whether the system is in a safe state. It simulates the allocation of resources for each process's maximum needs and checks if a safe execution sequence exists.
  • 75. EX. 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) matrixn"); 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 matrixn"); for(i=1;i<=tp;i++) { printf("process %d:n",i);
  • 76. for(j=1;j<=tr;j++) scanf("%d",&p[i][j]); } 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:");
  • 78. VIVA-VOCE QUESTIONS 1) What is deadlock detection? Deadlock detection is a mechanism used in operating systems to identify whether a system is in a deadlock state where processes are unable to proceed because each is waiting for the other to release resources. 2) Why is deadlock detection necessary? Deadlock detection is necessary to identify and resolve deadlocks that may occur in a system. It allows the operating system to take corrective actions, such as terminating processes or releasing resources, to break the deadlock and restore system functionality. 3) What are the commonly used approaches for deadlock detection?  Periodic polling  Wait-Die and Wound-Wait Schemes. 4) How does the periodic polling approach work for deadlock detection? In periodic polling, the operating system checks the state of the system at regular intervals to identify any potential deadlocks. It involves examining the resource allocation graph or other data structures to determine if a cycle exists, indicating a deadlock. 5) What is the resource allocation graph, and how is it used in deadlock detection? The resource allocation graph is a directed graph that represents the allocation of resources to processes and the relationships between them. Deadlocks can be detected by finding cycles in this graph, indicating circular waiting. 6) Explain the Wait-Die and Wound-Wait deadlock detection schemes. Wait-Die Scheme: In this scheme, older transactions (processes) are allowed to wait for resources, but younger transactions requesting resources held by older ones are aborted. Wound-Wait Scheme: Older transactions requesting resources held by younger transactions are allowed to wait, while younger transactions requesting resources held by older ones are aborted. 7) How does the operating system identify a deadlock using the Wait-Die and Wound-Wait schemes? When a process requests a resource, the operating system checks the age of the requesting process and the age of the process holding the resource. Based on the scheme (Wait-Die or Wound-Wait), the system decides whether to allow the waiting or to abort the requesting process to break the potential deadlock. 8) Can deadlock detection prevent deadlocks from occurring? No, deadlock detection cannot prevent deadlocks. It can only identify and resolve existing deadlocks. Prevention techniques, such as deadlock avoidance using the Banker's Algorithm, aim to eliminate the conditions that lead to deadlocks. 9) What are the advantages of deadlock detection over prevention? Deadlock detection has the advantage of not requiring prior knowledge of resource usage patterns. It can handle dynamic and unpredictable scenarios but comes with the cost of periodic checks and potential delays in detecting deadlocks. 10) How does the operating system resolve a deadlock after detection? After detecting a deadlock, the operating system can take various actions, including terminating one or more processes involved in the deadlock, releasing resources held by these processes, or rolling back the execution state to a safe point.
  • 79. EX. 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
  • 80. 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 startedn", counter); for(i=0; i<(0xFFFFFFFF);i++); printf("n Job %d finishedn", 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;}
  • 81. OUTPUT RESULT Thus a C program to implement the threading and synchronization applications was executed and output is verified successfully.
  • 82. VIVA-VOCE QUESTIONS 1) What is a thread? A thread is the smallest unit of execution within a process. It represents an independent flow of control and shares resources, such as memory space and file descriptors, with other threads within the same process. 2) Why do we use threads in programming? Threads are used in programming to achieve parallelism, responsiveness, and efficient resource utilization. They allow multiple tasks to execute concurrently within a single process, improving overall system performance. 3) How is threading different from multiprocessing? Threading involves multiple threads within the same process sharing the same resources, while multiprocessing involves multiple independent processes, each with its own resources. 4) Explain the concept of thread synchronization. Thread synchronization is the coordination of multiple threads to ensure that they access shared resources in a mutually exclusive and orderly manner, preventing race conditions and maintaining data consistency. 5) What is a critical section? A critical section is a part of the code where shared resources are accessed and modified by multiple threads. It needs to be protected to prevent conflicts and ensure the correct functioning of the program. 6) How can you implement thread synchronization? Thread synchronization can be implemented using synchronization primitives like mutexes, semaphores, and condition variables. These mechanisms ensure exclusive access to critical sections and coordinate thread activities. 7) What is a mutex? A mutex (short for mutual exclusion) is a synchronization primitive that provides exclusive access to a shared resource. It allows only one thread to enter the critical section at a time. 8) Explain the concept of a semaphore. A semaphore is a synchronization primitive that maintains a counter. It is used to control access to a shared resource by multiple threads and allows a specified number of threads to access the resource simultaneously. 9) What is the purpose of a condition variable? A condition variable is used for signaling and coordinating threads. It allows threads to wait until a certain condition is met, and it can be used in conjunction with mutexes to ensure orderly access to shared resources. 10) How do you create and manage threads in a programming language that supports multithreading? The process of creating and managing threads depends on the programming language and its threading library. Generally, it involves creating thread objects, defining thread functions, starting threads, and managing synchronization.
  • 83. EX. 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++)
  • 84. { 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); }
  • 85. OUTPUT: RESULT: Thus the C program to implement the memory management scheme using paging algorithm was executed and output is verified successfully.
  • 86. VIVA-VOCE QUESTIONS 1) What is paging in the context of memory management? Paging is a memory management scheme that allows a computer's physical memory to be non-contiguous. It divides the physical memory into fixed-size blocks called "frames" and logically divides the process's virtual memory into fixed-size blocks called "pages." 2) How does paging help overcome the limitations of contiguous memory allocation? Paging allows processes to be loaded into non-contiguous physical memory locations. It eliminates the need for a contiguous block of memory, making better use of available memory space and simplifying memory allocation. 3) What is a page table? A page table is a data structure used in paging systems to map virtual addresses to corresponding physical addresses. It contains entries that specify the frame number in physical memory for each page in the process's virtual address space. 4) How is the size of a page determined in a paging system? The size of a page is determined by the hardware and is typically a power of 2, such as 4 KB or 8 KB. The page size affects the granularity of memory allocation and can impact system performance. 5) Explain the concept of a page fault. A page fault occurs when a program attempts to access a page that is not currently in physical memory. The operating system must then bring the required page into memory from secondary storage, updating the page table accordingly. 6) What is the role of the page table in handling a page fault? The page table is consulted to find the frame number of the required page. If the page is not in physical memory (a page fault occurs), the operating system uses the page table to determine the location of the page on the secondary storage device and brings it into physical memory. 7) How does the operating system keep track of which pages are currently in physical memory? The operating system uses a valid/invalid bit in each page table entry to indicate whether a page is currently in physical memory (valid) or not (invalid). During a page fault, the operating system sets the valid bit accordingly. 8) What is the significance of the page frame number in a page table entry? The page frame number in a page table entry indicates the location in physical memory where the corresponding page is stored. It is used to translate virtual addresses to physical addresses. 9) Explain the term "translation lookaside buffer" (TLB) in the context of paging. The TLB is a small, high-speed cache that stores recently used page table entries. It helps improve the speed of address translation by providing a quick lookup for virtual-to-physical address mapping without always accessing the main page table. 10) How does a two-level page table differ from a single-level page table? A two-level page table is hierarchical, with a top-level page table that points to multiple smaller second- level page tables. This hierarchical structure helps manage large address spaces more efficiently than a single-level page table.
  • 87. EX. 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.
  • 88. 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.tsizettprocess no.ttsize"); for(i = 0; i < bno; i++)
  • 89. { printf("n%dtt%dtt", i+1, bsize[i]); if(flags[i] == 1) printf("%dttt%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.
  • 90. EX. 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.
  • 91. 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) {
  • 92. if(top < temp) { file_arr[m] = n; top = temp; } } } fragments[m] = top; block_arr[file_arr[m]] = 1; top = 0; } } printf("nFile NumbertFile SizetBlock NumbertBlock SizetFragment"); for(m = 0; m < number_of_files; m++) { printf("n%dtt%dtt%dtt%dtt%d", m, files[m], file_arr[m], blocks[file_arr[m]], fragments[m]); } printf("n"); return 0; }
  • 93. OUTPUT: RESULT: Thus a C program to implement the memory management scheme using worst fit algorithm was executed and output is verified successfully. .
  • 94. EX. 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("nt 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");
  • 95. 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%dtt%dtt%dtt%dtt%d",i,f[i],ff[i],b[ff[i]],frag[i]); getch();
  • 96. 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.
  • 97. VIVA-VOCE QUESTIONS 1) What is the First-Fit memory allocation algorithm? In the First-Fit algorithm, the first available block of memory that is large enough to accommodate the process is allocated. It starts searching for free memory from the beginning of the memory space. 2) Explain the advantage of the First-Fit algorithm. The advantage of the First-Fit algorithm is simplicity and efficiency. It quickly allocates the first block that fits the process's size. 3) What is the disadvantage of the First-Fit algorithm? The primary disadvantage is that it may lead to internal fragmentation, as the allocated block might be larger than the actual size of the process. 4) How does the Best-Fit memory allocation algorithm work? In the Best-Fit algorithm, the smallest available block that can accommodate the process is allocated. It involves searching the entire memory space to find the block with the minimum size. 5) What is the advantage of the Best-Fit algorithm? The advantage of the Best-Fit algorithm is that it aims to minimize internal fragmentation by selecting the smallest available block that fits the process. 6) What is the disadvantage of the Best-Fit algorithm? The primary disadvantage is that it may lead to more external fragmentation, as small blocks are allocated, leaving scattered free memory. 7) How does the Worst-Fit memory allocation algorithm function? In the Worst-Fit algorithm, the largest available block of memory is allocated to the process. It involves searching for the maximum-sized block in the entire memory space. 8) What is the advantage of the Worst-Fit algorithm? The advantage of the Worst-Fit algorithm is that it can lead to fewer allocations, reducing the likelihood of fragmentation. 9) What is the disadvantage of the Worst-Fit algorithm? The primary disadvantage is that it may result in significant internal fragmentation, as large blocks are allocated even if the process is smaller. 10) How do these algorithms handle cases where there is no suitable block for allocation? In such cases, the process is typically placed in a waiting queue until a suitable block becomes available, or it may lead to memory compaction or swapping to create larger contiguous blocks.
  • 98. EX. 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
  • 99. 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 stringt page frmaesn"); for(i=1;i<=n;i++) { printf("%dtt",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("%dt",frame[k]); } printf("n"); }
  • 100. printf("page fault is %d",count); getch(); return 0; } OUTPUT: RESULT: The program for FIFO page replacement was implemented and hence verified
  • 101. EX. 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
  • 102. 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("nntEnter the number of page frames : "); scanf("%d",&n); printf("nntEnter 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 {
  • 103. for(j=0;j<n;j++) 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("nnAfter inserting %d the stack status is : ",ref[i]); for(j=0;j<top;j++) printf("%d ",stack[j]); } printf("nntEnd to inserting the reference string."); printf("nntTotal page fault is %d.",fault); printf("nntPress any key to continue."); } void main() { int x; //freopen("in.cpp","r",stdin); while(1) { printf("nnt-----MENU ---- ");
  • 104. printf("nt1. Input "); printf("nt2. LRU (Least Recently Used) Algorithm"); printf("nt0. Exit."); printf("nntEnter your choice."); scanf("%d",&x); switch(x) { case 1: input(); break; case 2: LRU(); break; case 0: exit(0); } } } OUTPUT:
  • 105. RESULT: The program for LRU page replacement was implanted and hence verified.
  • 106. EX. NO: 12C. IMPLEMENT PAGE REPLACEMENT ALGORITHM USING LEAST FREQUENTLY USED ALGORITHM DATE: 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
  • 107. 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 Stringn"); 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;
  • 108. flag = 1; 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]; }
  • 109. for(n = 0; n < total_frames; n++) { printf("%dt", frame[n]); } printf("n"); } printf("Page Hit:t%dn", hit); return 0; } OUTPUT: RESULT: Thus the experiment was successfully compiled and executed