Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1 views113 pages

OS RECORD (1)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 113

ANNA UNIVERSITY

JAYA ENGINEERING COLLEGE


THIRUNINRAVUR-602 024
(An ISO 9001:2000 Certified Institution)
Email : info@jec.ac.in

Website: www.jec.ac.in

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
PRACTICAL RECORD
CS3461 OPERATING SYSTEMS LABORATORY

1
ANNA UNIVERSITY
JAYA ENGINEERING COLLEGE
THIRUNINRAVUR-602 024
(An ISO 9001:2000 Certified Institution)
Email:info@jec.ac.in
Website:
www.jec.ac.in

BONAFIDE CERTIFICATE

This is to certify that this is a bonafide record of work done by

Mr./Ms. Reg.No. of

B.E / COMPUTER SCIENCE AND ENGINEERING in CS3461 OPERATING

SYSTEM LABORATORY in the IV semester during MAY 2024 to JUNE 2024.

Head of the Department Staff-In-Charge

Submitted For Practical Examination Held On

Internal Examiner External Examiner

2
INDEX
LIST OF EXPERIMENTS:

EX. DATE NAME OF THE EXPERIMENT PAGE Cos POs &PSOs MARK SIGN
no NO Mapped Mapped
1. Illustration of windows OS
2. Basics of UNIX Commands
3.1 Implements System calls
fork(),exec(),getpid(),getppid(),wait()
3.2 Implement system calls opendir(),readir()
4.1 CPU Scheduling Algorithm(Round Robin
Algorithm)
4.2 SJF Algorithm
4.3 FCFS Algorithm
4.4 Priority Scheduling Algorithm
5. Implementation of Shared Memory and
IPC
6.1 To perform matrix addition in child
process using shared memory
6.2 To generate ODD number using Shared
memory.
6.3 Implementation of semaphores
7. Implementation of Bankers Algorithm for
Deadlock avoidance
8. Implementation of Deadlock Detection
Algorithm
9. Write C program to Implement Threading
&Synchronization application

10.1 Implementation of Memory


Management-Paging
10.2 Memory Allocation Methods for Fixed
Partition First Fit Allocation
10.3 Worst First Allocation
10.4 Best fit Allocation
11.1 First In First Out
11.2 Least Recently Used(LRU)
11.3 Optimal Page Replacement Algorithm
12.1 File Organization Techniques
Implementation of Single level Directory
12.2 Implementation of Two level Directory
13.1 File Allocation Strategies
Sequential file Allocation
13.2 Indexed File Allocation
13.3 Linked File Allocation
14 Disk Scheduling Algorithm
15. Linux Installation Using VMWARE

3
INDEX

S NO PARTICULARS PAGE NO

1 Vision and Mission of Institute


2 Vision and Mission of Department
3 Program Educational Outcomes
4 Program Specific Outcomes
5 Program Out comes
6 Course Out Comes
7 Syllabus

4
1. VISION AND MISSION OF THE INSTITUTE
Vision of the Institute
To achieve excellence in technical education through innovative teaching and
multidisciplinary research with professionalism to serve the global society.

Mission of the Institute


Jaya Engineering College (JEC) will Endeavor

M1 -To provide state of art teaching and learning for Engineering and Technology,
Research and Management studies.

M2 -To provide quality education, self discipline and ethical values.

M3 - To associate with R&D and industries to have connectivity with the society.

M4 – To impart knowledge to become empowered professionals in the field of Engineering and


Management

2. VISION AND MISSION OF THE DEPARTMENT


Vision of the department
To achieve Excellence in Computer Science and Engineering by providing quality technical
education to cater the need of industry and society through research and development.

Mission of the department


The Computer Science and Engineering Department is committed to:
M1: Provide strong fundamentals and technical skills in Computer Science Engineering
through Effective teaching and learning methods.
M2: Impart high quality experiential learning to get expertise in modern software tools and
to Procure the real time requirements of the industry.
M3: Inculcate problem solving and team building skills and promote lifelong learning with a sense of
societal and ethical responsibilities.

5
3. PROGRAM EDUCATIONAL OBJECTIVES
Graduates can
PEO1: Apply their technical competence in computer science to solve real world problems, with
technical and people leadership.
PEO2: Conduct cutting edge research and develop solutions on problems of social relevance.
PEO3: Work in a business environment, exhibiting team skills, work ethics, adaptability and
lifelong learning.

4. PROGRAM OUTCOMES

Engineering Graduates will be able to:


PO1 - Engineering Knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialisation 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.

6
PO7 - Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.

PO8 - Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.

PO9 - Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.

PO10 - Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.

PO11 - Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member
and leader in a team, to manage projects and in multidisciplinary environments.

PO12 - Life-long learning: Recognize the need for, and have the preparation and ability to engage

in independent and life-long learning in the broadest context of technological change.

7
5. PROGRAMME OUTCOMES
Engineering Graduates will be able to:
PSO1: Exhibit design and programming skills to build and automate
business solutions using cutting edge technologies
PSO2: Strong theoretical foundation leading to excellence and excitement towards
research, to provide elegant solutions to complex problems.
PSO3: Ability to work effectively with various engineering fields as a team to design, build
and develop system applications.

6. COURSE OUTCOME

On completion of this course, the students will be able to


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

CS3461 OPERATING SYSTEMS LABORATORY LT

P C 0 0 3 1.5 COURSE OBJECTIVES:

● To install windows operating systems.


● To understand the basics of Unix command and shell programming.
● To implement various CPU scheduling algorithms.
● To implement Deadlock Avoidance and Deadlock Detection Algorithms
● To implement Page Replacement Algorithms
● To implement various memory allocation methods.
● To be familiar with File Organization and File Allocation Strategies
LIST OF EXPERIMENTS:

1) Installation of windows operating system


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

8
9
Ex.No : 1 INSTALLATION OF WINDOWS OPERATING
SYSTEM
DATE:

AIM:
To know how to install the windows operating system

INTRODUCTION:
Each version of Microsoft Windows is installed on a computer using similar steps.
While there are steps in the installation process that differ between versions of Windows, the
following general steps and guidelines help you install Windows on your computer. The
steps below are for all recent versions of Windows, including Windows 98, Windows ME,
Windows 2000, Windows XP, Windows Vista, Windows 7, Windows 8, Windows 10, and
Windows 11. These steps even work for earlier versions (e.g., Windows 95) as long as you
use the disc version. The floppy diskette version is similar, but it requires additional steps.

CHECK HARDWARE COMPATIBILITY


Before installing or upgrading Windows on your computer, check the hardware in
the computer to make sure it's compatible with that version of Windows. Microsoft provides
a Windows Compatible Products List for checking if the hardware in your computer is
compatible with the chosen version of Windows.
If one or more pieces of hardware is not compatible with the chosen Windows
version, we recommend replacing that hardware with compatible hardware or purchasing a
new computer. Having compatible hardware in your computer helps ensure the Windows
install or upgrade process is successful.

GENUINE WINDOWS CD, DVD, OR USB THUMB DRIVE


First, you need a genuine copy of the Microsoft Windows
operating system installation CD, DVD, or USB thumb drive. A genuine Windows product
key is included with the installation disc, which is required to activate Windows after
installation. If you have an OEM (original equipment manufacturer) computer, the Windows
product key is often on the back or side of the computer.
If you have an OEM computer (e.g., Acer, Dell, HP, etc.), the computer will not
have a genuine Windows CD, DVD, or USB thumb drive. Instead, you would reinstall
Windows and the software using a hidden partition or a set of restore discs. The steps
mentioned on this page would still work, but you'd need a copy of Windows. You can
borrow a friend's Windows disc, as long as it's the same version of Windows that came with
the computer and have a product key.

HOW TO ENTER AND EXIT THE BIOS OR CMOS SETUP


Every computer provides a way to enter the BIOS or CMOS setup, which lets you
configure some basic settings for your computer and its hardware components.
Below is a list of common methods for accessing and exiting your computer's BIOS
or CMOS setup and recommendations if you're having trouble.

ACCESS BIOS OR CMOS ON NEWER COMPUTERS:


Computers manufactured in the last few years allow you to enter the BIOS or CMOS
setup by pressing one of the five keys listed below during the boot process.
● F1
● F2
● F10
● Delete or Del
● Esc

10
● If pressing F2 opens a diagnostics tool, your setup key is likely F10.
● F10 is also used for the boot menu. If pressing F10 opens a boot menu, your
setup key is likely F2.
Setup keys are to be pressed as the computer is booting up. Most users see a
message similar to the example below upon startup. Some older computers may also display
a flashing block of text to indicate when to press F1 or F2.
Press F2 to enter BIOS setup.Once you have successfully entered the CMOS
setup, a screen similar to the example below appears. Your CMOS setup may look different,
depending on the manufacturer, but it should still share a lot of the same options and
information.

HOW DO I CHANGE AND SAVE CHANGES IN CMOS SETUP


Once in CMOS setup, the method for changing the settings often depends on
the BIOS manufacturer. You may use the arrow keys and the Enter key to select categories
and change their values. Some manufacturers may have you press the Page up and Page
down keys to change the values.
If you're trying to change the clock, speed, or other settings and don't have the
option available, the motherboard doesn't support it. If you believe it should be supported,
you may need a BIOS update.

HOW DO I SAVE THE CHANGES:


If any changes are made, you need to save those changes, which is usually
done by pressing the F10 key on the keyboard. If F10 doesn't work, look at the bottom or
top of the screen for the key that's used to save the settings.

ACCESS BIOS OR CMOS ON OLDER COMPUTERS:


Unlike today's computers, older computers (before 1995) had numerous
methods of entering the BIOS setup. Below is a listing of key sequences to press as the
computer boots to enter the BIOS setup.
• Ctrl+Alt+Esc
• Ctrl+Alt+Insert
• Ctrl+Alt+Enter
• Ctrl+Alt+S
• Page Up
• Page Down

Acer BIOS:
If your Acer computer cannot boot or you want to restore the BIOS to its
original settings, press and hold the F10 as you turn on the computer. While holding F10,
two beeps should be heard to indicate the settings are restored.

AMI BIOS:
Older AMI BIOS could be restored to bootable settings by pressing and holding
,Insert as the computer is booting.

BIOS or CMOS diskettes:


Early 486, 386, and 286 computers required a floppy disk to enter the BIOS
setup. These diskettes may be called ICU, BBU, or SCU disks. Because these diskettes are
unique to your computer manufacturer, you must obtain the diskettes from them. See the
computer manufacturers list for contact information.
Access BIOS on early IBM computers:
Some early IBM computers require you to press and hold both mouse buttons
as the computer boots to enter the BIOS setup.
Additional suggestions for accessing BIOS or CMOS:
Finally, if none of the above suggestions allow access to the setup, try generating
a stuck key error, which gives an option to enter the BIOS or CMOS setup. To do this, press
and hold any key on the keyboard, and do not let go (you may get several beeps as you
11
are

12
doing this). Keep pressing the key until the computer stops booting, and you have the option
to enter setup. If this does not work, make sure your keyboard is working.
HOW TO EXIT THE BIOS OR CMOS:
There are several ways to exit the BIOS or CMOS setup depending on the
computer's type. The most common methods include the following.
● Press the Esc key to exit without saving any changes.
● Press the F10 or F12 key to save changes and exit.
● Access the Exit or Save & Exit tab in setup and select the Exit or Save
and Exit option.
If you have trouble exiting the BIOS or CMOS setup, you can try the
following methods to fix the problem.
▪ Press the F9 key to load default settings and press F10 to save and exit.
▪ Access the Exit or Save & Exit tab in setup, select the Load Optimized
Defaults option, select Yes, and press Enter. Any changes made are
reverted, and the BIOS or CMOS is set back to default settings.
▪ Turn off the computer (use only as a last resort and with caution).

INSTALLING OR UPGRADING WINDOWS:


To start the Windows install or upgrade process, you need to configure your
computer to boot from a CD or DVD before booting to the hard drive. Changing the boot
process forces the computer to look for the Windows installation disc before booting from
the hard drive.
1. Open the CMOS setup.
2. Change the computer's boot order. Set the CD, DVD, or disc drive as the
first boot device if you are trying to boot from a disc. Or, set the first boot
device to your USB drive if you're trying to boot from a USB thumb drive.
If the drive is not shown, keep the disc is inserted and reboot the
computer. With the disc in the drive, BIOS should recognize and include it
in the list.
3. Save the settings change and exit BIOS.
Note: Once you have updated the boot order, you can begin the Windows
installation process.
4. Place the Windows disc in the CD/DVD drive or USB thumb drive into
the back of the computer.
5. Turn on or restart the computer. As the computer starts up, it should detect
the installation disc or drive and show a message similar to Press any key
to boot from CD. Press any key on the keyboard to have the computer boot
from the Windows disc or drive.
6. After the Windows install begins, there are several prompts that you need
to answer. Select either Yes or the appropriate option to install Windows.
7. When asked which partition to install Windows onto, select the main
partition, usually the C: drive or one labeled "Unallocated partition". If
upgrading Windows, select the existing installation of Windows on the
hard drive.
8. You may be asked if you want to erase all contents on the hard drive, then
install Windows. We recommend you choose this option, as it also formats
the hard drive to allow the Windows operating system to be installed.
9. The computer may need to restart several times during the Windows
install process. The restarts are normal and if prompted to restart, select
the Yes option.
10. When the install process is nearly complete, the Windows configuration
option screens are shown. On these screens, you may be asked to select the
time zone you live in, your preferred language, and the account's name
you use to access Windows. Select the appropriate options and enter the
appropriate information on each configuration screen.
11. The Windows install process is completed when the computer prompts
you to log in or when it loads into Windows.
13
FINAL WINDOWS AND COMPUTER CONFIGURATION:
After Windows is installed on the computer, you need to install the drivers
and related software for the hardware in the computer. You can use the installation discs that
came with the hardware or download the drivers from the hardware manufacturer's
website.We strongly recommend you install the latest drivers for each piece of hardware.
To determine which hardware needs drivers to be installed, check the
Device Manager and look for the exclamation mark "!" next to hardware devices. The
exclamation point means drivers are needed for that device.After installing the necessary
hardware device drivers, install any software programs on the computer that you want to
use.
Finally, download and install any available Windows updates. Updating
Windows improves the operating system's performance, the hardware in the computer, and
the software programs you use. It can also improve security by fixing potential security
holes and flaws in Windows.

LONG-TERM MAINTENANCE OF WINDOWS:


Microsoft frequently releases new updates for Windows, so we
recommend you check for and install available updates. Doing so helps keep Windows
running better and keep your computer protected.
Also, periodically check for updated hardware device drivers from
manufacturers' websites. Keeping hardware drivers updated helps the hardware devices in
the computer run at peak performance and improves compatibility with other computer
hardware and software.

RESULT:

Thus the study exercise for installing windows operating system is studied successfully

14
Ex.No : 2 UNIX COMMANDS AND SHELL PROGRAMMING
DATE:

Aim:
To study basic UNIX commands.

(1) Command : cat


(a) To Create a New File:
Syntax: cat > filename [cselab@jec]$ cat > one.txt Hi
Welcome to CSE Lab JEC
Chennai
Pressing Ctrl+z to save the file
[2]+ Stopped cat >one.txt
[CSElab@jec]$

(b) To Display the Contents of the File : Syntax


: cat filename [itlab@jec]$ cat one.txt
Hi
Welcome to CSE Lab JEC
Puliyangudi
[itlab@jec]$

(2) Command : mkdir (Make directory)


Syntax : mkdir filename [cselab@jec]$
mkdir programs:
[itlab@jec]$ ls
a./out
college.txt fir.sh
new.txt second.sh
col1.txt coll.txt firs.sh
one pgms college2.txt file.txt
one.txt
programs [cselab@jec]$

(3)Command : cd (change directory)


Syntax : cd directory name
[itlab@jec]$ cd programs
[itlab@jec programs]$ cd ..
[itlab@jec]$ cd programs
[itlab@jec programs]$ mkdir shellprogram
[itlab@jec programs]$ cd
shellprogram [itlab@jec shellprogram]$ cd
[itlab@jec]

(4) Command : pwd (Print Working Directory)


[cselab@jec shellprogram]$
pwd/home/cselab/programs/shellprogram
[cselab@jec shellprogram]$ cd [cselab@jec]$
pwd/home/cselab [cselab@jec]

15
(5)Command : ls (List Files and Directories)
a. ls
[cselab@jec]$ ls
111 2.prn cpgm.c HelloWorld.class mac.c print.c
1. ccc a.out duplicate.c HelloWorld.java Makefile sample.c
1. docx array.c fib.c inc.c OS streverse.c
1. prn CP fun.c JAVA pr.c
vin [cselab@jec]$

b.ls –l : Lists Files and Directories in Long Listing Mode


[cselab@jec]$ ls -l total
112
-rw-rw-r-- 1 cselab cselab 35 Jul 21 16:31 111
-rw-r--r-- 1 cselab cselab 0 Sep 3 13:12 1.ccc
-rw-rw-r-- 1 cselab cselab 6857 Aug 9 16:30 1.docx
-rw-rw-r-- 1 cselab cselab 785 Jul 21 16:32 1.prn
-rw-rw-r-- 1 cselab cselab 166 Jul 21 16:33 2.prn
-rwxrwxr-x 1 cselab cselab 4777 Nov 22 11:00 a.out
-rw-rw-r-- 1 cselab cselab 346 Jul 15 2016 array.c
drwxrwxr-x 2 cselab cselab 4096 Sep 2 13:22 CP
-rw-rw-r-- 1 cselab cselab 81 Aug 3 16:47 cpgm.c
-rw-rw-r-- 1 cselab cselab 842 Aug 6 12:21 duplicate.c
-rw-rw-r-- 1 cselab cselab 265 Oct 31 13:26 fib.c
[cselab@jec]$

c. [cselab@jec]$ ls –a (To show Hidden files)


. 2.prn .bashrc fun.c mac.c sample.c
.. a.out CP .gnome2 Makefile .ssh
111 array.c cpgm.c HelloWorld.class .mozilla streverse.c
1. ccc .bash_history duplicate.c HelloWorld.java OS .vim 1.docx
.bash_logout .emacs inc.c pr.c .viminfo
1. prn .bash_profile fib.c JAVA print.c vin [cselab@jec]$

d.[cselab@jec]$ ls –x
111 1.ccc 1.docx 1.prn 2.prn a.out
array.c CP cpgm.c duplicate.c fib.c
fun.c HelloWorld.class HelloWorld.java inc.c
JAVA mac.c
Makefile OS pr.c print.c sample.c streverse.c vin [cselab@jec]$
(5) Command : mv (Move)
a. mv (Move a File to Directory)
Syntax : mv SourceFile DestinationDirectory
[cselab@jec]$ mv coll.txt programs
[cselab@jec]$ cd programs [cselab@jec
programs]$ ls
coll.txt shellprogram
[cselab@jec programs]$

16
b. mv (Move Contents of one File to
Another File) Syntax : mv SourceFile
DestinationFile [cselab@jec]$ cat one.txt
Hi, Welcome to CSE Lab
SVCET
[cselab@jec]$ mv one.txt new.txt
[cselab@jec]$ cat new.txt
Hi, Welcome to CSE Lab
SVCET
[cselab@jec]$
1) Command : rm (Remove
a File) Syntax : rm filename
[cselab@jec]$ ls
a.out college2.txt file.txt firs.sh one programs
col1.txt college.txt fir.sh new.txt pgms
second.sh [cselab@jec]$ rm new.txt
[cselab@jec]$ ls
a.out college2.txt file.txt firs.sh pgms second.sh
col1.txt college.txt fir.sh one programs
[cselab@jec]$
2) Command : rmdir (Remove a
Diretory) Syntax : rmdir Directoryname
[cselab@jec programs]$ ls
coll.txt shellprogram
[cselab@jec programs]$ rmdir shellprogram
[cselab@jec programs]$ ls
coll.txt
[cselab@jec programs]$
3) Command : rm -rf (Remove a Diretory which is not Empty)
Syntax : rm –rf Directoryname
[cselab@jec programs]$ ls
coll.txt
[cselab@jec]$ rm -rf programs
[cselab@jec]$ ls
a.out college2.txt file.txt firs.sh pgms
col1.txt college.txt fir.sh one second.sh
[cselab@jec]$
4) Command : echo (Prints the Given String)
a) Syntax: echo “String”
[cselab@jec]$ echo
"SVCET" SVCET
[cselab@jec]$
b) Syntax: echo –n “String” (Don’t Print a
New Line) [cselab@jec]$ echo -n "SVCET"
SVCET [cselab@jec]$

5) Command : head (Prints required no. of lines in the File Counting from
the Beginning of the File)
Syntax : head –n filename
n : Number of Lines to be
displayed [cselab@jec]$ cat
one.txt Welcome to SVCET

17
Puliyangudi
CSE Dept

Computer Practices Laboratory


[cselab@jec]$ head -2 one.txt
Welcome to SVCET
Puliyangudi
[cselab@jec]$

6) Command : tail (Prints required no. of lines in the File


Counting from the End of the File)
Syntax : tail –n filename
n : Number of Lines to be
displayed [cselab@jec]$ cat
one.txt Welcome to SVCET
Puliyangudi
CSE Dept
Computer Practices Laboratory
[cselab@jec]$ tail -2 one.txt CSE
Dept
Computer Practices Laboratory
[cselab@jec]$
7) Command : who (Displays the Users Who Logged into the System)
Syntax: who
[cselab@jec]$ who
root tty7 2015-01-06 02:14 (:0)
cselab pts/20 2016-12-01 16:07 (172.16.67.30)
[cselab@jec]$
Command : who am i (Displays the Name of the Current User of this
System)
Syntax: who am i
[cselab@jec]$ who am i
cselab pts/20 2016-12-01 16:07 (172.16.67.30)
[cselab@jec]$
8) Command : date (Displays the Current Date and Time)
Syntax: date
[cselab@jec]$ date
Thu Dec 1 16:07:49 IST 2016
[cselab@jec]$

9) Command : cal (Displays the Calendar)

Syntax: cal
[cselab@jec]$
cal [cselab@jec]
$ cal
December 2016
Su Mo Tu We Th Fr Sa
123
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 29 30 31

18
[cselab@jec]$ cal 5 2009
May 2009
Su Mo Tu We Th Fr Sa
1 2
1) Command : grep (Displays a Line from the file Containing the Given String)
Syntax : grep “String” filename
Syntax : grep –i “String” filename
i – Ignore Case of the Given
String [cselab@jec]$ cat one.txt
Welcome to SVCET
Puliyangudi
CSE Dept
Computer Practices Laboratory
[cselab@jec]$ grep "Ramco" one.txt
Welcome to SVCET
[cselab@jec]$

Result
Thus the study and execution of UNIX commands has been completed successfully.

19
Ex.No : 3.1 Implement System Calls fork(), Exec(), getpid(), getppid(), wait()

DATE:
Aim:
To write the program using System Calls fork(), Exec(), getpid(), getppid(), wait() .
Algorithm:
Step 1 : Declare the variable pid.
Step 2 : Get the pid value using system call fork().
Step 3 : If pid value is less than zero then print as “Fork failed”.
Step 4 : Else if pid value is equal to zero include the new process in the
system‟s file using execlp system call.
Step 5 : Else if pid is greater than zero then it is the parent
process and it waits till the child completes using the system call
wait() Step 6 : Then print “Child complete”.

Program:
#include<stdio.h>
#include<sys/types.h
> #include<string.h>
#include<unistd.h>
#include<sysexits.h>
#include<stdlib.h>
main()
{
int pid;
pid=fork();
if(pid<0)
printf("error");
else if(pid>0)
{
wait(1000);
printf("\n Parent Process:\n");
printf("\n\tParent Process id:%d\t\n",getppid());
execlp("/bin/ls","ls",NULL);
}
else
{
printf("\nChild process:%d\n",getpid()); printf("\n\
tChildprocess parent id:\t %d\n",getppid());
execlp("cal","cal",NULL);
exit(0);
}
}

20
Output:
[cse6@localhost Pgm]$ cc prog4a.c
[cse6@localhost Pgm]$ ./a.out

Result
Thus the program using System Calls fork(), Exec(), getpid(), getppid(), wait() has
been completed successfully.

21
Ex.No : 3.2
Implement System calls opendir(),readdir()
DATE:
Aim:
To write the program using System Calls opendir(),readdir().
Algorithm:
Step 1 : Start.
Step 2 : In the main function pass the arguments.
Step 3 : Create structure as stat buff and the variables as integer.
Step 4 : Using the for loop,initialization.

Program:
#include<sys/types.h>
#include<dirent.h>
#include<stdio.h>
main(int c,char* arg[])
{
DIR *d;
struct dirent *r;
int i=0;
d=opendir(arg[1]);
printf("\n\t NAME OF ITEM
\n"); while((r=readdir(d)) !=
NULL)
{
printf("\t %s \n",r->d_name); i=i+1;
}
printf("\n TOTAL NUMBER OF ITEM IN THAT DIRECTORY IS %d \n",i);
}

Result:
Thus the program using System Calls opendir(),readdir() has been completed
Successfully.
22
EX.NO:4.1 CPU SCHEDULING ALGORITHM
( Round Robin Algorithm )
DATE :

AIM:
To write a C program to implement round robin scheduling algorithm.

ALGORITHM:
1. Read no. of processes and time quantum( TQ).
2. Read process name and burst time(BT) for each process.
3. Ready queue is treated as circular queue.CPU schedules all processes (according
to their of order of arrival) only up to given time quantum.
4. A timer is set to interrupt the scheduling if time quantum expires for a process.
5. If BT of process is greater than TQ then after executing upto TQ, it gets added to tail
of ready queue.
6. If BT of process is less than TQ then CPU gets released from it and schedules
next process in ready queue.
7. Set waiting time (WT) of first process as zero and turnaround time(TAT) as burst time.
8. Calculate waiting time and turnaround time of other processes
as follows: Pi (WT) = P i-1(WT) +P i-1(BT)
P i (TAT) = P i (BT) + P i (WT)
9. Calculate and display average WT and TAT.
10. Display order of execution of processes ie. Process name, burst time, WT and TAT.

PROGRAM:
#include<stdio.h>
int main()
{
int i, limit, total = 0, x, counter = 0, time_quantum;
float average_wait_time, average_turnaround_time;
printf("\nEnter Total Number of Processes:\t");
scanf("%d", &limit);
x = limit;
for(i = 0; i < limit; i++)
{
printf("\nEnter Details of Process[%d]\n", i + 1);
printf("Arrival Time:\t");
scanf("%d",
&arrival_time[i]);
printf("Burst Time:\t");
scanf("%d", &burst_time[i]);
printf("\nEnter Time Quantum:\t");
scanf("%d", &time_quantum);
printf("\nProcess ID\t\tBurst Time\t Turnaround Time\t Waiting Time\n");
for(total = 0, i = 0; x != 0;)
{
if(temp[i] <= time_quantum && temp[i] > 0)
{
23
total = total + temp[i];
temp[i] = 0;
counter = 1;
}
else if(temp[i] > 0)
{
temp[i] = temp[i] - time_quantum;
total = total + time_quantum;
}
if(temp[i] == 0 && counter == 1)
{
x--;
printf("\nProcess[%d]\t\t%d\t\t %d\t\t\t %d", i + 1,
burst_time[i], total - arrival_time[i],
total - arrival_time[i] - burst_time[i]);
turnaround_time = turnaround_time + total - arrival_time[i];
counter = 0;
}
if(i == limit - 1)
{
i = 0;
}
else if(arrival_time[i + 1] <= total)
{
i++;
}
else
{
i = 0;
}
}
average_wait_time = wait_time * 1.0 / limit;
average_turnaround_time = turnaround_time * 1.0 / limit; printf("\
n\nAverage Waiting Time:\t%f", average_wait_time); printf("\
nAvg Turnaround Time:\t%f\n", average_turnaround_time); return
0;
}

24
Output
[cselab@jec ~]$ cc round.c
[cselab@jec ~]$ ./a.out
Enter Total Number of Processes: 3
Enter Details of
Process[1] Arrival Time:
1
Burst Time: 24
Enter Details of
Process[2] Arrival Time:
2
Burst Time: 3
Enter Details of
Process[3] Arrival Time:
3
Burst Time: 3
Enter Time Quantum: 3
Process ID Burst Time Turnaround Time Waiting Time
Process[2] 3 4 1
Process[3] 3 6 3
Process[1] 24 29 5

Average Waiting Time: 3.000000


Avg Turnaround Time: 13.000000
[cselab@jec ~]$

RESULT:
Thus the Round Robin CPU scheduling algorithms was executed successfully.

25
EX.NO: 4 .2
Shortest Job First Algorithm
DATE :

AIM:
To write a C program to implement SJF (Shortest Job First) scheduling algorithm.

ALGORITHM:
Step1:Read no. of processes.
Step2:Read process name and burst time for each process.
Step3:Sort the processes in ready queue according to burst time.CPU schedules
process with shortest burst time first followed by other processes.
Step4:Set waiting time(WT) of first process as zero and turnaround time(TAT) as
burst time.
Step5:Calculate waiting time and turnaround time of other processes as
follows: Pi (WT) = P i-1(WT) +P i-1(BT)
P i (TAT) = P i ( BT) + P i (WT)
Step6:Calculate and display average WT and TAT.
Step7:Display order of execution of processes ie. Process name, burst time, WT and
TAT.

PROGRAM:
#include<stdio.h>
#include<string.h>
struct jo
{
Charjn[20];
int bt;
int wt,tat;
}
j[20];
main()
{
int i,tmp,n; char
t[20];
float avgwt,avgtat;
printf("\n\t SJF SCHEDULING ALGORITHM \n\n");
printf("Enter no. of jobs\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\nEnter job name of job %d : ",i);

26
scanf("%s",j[i].jn);
printf("\nEnter burst time of job %d : ",i);
scanf("%d",&j[i].bt);
}
for(j=i+1;j<=n;j++)
{
if( j[i].bt > j[j].bt)
{
strcpy( t, j[i].jn);
strcpy(j[i].jn,
j[j].jn);
strcpy(j[j].jn, t);
tmp= j[i].bt;
j[i].bt=j[j].bt;
j[j].bt=tmp;
}
}
}
j[1].wt=0;
j[1].tat=j[1].bt;
for(i=2;i<=n;i++)
{
j[i].wt=j[i-1].wt+j[i-1].bt;
j[i].tat=j[i].wt+j[i].bt;
}
printf("\n\n\tORDER OF EXECUTION OF JOBS\n\n"); printf("\tJN\tBT\tWT\tTAT\n\
n");
for(i=1;i<=n;i++)
{
printf("\t%s\t%d\t%d\t%d\n",j[i].jn,j[i].bt,j[i].wt,j[i].tat);
avgwt=avgwt+j[i].wt;
avgtat=avgtat+j[i].tat;
}
avgwt=avgwt/n; avgtat=avgtat/n; printf("\n\nAVG
WAITING TIME: %f",avgwt);
printf("\n\nAVG TURN AROUND TIME : %f\n\n",avgtat);
}

27
Output
[cselab@jec ~]$ cc sjf.c
[cselab@jec ~]$ ./a.out

Enter Total Number of Processes: 3


Enter Burst Time For Process[1]: 5
Enter Burst Time For Process[2]: 12
Enter Burst Time For Process[3]: 3
Process
Turnaround TimeID Burst TimeWaiting Time
Process[3] 3 0 3
Process[1] 5 3 8
Process[2] 12 8 20

Average Waiting Time: 3.666667

Average Turnaround Time: 10.333333

RESULT:
Thus the Shortest Job First CPU scheduling algorithms was executed successfully.

28
EX.NO: 4.3 First Come First Serve Algorithm (FCFS)
DATE :

AIM:
To write a C program to implement FCFS scheduling algorithm.

ALGORITHM:
Step1:Read no. of processes.
Step2:Read process name and burst time for each process.
Step3:CPU schedules processes according to their order of arrival in read queue (ie It
first executes process which is at head of ready queue)
Step4:Set waiting time(WT) of first process as zero and turnaround time(TAT) as burst
time.
Step5:Calculate waiting time and turnaround time of other processes as follows:
Pi (WT) = P i-1(WT) +P i-1(BT)
P i (TAT) = P i ( BT) + P i (WT)
Step6:Calculate and display average WT and TAT.
Step7:Display order of execution of processes ie. Process name, burst time, WT and TAT.

PROGRAM:
#include<stdio.h>
int main()
printf("Enter The Number of Processes To Execute:\t");
scanf("%d", &total_process);
printf("\nEnter The Burst Time of Processes:\n\n");
for(count = 0; count < total_process; count++)
{
printf("Process [%d]:", count + 1);
scanf("%f", &burst_time[count]);
}
waiting_time[0] = 0;
for(count = 1; count < total_process; count++)
{
waiting_time[count] = 0;
for(j = 0; j < count; j++)
{
waiting_time[count] = waiting_time[count] + burst_time[j];
}
}
printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time\n");
for(count = 0; count < total_process; count++)
{
turnaround_time[count] = burst_time[count] + waiting_time[count];
average_waiting_time = average_waiting_time + waiting_time[count];
average_turnaround_time = average_turnaround_time + turnaround_time[count];
printf("\nProcess [%d]\t\t%.2f\t\t%.2f\t\t%.2f", count + 1,
burst_time[count], waiting_time[count], turnaround_time[count]);
}
printf("\n");

29
average_waiting_time = average_waiting_time / count;
average_turnaround_time = average_turnaround_time / count;
printf("\nAverage Waiting Time = %f", average_waiting_time); printf("\
nAverage Turnaround Time = %f", average_turnaround_time); printf("\n");
return 0;
}

Output
[cselab@jec ~]$ cc fcfs.c
[cselab@jec ~]$ ./a.out
Enter The Number of Processes To Execute:

3 Enter The Burst Time of Processes:

Process [1]:24
Process [2]:3
Process [3]:3

Process Burst Time Waiting Time Turnaround Time

Process [1] 24.00 0.00 24.00


Process [2] 3.00 24.00 27.00
Process [3] 3.00 27.00 30.00

Average Waiting Time = 17.000000


Average Turnaround Time = 27.000000
[cselab@jec ~]$

RESULT:
Thus the First in First Out CPU scheduling algorithms was executed successfully.

30
EX.NO: 4 .4 Priority Scheduling Algorithm
DATE:

AIM:
To write a C program to implement priority scheduling algorithm.
ALGORITHM:
Step1:Read no. of processes.
Step2:Read process name, burst time and priority for each process.
Step3:Sort the processes in ready queue according to priority. (i.e. Process with high
priority get placed at head of ready queue) CPU schedules process with high priority
first followed by other processes.
Step4:Set waiting time (WT) of first process as zero and turnaround time (TAT) as
burst time.
Step5:Calculate waiting time and turnaround time of other processes as follows:
Pi (WT) = P i-1(WT) +P i-1(BT)
P i (TAT) = P i (BT) + P i (WT)
Step6:Calculate and display average WT and TAT.
Step7:Display order of execution of processes ie. Process name, burst time, priority,
WT and TAT.
Step8:Stop the program.

PROGRAM:
#include<stdio.h>
int main()
{
int burst_time[20], process[20], waiting_time[20], turnaround_time[20],
priority[20];
int i, j, limit, sum = 0, position, temp;
float average_wait_time, average_turnaround_time;
printf("Enter Total Number of Processes:\t");
scanf("%d", &limit);
printf("\nEnter Burst Time and Priority For %d Processes\n", limit);
for(i = 0; i < limit; i++)
{
printf("\nProcess[%d]\n", i + 1);
printf("Process Burst Time:\t");
scanf("%d", &burst_time[i]);
printf("Process Priority:\t");
scanf("%d", &priority[i]);
process[i] = i + 1;
}
for(i = 0; i < limit; i++)
{
position = i;
for(j = i + 1; j < limit; j++)
{
if(priority[j] < priority[position])

31
{
position = j;
}
}
temp = priority[i];
priority[i] =
priority[position];
priority[position] = temp;
temp = burst_time[i];
burst_time[i] = burst_time[position];
burst_time[position] = temp;
temp = process[i];
process[i] = process[position];
process[position] = temp;
}
waiting_time[0] = 0;
for(i = 1; i < limit;
i++)
{
waiting_time[i] =
0; for(j = 0; j < i; j+
+)
{
waiting_time[i] = waiting_time[i] + burst_time[j];
}
sum = sum + waiting_time[i];
}
average_wait_time = sum / limit;
sum = 0;
printf("\nProcess ID\t\tBurst Time\t Waiting Time\t Turnaround Time\
n"); for(i = 0; i < limit; i++)
{
turnaround_time[i] = burst_time[i] + waiting_time[i];
sum = sum + turnaround_time[i]; printf("\nProcess[%d]\
t\t%d\t\t %d\t\t %d\n", process[i], burst_time[i],
waiting_time[i], turnaround_time[i]);
}
average_turnaround_time = sum / limit;
printf("\nAverage Waiting Time:\t%f", average_wait_time); printf("\
nAverage Turnaround Time:\t%f\n", average_turnaround_time); return
0;
}

32
Output
[cselab@jec ~]$ cc prior.c
[cselab@jec ~]$ ./a.out
Enter Total Number of Processes: 3
Enter Burst Time and Priority For 3 Processes
Process[1]
Process Burst 5
Time: Process 3
Priority:
Process[2] 8
Process Burst
Time:
Process 2
Priority:
Process[3] 7
Process
Burst Time:
Process 1
Priority: Burst Time Waiting Turnaround
Process ID Time Time

Process[3] 7 0 7

Process[2] 8 7 15

Process[1] 5 15 20

Average Waiting Time: 7.000000


Average Turnaround Time: 14.000000
[cselab@jec ~]$

RESULT:
Thus the Priority CPU scheduling algorithm was executed successfully.

33
EX.NO: 5 IMPLEMENTATION OF SHARED MEMORY AND

IPC DATE:

AIM:
To write a C program to implement IPC (Inter Process Communication) via message
queue.

ALGORITHM:
Sender side
Step1:Establish a message queue using msgget() with unique msg id.
Step2:Read 5 messages from user using fgets( ) and transmit it to receiver
using msgsnd( ).
Receiver side
Step1:Establish a connection with message queue of sender.
Step2:Receive and print messages from queue using msgrcv( ).

PROGRAM:
Sender Side:
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h
>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<errno.h>
#include<string.h>
#define NMSGS 5
extern int errno;

struct msgbuf
{
long
mtype; char
mtext[100];
};
int main()
{
int msgid;
int i,nloop;
34
struct msgbuf msgp;

35
char tmp_msg[100];

tmp_msg[0]='\0'

msgid=msgget(9999,IPC_CREAT|0666);
if(msgid<0)
{
printf("%d:Error number is %d\n", LINE ,errno);
exit(1);
}
printf("Enter messsage(max 5lines)\n");
for(nloop=1;nloop<=NMSGS;nloop++)
{
msgp.mtype=1;
fgets(tmp_msg,100,stdin);
strncpy(msgp.mtext,tmp_msg,strlen(tmp_msg));
i=msgsnd(msgid,&msgp,strlen(tmp_msg),IPC_NOWAIT);
if(i<0)
{
printf("%d:Error number is%d\n", LINE ,errno);
exit(1);
}
tmp_msg[0]='\0';
}
return 0;
}

Receiver Side
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h
>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<errno.h>
#include<string.h>
extern int errno;

36
struct msgbuf

37
{
long mtype;

char mtext[100];
};
int main()
{
int
msgid;
int
i,nloop;
struct msgbuf msgp;
msgid=msgget(9999,0444);
if(msgid<0)
{
printf("%d:Error number is %d\n", LINE ,errno);
exit(1);
}
for(nloop=0;nloop<5;nloop++)
{
bzero(msgp.mtext,100);
i=msgrcv(msgid,&msgp,100,1,IPC_NOWAIT);
if(i<0)
{
printf("%d:Error number is %d\n", LINE ,errno);
exit(1);
}
msgp.mtext[strlen(msgp.mtext)]='\0';
fwrite(msgp.mtext,sizeof(char),strlen(msgp.mtext),stdout);
printf("Message is %s\n",msgp.mtext);
}

if(msgctl(msgid,IPC_RMID,NULL)<0)
{
printf("%d:Error number is %d\n", LINE ,errno);
exit(1);
}
return 0;

38
Output:
"ex31.c" 44L, 734C written
[cselab@jec ~]$ cc ex31.c
[cselab@jec ~]$ ./a.out Enter
messsage(max 5lines) welcome
to SVC
Welcome to OS Lab
Welcome to Second
year Good
[cselab@jec ~]$ cc ex32.c
[cselab@jec ~]$ ./a.out
welcome
Message is welcome
To SVC
Message is to SVC
Welcome to OS
Lab
Message is Welcome to OS Lab
Welcome to Second year
Message is Welcome to Second year
Good
Message is Good
[cselab@jec ~]$

RESULT:
Thus the Inter Process Communication program was executed successfully.

39
ExNo 6.1
To perform matrix addition in child process using shared memory
DATE:
AIM:
To write a C program to perform matrix addition in child process using shared memory

Algorithm
Step1:Enter the order of matrix
Step2:Using shmget create shared memory for parent and child process and attach shared
memory to processes.
Step3:Enter the element of matricse stored in to shared memory variable.
Step4:Calculate addition of matrices using shared memory.
Step5:Stop the
program Program
#include<unistd.h>
#include<stdio.h>
#include<sys/types.h>
#include<sys/shm.h>
int main()

{
int
p,k,i,n,l,m,*c;
int *a,*b;
printf("enter the order of matrix");
scanf("%d",&n);
k=shmget(IPC_PRIVATE,n*sizeof(int),00700);
a=(int*) shmat(k,0,0);
l= shmget(IPC_PRIVATE,n*sizeof(int),00700);
b=(int*) shmat(k,0,0);
m= shmget(IPC_PRIVATE,n*sizeof(int),00700);
c=(int*) shmat(k,0,0);
printf("enter the elements of a");
for(i=0;i<n*n;i++)
{
40
scanf("%d",(a+i));
}
printf("enter the elements of b");
for(i=0;i<n*n;i++)
{

scanf("%d",(b+i));

}
p=fork();
if(p==0)
{
for(i=0;i<(n*n)/2;i++)

*(c+i)=*(a+i)+*(b+i);
}

printf("matrix
addition");
for(i=0;i<n*n;i++)

printf("%d\t",*(c+i));
}

if(p!=0)
{

for(i=(n*n)/2;i<n*n;i++)
{

*(c+i)=*(a+i)+*(b+i);
}
}

for(i=0;i<n*n;i++)
{
printf("%d\t",*(c+i));

return 0;
}
41
}

42
Output
[cselab@jec ~]$ cc matadd.c
[cselab@jec ~]$ ./a.out enter the
order of matrix3
enter the elements of a1 2
3456
789

enter the elements of b4 5 6


213

345

[cselab@jec ~]$ matrix addition 8 10 12

4 1 3
3 4 5

8 10 12
4 1 3
3 4 5

Result:
Thus the program to perform matrix addition in child process using shared memory
was written and executed successfully.

43
Ex No: 6.2
To generate ODD number using Shared memory.
DATE:

AIM:
To write a C program to generate ODD number using shared memory.

Algorithm
Step1:Enter the number of elements.
Step2:Using shmget create shared memory for parent and child process and attach shared
memory to processes.
Step3:Using shared memory variable find out the odd number.
Step4:Generate odd series.
Step5:Stop the program.
Program
#include<sys/ipc.h>
#include<sys/shm.h>
#include<stdio.h>
main()

{
int k;
int
*a;
int
n,i;
printf("enter the no of elements");
scanf("%d",&n);
k=shmget(IPC_PRIVATE,n*n*sizeof(int),00700);
a=shmat(k,NULL,0);
printf("enter the
elements");
for(i=0;i<n;i++)
scanf("%d",(a+i));
int b=fork();
printf("odd
44
number"); if(b!=0)
{for(i=0;i<n;i++)

45
{
if((*a+i)%2!

printf("%d",*(a+i));
}

}
if(b==0)

for(i=n/2;i<n;i++)
{

if(*(a+i)%2!=0)
printf("%d",*(a+i));

}
}
shmdt(a);
}

Output
[cselab@jec os]$ cc odd.c
[cselab@jec os]$ ./a.out enter
the no of elements3
enter the elements1
2
3
odd number13[cselab@jec os]$

Result
Thus the Program to To generate ODD number using Semaphore was written and
executed successfully.

46
EX.NO:6.3 IMPLEMENTATION OF SEMAPHORES
DATE:

AIM:
To write a C program to implement PCP (Producer Consumer Problem) using
semaphores.

ALGORITHM:
Step1:Read size of buffer
Step2:Producer process produces and buffers the items using shmget() and shmctl()
Step3:Consumer process consumes item from buffer using semop() and semrel()
Step4:Producer process waits if buffer is full and consumer process waits if buffer is
empty.

PROGRAM:
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h
>
#include<sys/shm.h>
#include<sys/ipc.h>
#include<sys/sem.h>
#include<stdlib.h>
union semum
{
int array[3];
};
main()
{
int
k,f,i,x,n,t,sid,num[10],j,in=0,out=0;
int *l;
union semum arg;
struct sembuf a;
sid=shmget(50010,3,IPC_CREAT | 00700);
if(sid == -1)
{
printf("Not
created"); exit(0);
}
printf("Enter the no of
number");
scanf("%d",&n);
arg.array[0]=1;

47
arg.array[1]=5;
arg.array[2]=0;

48
semctl(sid,0,SETALL,arg);
k=shmget(IPC_PRIVATE,5*sizeof(int),00700);
l=(int*) shmat(k,NULL,0);
f=fork();
printf(" fork value=%d",f);
if(f != 0)
{
for(i=0;i<n;i++)
{
printf("Enter the number\n"); scanf("%d\
n",&num[i]);
a.sem_num=1;
a.sem_op=-1;
a.sem_flg=0;
semop(sid,&a,-1);

a.sem_num=0;
a.sem_op=-1;
a.sem_flg=0;
semop(sid,&a,-1);
l[in]=num[i];
in=(in+1)%n;
a.sem_num=0;
a.sem_op=1;
a.sem_flg=0;
semop(sid,&a,1);
a.sem_num=2;
a.sem_op=1;
a.sem_flg=0;
semop(sid,&a,1);
}
shmctl(k,IPC_RMID,NULL);
}
if(f==0)
{
for(j=0;j<n;j++)
{
a.sem_num=2;
a.sem_op=-1;
a.sem_flg=0;
semop(sid,&a,1);
a.sem_num=0;
a.sem_op=-1;
a.sem_flg=0;
semop(sid,&a,1);
x=l[out];
out=(out+1)%n;
a.sem_num=0;
a.sem_op=1;
49
a.sem_flg=0;
semop(sid,&a,1);
a.sem_num=0;
a.sem_op=1;
a.sem_flg=0;
semop(sid,&a,1);
printf("\n Consumer %d",x);
}
}
}

Output
[cselab@jec ~]$ cc semaphore.c
[cselab@jec ~]$ ./a.out
Enter the no of number3
Enter the number 6 3 4
Consumer consumes 4
Consumer consumes 3
Consumer consumes 6

Result

Thus the program to implement PCP (Producer Consumer Problem) using semaphores
was written and executed successfully.

50
EX.NO: 7 Implementation of Bankers Algorithm for Deadlock Avoidance
DATE:

AIM:
A program to simulate the Bankers Algorithm for Deadlock Avoidance.

Algorithm
Step1:Get the number of processes and number of resource instances.
Step2:Get the allocation matrix and Available matrix from the user.
Step3:Calculate need matrix.
Step4:Using banker’s algorithm allocate resources to processes.
Step5:Print safe sequence of processes..
Step6:Stop the program.

PROGRAM:
#include<stdio.h>
int max[100][100];
int alloc[100]
[100]; int
need[100][100]; int
avail[100];
int n,r;

void input();
void
show();
void cal();
int main()
{
int i,j;
printf("********** Banker's Algorithm ************\n");
input();
show();
cal();
//
getch();

51
return 0;
}
void input()

52
{
int i,j;
printf("Enter the no of Processes\t");
scanf("%d",&n);
printf("Enter the no of resources instances\t");
scanf("%d",&r);
printf("Enter the Max Matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
scanf("%d",&max[i][j]);
}
}
printf("Enter the Allocation Matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
scanf("%d",&alloc[i][j]);
}
}
printf("Enter the available Resources\n");
for(j=0;j<r;j++)
{
scanf("%d",&avail[j]);
}
}
void show()
{
int i,j;
printf("Process\t Allocation\t Max\t Available\t");
for(i=0;i<n;i++)
{
printf("\nP%d\t ",i+1);

53
for(j=0;j<r;j++)
{
printf("%d ",alloc[i][j]);
}
printf("\t");
for(j=0;j<r;j++
)
{
printf("%d ",max[i][j]);
}
printf("\t");
if(i==0)
{
for(j=0;j<r;j++)
printf("%d
",avail[j]);
}
}
}
void cal()
{
int finish[100],temp,need[100]
[100],flag=1,k,c1=0; int safe[100];
int i,j;
for(i=0;i<n;i++)
{
finish[i]=0;
}
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
need[i][j]=max[i][j]-alloc[i][j];
}
}

54
printf("\n");
while(flag)

{
flag=0;
for(i=0;i<n;i++)
{
int c=0;
for(j=0;j<r;j++
)
{
if((finish[i]==0)&&(need[i][j]<=avail[j]))
{
c++;
if(c==r)
{
for(k=0;k<r;k++)
{
avail[k]+=alloc[i][j];
finish[i]=1;
flag=1;
}
printf("P%d->",i);
if(finish[i]==1)
{
i=n;
}
}
}
}
}
}
for(i=0;i<n;i++)
{
if(finish[i]==1)

55
{
c1++;
}
else

{
printf("P%d->",i);
}
}
if(c1==n)
{
printf("\n The system is in safe state");
}
else
{
printf("\n Process are in dead lock");
printf("\n System is in unsafe state");
}
}

56
Output
********** Banker's Algorithm
************ Enter the no of Processes
5 Enter the no of resources instances 3
Enter the Max Matrix
753
322
902
222
433
Enter the Allocation
Matrix 0 1 0
200
302
211
002
Enter the available Resources
332
Process Allocation Max Available
P1 010 753332
P2 200 322
P3 302 902
P4 211 222
P5 002 433

P1->P3->P4->P2->P0->
The system is in safe state

RESULT:
Thus the program for implementing deadlock avoidance algorithm was implemented
has been executed successfully.

57
EX.NO: 8 Implementation of Deadlock Detection Algorithm
DATE :

AIM:
To write a C program to implement the concept of deadlock detection.

ALGORITHM
1. Get the number of processes and number of resource
instances. 2.Get the allocation matrix and Available matrix
from the user. 3.Calculate need matrix.
4.Using banker’s algorithm allocate resources to processes.
5.Print”deadlock occurred or not.
6.Stop the program.

PROGRAM:
#include<stdio.h>
int max[100][100];
int alloc[100][100];
int need[100][100];
int avail[100];
int n,r;

void input(); void


show(); void cal(); int
main()
{
int i,j;
printf("********** Deadlock Detection Algo ************\n"); input();
show();
cal();
return
0;
}
void input()
{
int i,j;
printf("Enter the no of Processes\t"); scanf("%d",&n);

58
printf("Enter the no of resource instances\t"); scanf("%d",&r);

59
printf("Enter the Max Matrix\n"); for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
scanf("%d",&max[i][j]);
}
}
printf("Enter the Allocation Matrix\n"); for(i=0;i<n;i++)
{for(j=0;j<r;j++)
{
scanf("%d",&alloc[i][j]);
}
}
printf("Enter the available Resources\n"); for(j=0;j<r;j++)
{
scanf("%d",&avail[j]);
}
}
void show()
{
int i,j;
printf("Process\t Allocation\t Max\t Available\t"); for(i=0;i<n;i++)
{
printf("\nP%d\t ",i+1); for(j=0;j<r;j++)
{
printf("%d ",alloc[i][j]);
}
printf("\t"); for(j=0;j<r;j++)
{
printf("%d ",max[i][j]);
}
printf("\t"); if(i==0)
{
for(j=0;j<r;j++);

printf("%d

60
",avail[j]);

61
}
}
}
void cal()
{
int finish[100],temp,need[100][100],flag=1,k,c1=0; int dead[100];
int safe[100];
int i,j; for(i=0;i<n;i+
+);
{
finish[i]=0;
}
for(i=0;i<n;i++)
{
for(j=0;j<r;j++);
{
need[i][j]=max[i][j]-alloc[i][j];
}
{
flag=0;

for(i=0;i<n;i++);

{
int c=0;

for(j=0;j<r;j++);
{
if((finish[i]==0)&&(need[i][j]<=avail[j]))
{ c+
+;
if(c==r)
{
for(k=0;k<r;k++);
{
avail[k]+=alloc[i][j];
finish[i]=1; flag=1;
if(finish[i]==1)
62
{
i=n;
}
}
}
}

j=0;
flag=0;
for(i=0;i<n;i++)
{
if(finish[i]==0)
{
dead[j]=i;

j++;
flag=1;
}
}
if(flag==1)
{
printf("\n\nSystem is in Deadlock and the Deadlock process are\n");
for(i=0;i<n;i++)
printf("P%d\t",dead[i]);

}}
else
{

printf("\nNo Deadlock Occur");


}}

63
Output

********** Deadlock Detection Algo


************ Enter the no of Processes 5
Enter the no of resource instances 3
Enter the Max Matrix
753
322
902
222
433
Enter the Allocation Matrix
010
200
302
211
002
Enter the available Resources
322
Process Allocation Max Available
P1 010 753 322
P2 200 322
P3 302 902
P4 211 222
P5 002 433

P1 P3 P4 P2 P0 No Deadlock Occur

RESULT:
Thus the program for implementing deadlock detection algorithm was executed
successfully

64
EX.NO:9 WRITE C PROGRAM TO IMPLEMENT
THREADING & SYNCHRONISATION
APPLICATIONS
DATE:
AIM:
To write a C program to implement thread and synchronisation applications.

ALGORITHM:
Step1. Start the program
Step2. i is initialized in the beginning of the main function.

Step3. Pthread function used to create thread by calling myThread().The variable is


locked using mutex variable i
Step4. The threads wait for 30ms then the thread is completed one by one in the order
which will complete execution.
Step5. At the end of the main function the mutex is destroyed .
Step6. Stop the program

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
int c;
void *myThreadFun(void *vargp)
{
int i=0;
printf("Thread %d is processing \n",vargp);
//c+=1;
//for(i=0;i<(0xFFFFFFFF);i++);
sleep(40);
printf("Thread %d is completed\n",vargp);
pthread_exit(NULL);

}
void *mythread(void *vargp)
{
printf("Thread %d is running",vargp);

65
pthread_exit(NULL);

66
}

int main()

{
int i,x;
pthread_t
a[6];
printf("Before Thread\
n"); for(i=0;i<5;i++)
{
x=pthread_create(&a[i],NULL,myThreadFun,(void
*)i); if(x!=0)
printf("Thread not created");
}
//for(i=0;i<5;i++)
//{
//x=pthread_create(&a[i],NULL,mythread,(void *)i);
//if(x!=0)
// printf("Thread is not created\n");
//}
pthread_exit(NULL);

67
Output

[cselab@jec ~]$ cc extrial.c -pthread cc:


extrial.c: No such file or directory
cc: no input files

[cselab@jec ~]$ cc ex5trial.c -pthread


[cselab@jec ~]$ ./a.out

Before Thread

Thread 3 is
processing Thread 4
is processing Thread
2 is processing
Thread 0 is
processing Thread 1
is processing Thread
3 is completed Thread
4 is completed Thread
2 is completed Thread
0 is completed Thread
1 is completed
[cselab@jec ~]$

RESULT:
Thus the program for implementing thread and synchronisation application was
executed successfully
68
EX.NO: 10.1 IMPLEMENTATION OF MEMORY MANAGEMENT - PAGING

DATE:

AIM:

To write a C program to implement paging concept for memory management.

ALGORITHM:
Step 1: Start the program.
Step 2: Enter the logical memory address i.e no of pages in memory.
Step 3: Enter the page table which has offset and page frame.

Step 4: The corresponding physical address can be calculate


by, PA = [ pageframe* No. of page size ] + Page offset.
Step 5: Print the physical address for the corresponding logical address.
Step 6: Terminate the program.
PROGRAM:
#include<stdio.h>
#define MAX 50
int main()
{

int page[MAX],i,n,f,ps,off,pno;
printf("\nEnter the no of pages
in memory"); scanf("%d",&n);
printf("\nEnter page size");
scanf("%d",&ps); printf("\
nEnter no of frames");
scanf("%d",&f); for(i=0;i<n;i+
+)
page[i]=-1;

printf("\nEnter the page table\n");

printf("(Enter frame no as -1 if that page is not present in any frame)\n\


n"); printf("\npageno\tframeno\n-------\t ");
for(i=0;i<n;i++)

{
printf("\n\n%d\t\t",i);

69
scanf("%d",&page[i]);
}

printf("\n\nEnter the logical address(i.e,page no & offset):"); scanf("%d


%d",&pno,&off);
if(page[pno]==-1)

printf("\n\nThe required page is not available in any of frames");


else

printf("\n\nPhysical address(i.e,frame no & offset):%d,%d",page[pno],off); printf("\


nPhysical Address is %d",(page[pno]*ps)+off);
return 1;

Output
Enter the no of pages in
memory4 Enter page size2
Enter no of frames4
Enter the page table

(Enter frame no as -1 if that page is not present in any frame)


page no frame no

0 3
1 5
2 1
3 7

Enter the logical address(i.e,page no & offset):2 19


Physical address(i.e,frame no & offset):1,19
Physical Address is 21

RESULT:
Thus C program for implementing paging concept for memory management has been
executed successfully.

70
EX.NO:10.2 MEMORY ALLOCATION METHODS FOR FIXED PARTITION
FIRST FIT ALLOCATION

DATE:

AIM:
To allocate memory requirements for processes using first fit allocation.

ALGORITHM:

1. Declare structures hole and process to hold information about set of holes
and processes respectively.
2. Get number of holes, say nh.
3. Get the size of each hole
4. Get number of processes, say np.
5. Get the memory requirements for each process.
6. Allocate processes to holes, by examining each hole as follows:
a. If hole size>process size then
i. Mark process as allocated to that hole.
ii. Decrement hole size by process size.
b. Otherwise check the next from the set of holes
7. Print the list of process and their allocated holes or unallocated status.
8. Print the list of holes, their actual and
current availability
.9.Stop the program.

PROGRAM
#include<stdio.h>
struct process
{
int size; int flag; int hole_id;
}p[10];
struct hole
{
int size;
int
actual;
}h[10];
main()
{
int i,np,nh,j;
printf("EnterthenumberofHoles:");
scanf("%d",&nh); for(i=0;i<nh;i+
+){ printf("EntersizeforholeH
%d:",i);
71
scanf("%d",&h[i].size);
h[i].actual=h[i].size;
}
printf("\nEnternumberofprocess:");
scanf("%d",&np); for(i=0;i<np;i++)
{
printf("enterthesizeofprocessP%d:",i);
scanf("%d",&p[i].size);
p[i].flag=0;
}
for(i=0;i<np;i++){
for(j=0;j<nh;j++){
if(p[i].flag!=1){
if(p[i].size<=h[j].size){
p[i].flag=1; p[i].holeid=j; h[j].size-=p[i].size;
}}}}
printf("\n\tFirstfit\n"); printf("\
nProcess\tPSize\tHole");
for(i=0;i<np;i++){ if(p[i].flag!
=1)
printf("\nP%d\t%d\tNotallocated",i,p[i].size);
else printf("\nP%d\t%d\tH
%d",i,p[i].size,p[i].holeid);
}
printf("\n\nHole\tActual\tAvailable");
for(i=0;i<nh;i++) printf("\nH%d\t%d\t
%d",i,h[i].actual,h[i].size); printf("\n");
}

72
OUTPUT:

RESULT:
Thus processes were allocated memory using first fit method.

73
EX. NO:10.3 WORST FIT

ALLOCATION DATE:

AIM:
To allocate memory requirements for processes using worst fit allocation.

ALGORITHM:

Step 1: Start the program.


Step 2: Input memory blocks and processes with
sizes.
Step 3: Initialize all memory blocks as free.
Step 4: Start by picking each process and find the
maximum block size that can be assigned to
current process i.e., find max(bockSize[1],
blockSize[2], blockSize[n])

> processSize[current], if found then assign it to


the current process.
Step 5: If not then leave that process
and keep checking the further
processes.
Step 6: Stop the program.

PROGRAM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int
frag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
clrscr();
printf("\n\tMemory Management Scheme - First Fit");
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++)
{
74
printf("File %d:",i);

75
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)
{
ff[i]=j;
break;
}
}
}
frag[i]=temp;
bf[ff[i]]=1;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\
tFragement"); for(i=1;i<=nf;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();
}
INPUT
Enter the number of blocks: 3
Enter the number of files: 2
Enter the size of the blocks:-
Block 1: 5
Block 2: 2
Block 3: 7
Enter the size of the files:-
File 1: 1
File 2: 4

OUTPUT
File No File Size Block No Block Size Fragment
1 1 1 5 4
2 4 3 7 3

RESULT:

Thus processes were allocated memory using the worst fit method.

76
EX. NO:10.4 BEST FIT

ALLOCATION DATE:

AIM:
To allocate memory requirements for processes using best fit allocation.

ALGORITHM:
1. Declare structures hole and process to hold information
about set of holes and processes respectively.
2. Get the number of holes, say nh.
3. Get the size of each hole
4. Get the number of processes, say np.
5. Get the memory requirements for each process.
6. Allocate processes to holes, by examining each hole as follows:
a. Sort the holes according to their sizes in ascending order
b. If hole size>process size then
i. Mark process as allocated to that hole.
ii. Decrement hole size by process size.
c. Otherwise check the next from the set of sorted holes.
7. Print the list of processes and their allocated holes or unallocated status.
8. Print the list of holes, their actual and current availability.
9. Stop

PROGRAM:
#include<stdio.h>
struct process
{
int size;
int flag;
int
holeid;
}
p[10];
struct hole
{
int hid;
int size;
int
actual;
}
h[10];
main()
{
int i,np,nh,j;
void bsort(structhole[],int);
printf("Enter the number of Holes:");
scanf("%d",&nh);
for(i=0;i<nh;i++)
{
77
printf("Enter size for holeH%d:",i);

78
scanf("%d",&h[i].size);
h[i].actual=h[i].size;
h[i].hid=i;
}
printf("\nEnter number of process:");
scanf("%d",&np);
for(i=0;i<np;i++)
{
printf("enter the size of processP%d:",i);
scanf("%d",&p[i].size);
p[i].flag=0;
}
for(i=0;i<np;i++)
{
bsort(h,nh); for(j=0;j<nh;j+
+)
{
if(p[i].flag!=1)
{
if(p[i].size<=h[j].size)
{
p[i].flag=1;
p[i].holeid=h[j].hid;
h[j].size-=p[i].size;
}}}
}
printf("\n\tBestfit\n"); printf("\
nProcess\tPSize\tHole");
for(i=0;i<np;i++)
{
if(p[i].flag!=1) printf("\nP%d\t%d\
tNotallocated",i,p[i].size); else printf("\nP%d\t
%d\tH%d",i,p[i].size,p[i].holeid);
}
printf("\n\nHole\tActual\tAvailable"); for(i=0;i<nh;i+
+) printf("\nH%d\t%d\t%d",h[i].hid,h[i].actual,
h[i].size); printf("\n");
}
Void bsort(structholebh[],intn)
{
struct
holetemp; int
i,j;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(bh[i].size>bh[j].size)
{
temp=bh[i];
bh[i]=bh[j];
bh[j]=temp;
}
}
}
}

79
OUTPUT:

PAGE REPLACEMENT ALGORITHM

RESULT:
Thus processes were allocated memory using the best fit method.

80
EX.NO: 11.1 First In First Out
DATE:

AIM:
To write a C program to implement FIFO page replacement algorithms.

ALGORITHM:
Step1:Read the size of the frame, no. of elements and elements one by one.
Step2:Initialise the frames with value -1.
Step3:Insert each element into frame, if it's not present.
Step4:If the frame is full and the new element is not already present then replace
the oldest element by the new element.
Step5:Increment no. of page faults by one while inserting each element into
the frames.
Step6:Display the contents of frames during processing and the total no. of page
faults.

PROGRAM:

#include<stdio.h>
int main()
{
int reference_string[10], page_faults = 0, m, n, s, pages, frames; printf("\
nEnter Total Number of Pages:\t");
scanf("%d", &pages);
printf("\nEnter values of Reference String:\n");
for(m = 0; m < pages; m++)
{
printf("Value No. [%d]:\t", m +
1); scanf("%d",
&reference_string[m]);
}
printf("\nEnter Total Number of Frames:\t");
{
scanf("%d", &frames);
}
int temp[frames];

81
for(m = 0; m < frames; m++)
{
temp[m] = -1;
}
for(m = 0; m < pages; m++)
{
s = 0;
for(n = 0; n < frames; n++)
{
if(reference_string[m] == temp[n])
{
s++;
page_faults--;
}
}
page_faults++;
if((page_faults <= frames) && (s == 0))
{
temp[m] = reference_string[m];
}
else if(s == 0)
{
temp[(page_faults - 1) % frames] = reference_string[m];
}
printf("\n");
for(n = 0; n < frames; n++)
{
printf("%d\t", temp[n]);
}
}
printf("\nTotal Page Faults:\t%d\n", page_faults);
return 0;
}

82
Output

[cselab@jec ~]$ ./a.out Enter


Total Number of Pages:

5
Enter values of Reference String:
Value No. [1]: 3
Value No. [2]: 5
Value No. [3]: 2
Value No. [4]: 3
Value No. [5]: 4
Enter Total Number of Frames: 3
3 -1 -1
3 5 -1
3 5 2
3 5 2
4 5 2

Total Page Faults: 4

Result:
Thus the program to implement FIFO page replacement algorithm was written and
83
executed successfully.

84
EX.NO: 11.2 Least Recently Used (LRU)
DATE:

AIM:
To write a C program to implement LRU page replacement algorithm.

ALGORITHM:
Step1:Read the size of the frame, no. of elements and elements one by one.
Step2:Initialize the frames with value -1.
Step3:Insert each element into frame, if it’s already not present.
Step4:If the frame is full and new element is not already present then replace the least
recently used element by the new element.
Step5:Increment no. of page faults by one while inserting each element into the frames.
Step6:Display the contents of frames during processing and the total no. of page faults.

PROGRAM:
#include<stdio.h>
int main()
{
int frames[10], temp[10], pages[10];
int total_pages, m, n, position, k, l, total_frames;
int a = 0, b = 0, page_fault = 0;
printf("\nEnter Total Number of Frames:\t");
scanf("%d", &total_frames);
for(m = 0; m < total_frames; m++)
{
frames[m] = -1;
}
printf("Enter Total Number of Pages:\t");
scanf("%d", &total_pages);
printf("Enter Values for Reference String:\n");
for(m = 0; m < total_pages; m++)
{
printf("Value No.[%d]:\t", m + 1);

85
scanf("%d", &pages[m]);
}
for(n = 0; n < total_pages; n++)
{
a = 0, b = 0;
for(m = 0; m < total_frames; m++)
{
if(frames[m] == pages[n])
{
a = 1;
b = 1;
break;
}
}
if(a == 0)
{
for(m = 0; m < total_frames; m++)
{
if(frames[m] == -1)
{
frames[m] = pages[n];
b = 1;
break;
}
}
}
if(b == 0)
{
for(m = 0; m < total_frames; m++)
{
temp[m] = 0;
}
for(k = n - 1, l = 1; l <= total_frames - 1; l++, k--)
{
for(m = 0; m < total_frames; m++)

86
{
if(frames[m] == pages[k])
{
temp[m] = 1;
}
}
}
for(m = 0; m < total_frames; m++)
{
if(temp[m] == 0)
position = m;
}
frames[position] = pages[n];
page_fault++;
}
printf("\n");
for(m = 0; m < total_frames; m++)
{
printf("%d\t", frames[m]);
}
}
printf("\nTotal Number of Page Faults:\t%d\n", page_fault);
return 0;
}

87
Output

[cselab@jec ~]$ ./a.out Enter

Total Number of Frames: 3 Enter

Total Number of Pages: 7

Enter Values for Reference String:

Value No.[1]: 5
Value No.[2]: 6
Value No.[3]: 3

Value No.[4]: 2

Value No.[5]: 5
Value No.[6]: 1
Value No.[7]: 8

5 -1 -1
5 6 -1

5 6 3

2 6 3

2 5 3

2 5 1
8 5 1

Total Number of Page Faults: 4

Result

Thus the program to implement LRU page replacement algorithm was written and
executed successfully.

88
EX.NO: 11.3 OPTIMAL PAGE REPLACEMENT
ALGORITHMS DATE:
AIM:

To implement Optimal (The page which is not used for longest time) page replacement
algorithms.

ALGORITHM:
Step1:Read the size of the frame, no. of elements and elements one by one.
Step2:Initialize the frames with value -1.
Step3:Insert each element into frame, if it’s already not present.
Step4:If the frame is full and new element is not already present then replace the least
frequently used element by the new element.
Step5:Increment no. of page faults by one while inserting each element into the frames.
Step6:Display the contents of frames during processing and the total no. of page faults.
PROGRAM:
#include<stdio.h>
int main()
{
int reference_string[25], frames[25], interval[25];
int pages, total_frames, page_faults = 0;
int m, n, temp, flag, found;
int position, maximum_interval, previous_frame = -1;
printf("\nEnter Total Number of Pages:\t");
scanf("%d", &pages);
printf("\nEnter Values of Reference String\n");
for(m = 0; m < pages; m++)
{
printf("Value No.[%d]:\t", m +
1); scanf("%d",
&reference_string[m]);
}
printf("\nEnter Total Number of Frames:\t");
scanf("%d", &total_frames);
for(m = 0; m < total_frames; m++)
{
89
frames[m] = -1;
}
for(m = 0; m < pages; m++)
{
flag = 0;
for(n = 0; n < total_frames; n++)
{
if(frames[n] == reference_string[m])
{
flag = 1;
printf("\t");
break;
}
}
if(flag == 0)
{
if (previous_frame == total_frames - 1)
{
for(n = 0; n < total_frames; n++)
{
for(temp = m + 1; temp < pages; temp++)
{
interval[n] = 0;
if (frames[n] == reference_string[temp])
{
interval[n] = temp - m;
break;
}
}
}
found = 0;
for(n = 0; n < total_frames; n++)
{
if(interval[n] == 0)
{

90
position = n;
found = 1;
break;
}
}
}
else
{
position = ++previous_frame;
found = 1;
}
if(found == 0)
{
maximum_interval = interval[0];
position = 0;
for(n = 1; n < total_frames; n++)
{
if(maximum_interval < interval[n])
{
maximum_interval = interval[n];
position = n;
}
}
}
frames[position] = reference_string[m];
printf("FAULT\t");
page_faults++;
}
for(n = 0; n < total_frames; n++)
{
if(frames[n] != -1)
{
printf("%d\t", frames[n]);
}
}

91
printf("\n");
}
printf("\nTotal Number of Page Faults:\t%d\n", page_faults);
return 0;
}
Output

Enter Total Number of Pages:

6 Enter Values of Reference

String

Value No.[1]: 3
Value No.[2]: 2

Value No.[3]: 3
Value No.[4]: 5

Value No.[5]: 6
Value No.[6]: 1

Enter Total Number of Frames: 4

FAULT 3
FAULT 3 2
3 2

FAULT 3 2 5
FAULT 3 2 5 6
FAULT 3 2 5 1

Total Number of Page Faults: 5

Result

Thus the program to implement optimal page replacement algorithm was written and
executed successfully.
92
EX.NO: 12.1 FILE ORGANIZATION TECHNIQUES
IMPLEMENTATION OF SINGLE LEVEL DIRECTORY

DATE:

AIM:
To write a C program to implement Single - Level directory structure in C
ALGORITHM:
1. Start
2. Declare the number, names and size of the directories and file names.
3. Get the values for the declared variables.
4. Display the files that are available in the directories.
5. Stop

PROGRAM:
#include<stdio.h>
main()
{
int master,s[20];
char f[20][20]
[20];
char d[20]
[20]; int i,j;
printf("enter number of directorios:");
scanf("%d",&master);
printf("enter names of directories:");
for(i=0;i<master;i++)
scanf("%s",&d[i]);
printf("enter size of directories:");
for(i=0;i<master;i++)
scanf("%d",&s[i]);
printf("enter the file names :");
for(i=0;i<master;i++)
for(j=0;j<s[i];j++)
scanf("%s",&f[i][j]); printf("\
n");
printf(" directory\tsize\tfilenames\n");
printf("*************************************************\n");
for(i=0;i<master;i++)
{
printf("%s\t\t%2d\t",d[i],s[i]);
for(j=0;j<s[i];j++) printf("%s\n\t\t\
t",f[i][j]); printf("\n");
}
printf("\t\n");
}

93
OUTPUT:

RESULT:

Thus the Single level directory structure is written and executed successfully.

94
EX.NO:12.2 IMPLEMENTATION OF TWO-LEVEL DIRECTORY

DATE:

AIM:
To write a C program to implement Two-level directory structure in C.

ALGORITHM:
1. Start
2. Declare the number, names and size of the directories and subdirectories and filenames.
3. Get the values for the declared variables.
4. Display the files that are available in the directories and subdirectories.
5. Stop.

PROGRAM:

#include<stdio.h>
struct st
{
char dname[10];
char sdname[10][10];
char fname[10][10]
[10]; int ds,sds[10];
}dir[10];
void
main()
{
int i,j,k,n;
clrscr();
printf("enter number of directories:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter directory %d
names:",i+1);
scanf("%s",&dir[i].dname);
printf("enter size of directories:");
scanf("%d",&dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
printf("enter subdirectory name and size:");
scanf("%s",&dir[i].sdname[j]);
scanf("%d",&dir[i].sds[j]);
for(k=0;k<dir[i].sds[j];k++)
{
printf("enter file name:"); scanf("%s",&dir[i].fname[j]
95
[k]);
}}}

96
printf("\ndirname\t\tsize\tsubdirname\tsize\tfiles"); printf("\
n******************************************************\n"); for(i=0;i<n;i++){
printf("%s\t\t%d",dir[i].dname,dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
printf("\t%s\t\t%d\t",dir[i].sdname[j],dir[i].sds[j]);
for(k=0;k<dir[i].sds[j];k++) printf("%s\
t",dir[i].fname[j][k]);
printf("\n\t\t");}
printf("\n"); }
}

OUTPUT:

RESULT:

Thus a C program to implement Two-level directory structure is written and executed


successfully

97
FILE ALLOCATION STRATEGIES

EX.NO: 13.1 Sequential File Allocation


DATE
:

AIM:
To write a C Program to implement Sequential File Allocation method.

ALGORITHM:
Step 1: Start the program.

Step 2: Enter the number of files.using for loop get the file name

Step 3: Get the starting block of each file from that allocate blocks sequentially.
Step 4: Print the File name and blocks occupied by file will be displayed.
Step 5: Stop the program.

PROGRAM:
#include<stdio.h>
main()
{
int n,i,j,b[20],sb[20],t[20],x,c[20]
[20]; printf("Enter no.of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter no. of blocks occupied by
file%d",i+1); scanf("%d",&b[i]);
printf("Enter the starting block of file
%d",i+1); scanf("%d",&sb[i]); t[i]=sb[i];
for(j=0;j<b[i];j++)
c[i][j]=sb[i]++;
}
printf("Filename\tStart block\tlength\
n"); for(i=0;i<n;i++)
printf("%d\t %d \t%d\n",i+1,t[i],b[i]);
printf("Enter file name:");

98
scanf("%d",&x);
printf("File name is:
%d",x);
printf("length is:%d",b[x-
1]); printf("blocks
occupied:"); for(i=0;i<b[x-
1];i++) printf("%4d",c[x-1]
[i]); getch();
}

Output
Enter no.of files:2
Enter no. of blocks occupied by
file1 5 Enter the starting block of
file1 1 Enter no. of blocks occupied
by file2 5 Enter the starting block of
file2 6 Filename Start
block length
1 1 5
2 6 5
Enter file name:1
File name is:1 length is:5 blocks occupied: 1 2 3 4 5

Result
Thus the following file allocation technique of Sequential File Allocation was written
and executed successfully.
99
EX.NO:13.2 INDEXED FILE
ALLOCATION DATE:

AIM:

To write a C Program to implement Indexed File Allocation method.

ALGORITHM:
Step 1: Start.

Step 2: Enter the filename and blocks occupied by a file index block using
loop. Step 3: Allocate file to index block.

Step 4: print the file name and index


block. Step 5: Stop the program.

PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
int n,m[20],i,j,sb[20],s[20],b[20]
[20],x; printf("Enter no. of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter starting block and size of file%d:",i+1); scanf("%d
%d",&sb[i],&s[i]);
printf("Enter blocks occupied by
file%d:",i+1);
scanf("%d",&m[i]); printf("enter
blocks of file%d:",i+1);
for(j=0;j<m[i];j++)
scanf("%d",&b[i][j]);
}
printf("\nFile\t index\tlength\
n"); for(i=0;i<n;i++)

10
0
{

10
1
printf("%d\t%d\t%d\n",i+1,sb[i],m[i]);
}
printf("\nEnter file
name:");
scanf("%d",&x);
printf("file name is:%d\
n",x); i=x-1;
printf("Index is:%d",sb[i]);
printf("Block
occupiedare:");
for(j=0;j<m[i];j++)
printf("%3d",b[i][j]);
}

Output
[cselab@jec ~]$ ./a.out
Enter no. of files:2
Enter starting block and size of file1:2 5
Enter blocks occupied by file1:10
enter blocks of
file1:3 2 5 4 6 7 2 6
4
7
Enter starting block and size of file2:3 4
Enter blocks occupied by file2:5
enter blocks of file2:2 3 4 5 6

File index length


1 2 10
2 3 5

Enter file
name:1
file name
is:1
Index is:2 Block occupied are: 3 2 5 4 6 7 2 6 4 7
10
2
Result
Thus the following file allocation technique of Indexed File Allocation was written
and executed successfully.

10
3
EX.NO: 13.3 LINKED FILE
ALLOCATION DATE:

AIM:
To write a C Program to implement Linked File Allocation method.
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:
#include<stdio.h>
#include<conio.h>
struct file
{
char fname[10];
int start,size,block[10];
}f[10];
main()
{
int i,j,n;
printf("Enter no. of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter file name:");
scanf("%s",&f[i].fname);
printf("Enter starting block:");
scanf("%d",&f[i].start);

10
4
f[i].block[0]=f[i].start;
printf("Enter no.of blocks:");
scanf("%d",&f[i].size);
printf("Enter block numbers:");
for(j=1;j<=f[i].size;j++)
{
scanf("%d",&f[i].block[j]);
}
}
printf("File\tstart\tsize\tblock\n")
; for(i=0;i<n;i++)
{
printf("%s\t%d\t%d\t",f[i].fname,f[i].start,f[i].size)
; for(j=1;j<=f[i].size-1;j++)
printf("%d--->",f[i].block[j]);
printf("%d",f[i].block[j])
; printf("\n");
}

10
5
Output

Enter no. of
files:2 Enter file
name:sample
Enter starting
block:20 Enter
no.of blocks:6
Enter block
numbers:4 12
15
45
32
25
Enter file
name:raj Enter
starting block:12
Enter no.of
blocks:5 Enter
block numbers:6
5
4

3
2
File start size block
sample 20 6 4--->12--->15--->45--->32--->25
raj 12 5 6--->5--->4--->3--->2

Result:

Thus the following file allocation technique of Linked File Allocation was
written and executed successfully.

10
6
EX.NO: 14 DISK SCHEDULING

ALGORITHM DATE:

AIM :

To Write C programs to simulate implementation FCFS Disk Scheduling Algorithm

ALGORITHM:

1. Let Request array represents an array storing indexes of tracks


that have been requested in ascending order of their time of arrival. ‘head’ is the
position of disk head.

2. Let us one by one take the tracks in default order and calculate the
absolute distance of the track from the head.

3. Increment the total seek count with this distance.

4. Currently serviced track position now becomes the new head position.

5. Go to step 2 until all tracks in the request array have not been serviced.

PROGRAM:

#include<stdio.h>

#include<conio.h>

#include<math.h>int

main()

int queue[100],t[100],head,seek=0,n,i,j,temp;float avg;

// clrscr();

printf("*** SSTF Disk Scheduling Algorithm ***\n");printf("Enter the size of Queue\

t"); scanf("%d",&n); printf("Enter the Queue\t");for(i=0;i<n;i++)

scanf("%d",&queue[i]);

printf("Enter the initial head

10
7
position\t");scanf("%d",&head); for(i=1;i<n;i+

+) t[i]=abs(head-queue[i]);for(i=0;i<n;i++)

{
for(j=i+1;j<n;j++)

if(t[i]>t[j])

temp=t[i]; t[i]=t[j]; t[j]=temp; temp=queue[i]; queue[i]=queue[j];queue[j]=temp;

for(i=1;i<n-1;i++)

seek=seek+abs(head-queue[i]);head=queue[i];

printf("\nTotal Seek Time is%d\

t",seek); avg=seek/(float)n;

printf("\nAverage Seek Time is

%f\t",avg); return 0;

OUTPUT:

*** SSTF Disk Scheduling Algorithm ***

Enter the size of Queue 5 Enter the Queue 10

17 2 15 4 Enter the initial head position 3

Total Seek Time is14

Average Seek Time is 2.800000

RESULT:

Thus the program was executed and verified successfully.

10
8
EX.NO: 15 LINUX INSTALLATION USING
VMWARE DATE:

AIM:
To install the Linux OS using VMware

Note: If your Linux distribution is not RPM-based, has a custom kernel, or is


unsupported, use the steps below to compile VMware Tools.
To install VMware Tools in a Linux guest operating system using Compiler:

1. Ensure that your Linux virtual machine is powered on.

2. If you are running a GUI interface, open a command shell.

Note: Log in as a root user, or use the sudo command to complete each of these steps.

3. Right Click VM in the virtual machine menu, then click Guest >
Install/Upgrade VMware Tools.
4. Click OK.

Note: In some cases, verify that the CDROM device is Connected from
within the Edit Settings option of the virtual machine.

5. To create a

mount

point, run:

mkdir

/mnt/cdrom

6. To mount the

CDROM, run:

mount

/dev/cdrom

/mnt/cdrom

7. To copy the Compiler gzip tar file to a temporary

local directory, run: cp

/mnt/cdrom/VMwareTools-version.tar.gz /tmp/

Where version is the VMware Tools package

10
9
version.

11
0
8. To determine the version of

VMware tools, run: ls

/mnt/cdrom You see output

similar to:

# VMwareTools-5.0.0-12124.tar.gz

9. To change to the tmp directory and extract the contents of the tar file into
a new directory called vmware-tools-distrib, run:

cd /tmp
tar -zxvf VMwareTools-version.tar.gz

10. To change directory to vmware-tools-distrib and run the


vmware-install.pl PERL script to install VMware Tools,
run:

cd vmware-tools-distrib
./vmware-install.pl

Notes:
● Complete the screen prompts to install the VMware Tools.
Options in square brackets are default choices and can be selected
by pressing Enter.
● To compile VMware Tools successfully, you need gcc
Compiler and Linux Kernel sources provided by your Linux
distribution. Consult your Linux distribution documentation for
details on methods to install these packages.
● It is normal for the console screen to go blank for a short
time during the installation when the display size changes.
● Some warnings or errors are normal, like when a files does not exist.
● Depending on the Linux distribution, your network service might
restart after installation. VMware recommends that you invoke
this command from the console and not remotely.

11. If you are running a GUI interface, restart your X


Window session for any mouse or graphics changes to
take effect.

12. To start VMware Tools running in the background during an


X Window session, using terminal session run the command

/usr/bin/vmware-toolbox &

13. Depending on your environment, you may need to unmount


the CD-ROM. To unmount the CD-ROM, run:

umount /mnt/cdrom

11
1
14. Depending on your environment, you may need to manually end the

11
2
VMware Tools installation. To end the VMware Tools install, click VM
in the virtual machine menu, then click Guest > End VMware Tools
Install.

15. To remove VMware Tools


installation packages, run: cd rm
/tmp/VMwareTools-version.tar.gz rm
-rf /tmp/vmware-tools-distrib

RESULT:

Thus the study exercise for Linux installation using VMware studied
successfully.

11
3

You might also like