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

564 views 149 slides May 16, 2024
Slide 1
Slide 1 of 149
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103
Slide 104
104
Slide 105
105
Slide 106
106
Slide 107
107
Slide 108
108
Slide 109
109
Slide 110
110
Slide 111
111
Slide 112
112
Slide 113
113
Slide 114
114
Slide 115
115
Slide 116
116
Slide 117
117
Slide 118
118
Slide 119
119
Slide 120
120
Slide 121
121
Slide 122
122
Slide 123
123
Slide 124
124
Slide 125
125
Slide 126
126
Slide 127
127
Slide 128
128
Slide 129
129
Slide 130
130
Slide 131
131
Slide 132
132
Slide 133
133
Slide 134
134
Slide 135
135
Slide 136
136
Slide 137
137
Slide 138
138
Slide 139
139
Slide 140
140
Slide 141
141
Slide 142
142
Slide 143
143
Slide 144
144
Slide 145
145
Slide 146
146
Slide 147
147
Slide 148
148
Slide 149
149

About This Presentation

csbs manual


Slide Content

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:%d\n”,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 fork\n");
pid=fork();
if(pid==0)
{
printf("Child states\n");
for(i=0;i<10;i++)
printf("%d \t",i);
printf("Child ends\n");
}
else

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


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 = % d\n", 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("\n\t\t Gantt chart \n");
printf("ProcessName StartTime BurstTime \n");
for(i=0;i<num;i++){
bt=start+burst[i];
printf("%c\t\t%f\t%f\n",procno[i],start,bt);
wait=wait+start;
start=start+burst[i]; }
avgwait=wait/num;
printf("Average waiting time of a process= %f\n",avgwait);
printf("Total running time of process= %f\n",start);
return 0;}

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("\n\t\t Gantt chart \n");
printf("ProcessName StartTime BurstTime \n");
for(i=1;i<=num;i++)
{
bt=start+burst[i];
printf("%c\t\t%f\t%f\n",procno[i],start,bt);
wait=wait+start;
start=start+burst[i];
}
avgwait=wait/num;
printf("Average waiting time of a process= %f\n",avgwait);
printf("Total running time of process= %f\n",start);
return 0;
}
void swap(int j)
{
char temp;
float tbt;
temp=procno[j];
tbt=burst[j];
procno[j]=procno[j+1];
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("\n\t\t Gantt chart \n\n");
printf("ProcessName\tPriority\tStart\tBurst \n");
for(i=1;i<=num;i++)
{
bt=start+burst[i];
printf("%c\t\t\t%d\t\t%f\t%f\n",procno[i],priority[i],start,bt);
wait=wait+start;
start=start+burst[i];
}
avgwait=wait/num;
printf("Average waiting time of a process= %f\n",avgwait);
printf("Total running time of process= %f\n",start);
return 0;
}
void swap(int j)
{
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%d\t\t%d\t\t%d\t\t%d ",i+1,bt[i],wt[i],tat[i]);
printf("\n Average wait time is %f\t\n Average turnaround time is %f\t\n",awt,atat); }


OUTPUT:


































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 pipe\n");
return 1;
}
printf("Writing to pipe - Message 1 is %s\n", writemessages[0]);
write(pipefds[1], writemessages[0], sizeof(writemessages[0]));
read(pipefds[0], readmessage, sizeof(readmessage));
printf("Reading from pipe – Message 1 is %s\n", readmessage);
printf("Writing to pipe - Message 2 is %s\n", writemessages[0]);
write(pipefds[1], writemessages[1], sizeof(writemessages[0]));
read(pipefds[0], readmessage, sizeof(readmessage));
printf("Reading from pipe – Message 2 is %s\n", readmessage);
return 0;
}

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.PRODUCER\n2.CONSUMER\n3.EXIT\n");
while(1)

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

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("\n\nEnter the no of resources : ");
scanf("%d", &r);
printf("\n\nEnter the Max Matrix for each process : ");
for(i = 0; i < p; i++)
{
printf("\nFor process %d : ", i + 1);
for(j = 0; j < r; j++)
scanf("%d", &Max[i][j]);
}
printf("\n\nEnter the allocation for each process : ");
for(i = 0; i < p; i++)
{
printf("\nFor process %d : ",i + 1);
for(j = 0; j < r; j++)
scanf("%d", &alloc[i][j]);
}
printf("\n\nEnter the Available Resources : ");
for(i = 0; i < r; i++)
scanf("%d", &avail[i]);

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

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) matrix\n");
for(i=1;i<=tp;i++)
{
printf("process %d:\n",i);
for(j=1;j<=tr;j++)
scanf("%d",&c[i][j]);
}
printf("Enter allocation matrix\n");
for(i=1;i<=tp;i++)
{
printf("process %d:\n",i);

for(j=1;j<=tr;j++)
scanf("%d",&p[i][j]);
}
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("%d\t",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 started\n", counter);
for(i=0; i<(0xFFFFFFFF);i++);
printf("\n Job %d finished\n", counter);
return NULL;
}
int main(void){
int i = 0;
int err;
while(i < 2){
err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL);
if (err != 0)
printf("\ncan't create thread :[%s]", strerror(err));
i++;}
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
return 0;}

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.\tsize\t\tprocess no.\t\tsize");
for(i = 0; i < bno; i++)

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


OUTPUT:


































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

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 Number\tFile Size\tBlock Number\tBlock Size\tFragment");
for(m = 0; m < number_of_files; m++)
{
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d", m, files[m], file_arr[m], blocks[file_arr[m]], fragments[m]);
}
printf("\n");
return 0;
}

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("\n\t Best Fit algorithm");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");

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


for(i=1;i<=nf && ff[i]!=0;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
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 string\t page frmaes\n");
for(i=1;i<=n;i++)
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if(avail==0)
{ frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");
}

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("\n\n\tEnter the number of page frames : ");
scanf("%d",&n);
printf("\n\n\tEnter the reference string (-1 for end) : ");
scanf("%d",&temp);
while(temp != -1)
{
ref[count++]=temp;
scanf("%d",&temp);
}
}
void LRU()
{
int i,j,k,stack[min],top=0,fault=0;
system("CLS");
for(i=0;i<count;i++)
{
if(top<n)
stack[top++]=ref[i],fault++;
else
{

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

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


OUTPUT:

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 String\n");
for(m = 0; m < total_pages; m++)
{
printf("Enter Value No.[%d]:\t", m + 1);
scanf("%d", &pages[m]);
}
printf("\n");
for(m = 0; m < total_pages; m++)
{
arr[pages[m]]++;
time[pages[m]] = m;

flag = 1;
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("%d\t", frame[n]);
}
printf("\n");
}
printf("Page Hit:\t%d\n", hit);
return 0; }



OUTPUT:






























RESULT:
Thus the experiment was successfully compiled and executed

VIVA-VOCE QUESTIONS
1) What is the purpose of page replacement algorithms?
Page replacement algorithms are used in operating systems to decide which page to replace when a
new page must be brought into memory, and there is no free space.
2) 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. It triggers the operating system to bring the required page into memory from secondary storage.
3) What is the Belady's Anomaly?
Belady's Anomaly is a phenomenon in page replacement algorithms where increasing the number
of frames can lead to an increase in page faults rather than a decrease.
4) What is the FIFO page replacement algorithm?
FIFO (First-In-First-Out) replaces the oldest page in memory, based on the assumption that the
page that has been in memory the longest is the least likely to be used soon.
5) Explain how FIFO is implemented.
In FIFO, a queue is maintained to keep track of the order in which pages were brought into
memory. The page at the front of the queue (oldest) is the one that gets replaced.
6) What is the main disadvantage of the FIFO algorithm?
The main disadvantage is its susceptibility to Belady's Anomaly, where increasing the number of
frames may not necessarily decrease the page fault rate.
7) How does the Optimal page replacement algorithm work?
The Optimal algorithm replaces the page that will not be used for the longest period of time in the
future. It requires knowledge of future page accesses, which is not practical in real systems but serves as a
benchmark for other algorithms.
8) What is the main advantage of the Optimal algorithm?
The main advantage is that it provides the lowest possible page fault rate, as it makes the optimal
decision based on future page accesses.
9) What is the main disadvantage of the Optimal algorithm?
The main disadvantage is its impracticality in real systems because it requires knowledge of future
page accesses, which is usually not available.
10) How does the LRU (Least Recently Used) page replacement algorithm work?
LRU replaces the page that has not been used for the longest period of time. It is based on the
principle that pages used least recently are more likely to be unused in the near future.

EX. NO: 13A. IMPLEMENTATION OF FILE ORGANIZATION TECHNIQUES USING
SINGLE LEVEL DIRECTORY
DATE:


AIM :
To write a C program to implement File Organization concept using the technique Single level
directory.

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

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

for(j=0;j<=i;j++,cir_x+=mid)
{
line(320,150,cir_x,250);
fillellipse(cir_x,250,30,30);
outtextxy(cir_x,250,fname[j]);
} getch();
} }

OUTPUT




































RESULT
Thus files were organized into a single level directory.

EX. NO: 13B. IMPLEMENTATION OF FILE ORGANIZATION TECHNIQUES
USING TWO LEVEL DIRECTORY
DATE:

AIM:
To write a C program to implement File Organization concept using the technique two level
directory

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

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

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

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

OUTPUT:













































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

EX. NO: 13C. IMPLEMENTATION OF FILE ORGANIZATION TECHNIQUES USING
HIERARCHICAL LEVEL DIRECTORY
DATE:

AIM
To write a C program to implement File Organization concept using the technique
hierarchical level directory.

ALGORITHM:


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

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

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

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


OUTPUT:

































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

EX. NO: 13D. IMPLEMETATION OF FILE ORGANIZATION TECHNIQUES
USING DAG
DATE:


AIM
To write a C program to implement File Organization concept using the technique DAG.


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

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

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

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

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

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

OUTPUT:






















































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

VIVA-VOCE QUESTIONS
1) What is a directory in an operating system?
A directory is a file system component that organizes and stores information about files and other
directories. It serves as a hierarchical structure to navigate and manage files.
2) How does a directory differ from a file?
A file contains data or information, while a directory is a special type of file that contains entries for
other files and directories.
3) What is the purpose of directories in an operating system?
Directories provide a systematic way to organize and manage files, making it easier for users to
locate, access, and organize their data.
4) What are the two main types of directories?
The two main types of directories are:
Single-Level Directory: A flat directory structure where all files are contained in a single directory.
Hierarchical Directory: A tree-like directory structure with multiple levels, allowing for the organization of
files into nested subdirectories.
5) Explain the Single-Level Directory structure.
In a Single-Level Directory, all files are stored in a single directory. Each file has a unique name,
and there is no hierarchy or nesting of directories.
6) What are the limitations of a Single-Level Directory structure?
Limitations include difficulty organizing a large number of files, potential for name conflicts, and a
lack of organization or categorization.
7) Describe the Hierarchical Directory structure.
In a Hierarchical Directory structure, directories are organized in a tree-like hierarchy. Each
directory can contain files and subdirectories, allowing for a more organized and structured approach to file
management.
8) What is the root directory in a Hierarchical Directory structure?
The root directory is the topmost directory in a hierarchical structure. It serves as the starting point
for the entire directory tree.
9) How are directories represented in a file system?
Directories are represented as special files that contain information about files and subdirectories.
Each entry in a directory points to an inode or file control block (FCB) associated with a file.
10) What is a Path in the context of directories?
A path is a unique identifier for the location of a file or directory in the directory tree. It specifies
the sequence of directories leading to the file, starting from the root directory.

EX. NO: 14A. IMPLEMENTATION OF SEQUENTIAL FILE ALLOCATION
STRATEGIES
DATE:

AIM
To write a C program to implement File Allocation Strategies.

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

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

OUTPUT:










































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

EX. NO: 14B. IMPLEMENTATION OF INDEXED FILE ALLOCATION
STRATEGIES
DATE:

AIM
To write a C program to implement File Allocation Strategies.

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

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

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




















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

EX. NO: 14C. IMPLEMENTATION OF LINKED FILE ALLOCATION
STRATEGIES
DATE:

AIM
To write a C program to implement Linked File Allocation Strategies.

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

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

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

































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

VIVA-VOCE QUESTIONS
1) What is file allocation in the context of operating systems?
File allocation refers to the process of assigning space to files on a storage device, such as a hard
disk. It involves determining how and where files will be stored.
2) What are the primary goals of file allocation strategies?
The primary goals include efficient space utilization, minimizing fragmentation, and providing fast
and convenient access to files.
3) Name the three main file allocation strategies.
The three main file allocation strategies are:
Contiguous Allocation
Linked Allocation
Indexed Allocation
4) Explain Contiguous Allocation.
In contiguous allocation, each file occupies a contiguous block of storage space on the disk. The
starting and ending locations of the file are recorded for easy access.
5) What is the advantage of Contiguous Allocation?
Contiguous allocation provides fast and efficient sequential access to files, as the entire file is stored
in a continuous block.
6) What is the disadvantage of Contiguous Allocation?
The main disadvantage is the potential for external fragmentation, where free space is scattered
throughout the disk, making it challenging to allocate contiguous space for large files.
7) Explain Linked Allocation.
In linked allocation, each file is a linked list of disk blocks. Each block contains a pointer to the
next block in the file. The last block typically has a null pointer.
8) What is the advantage of Linked Allocation?
Linked allocation avoids external fragmentation as files can be scattered across the disk. It is also
flexible in terms of file size changes.
9) What is the disadvantage of Linked Allocation?
The main disadvantage is that accessing a specific part of the file may require traversing the entire
linked list, resulting in slower access times.
10) Explain Indexed Allocation.
In indexed allocation, each file has an index block that contains pointers to all the blocks of the file.
The index block serves as a table of contents for the file.

EX. NO: 15A. IMPLEMENTATION OF FCFS DISK SCHEDULING ALGORITHM
DATE:
AIM
To write a C program to implement FCFS Disk Scheduling Algorithm.

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

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

OUTPUT











































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

EX. NO: 15B. IMPLEMENTATION OF SSTF DISK SCHEDULING ALGORITHM
DATE:
AIM
To write a C program to implement SSTF Disk Scheduling Algorithm.

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

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

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

OUTPUT




































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

VIVA-VOCE QUESTIONS
1) What is disk scheduling?
Disk scheduling is the process of selecting and ordering disk I/O requests to optimize the movement
of the disk arm and reduce the seek time, thus improving overall disk performance.
2) Why is disk scheduling necessary?
Disk scheduling is necessary to minimize the time it takes to access data on a disk. Efficient
scheduling helps reduce seek times and rotational latency, improving the overall performance of disk I/O
operations.
3) What is seek time?
Seek time is the time it takes for the disk arm to position itself over the desired track. It is a crucial
component of the total disk access time.
4) What is rotational latency?
Rotational latency is the time it takes for the desired disk sector to rotate under the disk head after
the disk arm has positioned itself over the correct track. It is another component of the total disk access
time.
5) Name some common disk scheduling algorithms.
Some common disk scheduling algorithms include:
FCFS (First-Come-First-Serve)
SSTF (Shortest Seek Time First)
SCAN
C-SCAN
LOOK
C-LOOK
6) Explain the FCFS disk scheduling algorithm.
FCFS schedules disk I/O requests in the order they arrive. The requests are processed in a first-
come-first-serve manner, without considering the distance between the tracks.
7) What is the main disadvantage of the FCFS algorithm?
The main disadvantage is that it may result in a phenomenon known as the "convoy effect," where a
long-request can delay other requests behind it.
8) Explain the SSTF disk scheduling algorithm.
SSTF selects the disk I/O request with the shortest seek time, prioritizing requests that require the
least movement of the disk arm.
9) What is the advantage of the SSTF algorithm?
The advantage of SSTF is its ability to minimize seek times, leading to reduced disk access times.
10) What is the main drawback of the SSTF algorithm?
The main drawback is that it can lead to starvation, where some requests may never be serviced if
there are always requests with shorter seek times.

EX. NO: 16. UNIX EDITORS
DATE:


AIM: To study of various UNIX editors such as vi, ed, ex and EMACS.

CONCEPT: Editor is a program that allows user to see a portions a file on the screen and modify
characters and lines by simply typing at the current position. UNIX supports variety of Editors. They
are: ed ex vi EMACS Vi- vi is stands for “visual”.vi is the most important and powerful editor.vi is a
full screen editor that allows user to view and edit entire document at the same time.vi editor was
written in the University of California, at Berkley by Bill Joy, who is one of the co-founder of Sun
Microsystems.


Features of vi: It is easy to learn and has more powerful features.
Itworksgreatspeedandiscasesensitive.vihaspowerfulundofunctionsandhas3modes:
1. Command mode
2. Insert mode
3. Escape or ex mode

In command mode, no text is displayed on the screen. In Insert mode, it permits user to edit insert or
replace text. In escape mode, it displays commands at command line. Moving the cursor with the
help of h, l, k, j, I, etc

EMACS Editor

Motion Commands:

M-> Move to end of file
M-< Move to beginning of file
C-v Move forward a screen
M –v Move backward a screen
C –n Move to next line
C-p Move to previous line
C-a Move to the beginning of the line
C-e Move to the end of the line
C-f Move forward a character
C-b Move backward a character
M-f Move forward a word
M-b Move backward a word

Deletion Commands:

DEL delete the previous character
C -d delete the current character
M -DEL delete the previous word
M-d delete the next word

C-x DEL deletes the previous sentence
M-k delete the rest of the current sentence
C-k deletes the rest of the current line
C-xu undo the lasted it change
Search and Replace in EMACS:
y Change the occurrence of the pattern
n Don‟t change the occurrence, but look for the other
q Don‟t change. Leave query replace completely ! Change this occurrence and all others
in the file
















RESULT:
Thus the UNIX editor commands have been executed successfully

EX. NO: 17 IMPLEMENTATION OF SHARED MEMORY USING IPC
DATE:

AIM:

To implement the inter-process communication using shared memory.

ALGORITHM:

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

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

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

OUTPUT:



































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