OS lab manual_Algorithm
OS lab manual_Algorithm
LAB MANUAL
AIM:
To study and to execute the basic shell commands in UNIX.
Syntax:
$ ln source-filename destination-filename
To create another name for a same file called a link or alias name.
Eg:
$ ln f1 f2 creates another name for f1
5. rm filename(s)
Removes files. Careful with this one - it is irreversible. It is usually aliased ( in a user"s .cshrc
file ) to "rm -i" which insures that "rm" asks you if you are sure that you want to remove the
named file.
Syntax: $ rm filename to remove a file
E.g.: $ rm f1
6. cmp {file1} {file2}
Compares the contents of two files from each other. Reports the first different character found,
and the line number.
Syntax: $ cmp file1 file2
E.g.
To compare doc1 and doc2, having the following data.
Doc1 doc2
This a document This is document
For internal calculation For internal calculation.
$ cmp doc1 doc2
output will be
doc1 and doc 2 differ: byte 6, line1.
7. diff {options}{file1} {file2}
Displays all the differences between two files or directories to the screen.
Options
-b ignores trailing blanks and other strings
-h used for files of unlimited length.
Syntax: $ diff file1 file2
8. comm {options} file1 file2
Displays common lines in the two files
Options
-1 suppresses the display of the first column in the output.
-2 suppresses the display of the second column in the output.
-3 suppresses the display of the third column in the output.
Syntax: $ comm. {-{1}{2}{3}} file1 file2
E.g.:
1. $ comm. emp1 emp2
emp1 emp2
Navneet Ritu
Ritu Rachana
Will produce the following output
Ritu
Rachana
Navneet
2. $ comm. –12 emp1 emp2
the output will be
Ritu
9. uniq {option}{file}
Displays the unique lines.
Options
-u display only the unique lines
-d display only the duplicate lines
-c display all lines, each processed by a count of the records.
Syntax: $ uniq {option}{file name}
Eg
$ uniq emp.dat
-display only the unique lines of the file.
Comman Purpose
d
5.grep
It is used to search and print specified patterns from a file.It is abbreviation of “global regular
expression and print”.
Syntax : $ grep [option] pattern file(s)
Options
-n prints line numbers
-v the reverse search criterion
-c display only a count of matching pattern
6.sort
It is used to sort the contents of a file.
Syntax : $ sort filename
Options available in sort:
Command Purpose
in reverse order
-n Sort numerically
7. nl(no. of lines)
It adds file number to a file and it displays the file and not provides to access to edit.
Syntax : $ nl filename
8. cut
It is used to select the specified fields from a line of text.
Syntax : $ cut {options} filename
Options
c selects columns specified by list
f selects fields specified by list
d field delimiter (default is tab)
9.paste
Merge lines of files.
Syntax : $ paste {options} filename1 filename2
Options
-d delimiters
-s serial (paste one file at a time instead of in parallel)
RESULT:
Thus the basic shell commands have been studied and executed in UNIX.
EX.NO.1.1 UNIX EDITOR
AIM:
To study about the VI editor and perform all editing options
INTRODUCTION
An Editor is a program that allows us to see a portion of a file on the screen and to modify
characters and lines by simply typing at the cursor position. There are a number of editors that
may be included with UNIX system, including ed, ex, vi, EMACS. The latter two use the entire
screen, which is a big advantage, and both are powerful editors. We are focusing on vi because it
is easier and perhaps more importantly it's guaranteed to always be part of UNIX.
THE VI EDITOR
vi stands for visual. Vi is a full screen editor that allows the user to edit the entire document at
the same time. vi has no menus but instead uses combinations of keystrokes in order to
accomplish commands. The vi editor was written in the university of California at Berkeley by
Bill joy, who is one of the co-founder of Sun-Micro systems.
STARTING WITH VI
There are different ways to start vi editor
$vi : opens an empty editor
$vi filename : opens an editor with specified file name
eg.,$ vi myfile
VI MODES
vi has two modes: the command mode and the insert mode.
Command mode:
In this mode, all the keys pressed by the user are interpreted to be editor commands. No text is
displayed on the screen,even if the corresponding key is pressed on keyboard.
Insert mode:
Insert mode permits to insert new text, editing and replacement of existing text. In the insert
mode letters typed in at the keyboard are echoed on the screen.
When the editor is opened it is in command mode. If you want to switch to 'insert mode' press i
to enter the insert mode of vi editor. If you wish to leave insert mode and return to the command
mode, hit the ESC key. If you are not sure which mode you are, hit ESC a couple of times and
that will put you back in command mode.
MOVING THE CURSOR
The cursor movement commands are
Command action
k or - Up one line
t[character] Moves right and places it one character before the specified
characters
T[character] Moves left and places it one character before the specified
character
To do all the above insert commands, first position the cursor appropriately by using cursor
movement commands.
Commands to delete a text from a file
command purpose
#dw Deletes the word from the cursor position to the end of the
word
Before using the above commands the vi editor must be in command mode. To do all the above
delete commands, first position the cursor appropriately by using cursor movement commands.
Commands for undo
vi has powerful undo features. Suppose some changes that has been made to the file has to be
unaffected we use undo options.
command purpose
QUITTING FROM VI
After making all the changes in the document,save the document and quit using ':wq' in
command mode. If we want to quit without saving the changes made,type':q!' in command
mode.
RESULT:
Thus the VI editor has been studied and all the editing options were performed
Ex No:2 PROCESS CREATION USING SYSTEM CALLS
AIM
ALGORITHM
2.A) PROCESS
OUTPUT:
CHILD: My parent is :1
OUTPUT:
PARENT:I am parent:2682
2.C)WAITING PROCESS:
OUTPUT:
2.D)ZOMBIE PROCESS:
OUTPUT:
My ID is 2716
My parent ID is 2716
My ID is 2717
RESULT
Thus the programs using system calls of unix operating system was written and executed
successfully
EX NO.3 SIMULATION OF UNIX COMMANDS
ALGORITHM
Step 1: Start the program
Step 2: Declare the varibles
Step 3: Write programs to use ls,mv,cd commands of unix operating system
Step 4: Execute the program to simulate the unix commands
Step 5: Stop the program
OUTPUT:
]$ cc iosys1.c
]$ ./a.out test.txt
]$ cat test.txt
This will be output to test.txt
]$cc iosys2.c
]$./a.out
This will be output to test.txt
3. b) SIMULATION OF ls COMMAND
OUTPUT
./a.out /home/cse/cse2011/cs045/list
abc.c
even.sh
.io.c.swo
.gnome
.bashrc
3.C) SIMULATION OF cd COMMAND
OUTPUT
./a.out student1
Change directory:student1
OUTPUT
We find that the file abc.c no longer exists. It has been renamed as qq.c
RESULT
Thus the programs to simulate unix command has been executed successfully
SHELL PROGRAMMING
EX.NO: 4.1 AREA AND CIRCUMFERENCE OF CIRCLE
AIM:
To write a shell program for finding the area and circumference of the circle.
ALGORITHM:
Step 1: Start the process.
Step 2: Read the radius r.
Step 3: Calculate area of the circle using the formula, area= Π*r*r
Step 4: Calculate circumference of the circle using the formula circumference= 2*Π*r
Step 5: Print area and circumference of the circle.
Step 6: Stop the process.
OUTPUT :
algin@ubuntu:~/shell$ sh circle.sh
enter the radius
3
area= 27
circumference= 18
RESULT :
Thus the shell program for finding the area and circumference of the circle has been
executed and verified.
EX.NO: 4.2 SWAP TWO NUMBERS
AIM:
To write a shell program to swap two numbers using a temporary variable.
ALGORITHM:
Step 1: Start the process.
Step 2: Read two variables 'a' and 'b'.
Step 3: Print the values of the variable before swapping.
Step 4: Assign 'a' value to temporary variable 'c', 'b' value to 'a' and 'c' value to 'b'.
Step 5: Print the values after swapping.
Step 6: Stop the process.
OUTPUT:
algin@ubuntu:~/shell$ sh swap.sh
enter the two numbers for swapping
23 45
Before swapping
A=23 and B=45
After swapping
A=45 and B=23
RESULT :
Thus the shell program to swap two numbers using a temporary variable has been executed
and verified
EX.NO : 4.3 CALCULATE THE GROSS SALARY
AIM :
To write a Shell program to find the gross salary.
ALGORITHM :
Step 1: Start the process.
Step 2: Read name and salary of the employee.
Step 3: Calculate da=s*47/100.
Step 4: Calculate hra=s*12/100.
Step 5: Calculate cca=s*3/100.
Step 6: Calculate gross=s+hra+cca+da.
Step 7: Print gross salary of the employee.
OUTPUT :
algin@ubuntu:~/shell$ sh gross.sh
Enter the employee name
Algin
enter the basic salary
12413
The gross salary of Algin is 20108
RESULT:
Thus the Shell program to find the gross salary has been executed and verified.
EX.NO : 4.4 GREATEST OF TWO NUMBERS
AIM :
To write a Shell program to find the greatest of two numbers.
ALGORITHM :
Step 1: Start the process.
Step 2: Read two variables 'a' and 'b'.
Step 3: Assign 'a' value to big.
Step 4: Check if(b>big) then assign 'b' value to big and print “big is the greatest”.
Step 5: Stop the process.
OUTPUT:
algin@ubuntu:~/shell$ sh grea_2no.sh
Enter the two numbers
21 79
79 is the greatest
RESULT :
Thus the shell program to find the greatest of two numbers has been executed and
verified.
EX.NO: 4.5 CHECK ADD OR EVEN
AIM :
To write a Shell program to check whether a given number is odd or even.
ALGORITHM :
Step 1: Start the process.
Step 2: Read the input value n.
Step 3: Find n %2 and store the result in r.
Step 4: Check if r=0 then print “ The given no is even” else print “The given no is
odd”.
Step 5: Stop the process.
OUTPUT:
algin@ubuntu:~/shell$ sh odd.sh
Enter a number
4
The given number 4 is even
algin@ubuntu:~/shell$ sh odd.sh
Enter a number
9
The given number 9 is odd
RESULT:
Thus the shell program to check whether a given number is odd or even has been
executed and verified.
EX.NO : 4.6 CHECK POSITIVE , NEGATIVE OR ZERO
AIM :
To write a shell program to check whether a given number is positive, negative or zero.
ALGORITHM :
Step 1: Start the process.
Step 2: Read the input value n.
Step 3: Check if n > 0 then print “The given no is Positive” and go to step 6 else go to 4.
Step 4: Check if n< 0 then print “The given no is Negative” and go to step 6 else go to 5.
Step 5: Print “The given no is Zero”.
Step 6: Stop the process.
OUTPUT :
algin@ubuntu:~/shell$ sh pos_neg_zero.sh
enter a number 68
The given number 68 is a positive number
algin@ubuntu:~/shell$ sh pos_neg_zero.sh
enter a number -21
The given number -21 is a negative number
RESULT :
Thus the shell program to check whether a given number is positive, negative or zero
has been executed and verified
EX.NO.4 .7 BASIC ARITHMETIC OPERATIONS
AIM :
To write a shell program to perform the basic arithmetic operations.
ALGORITHM :
Step 1: Start the process.
Step 2: Read the input numbers 'a' and 'b' and the choice ,
1. Add 2. Subtract 3.Multiply 4.Divide 5. Exit.
Step 3: If choice = 1 then find sum=a+b and print the sum.
Step 4: If choice = 2 then find difference=a-b and print the difference.
Step 5: If choice = 3 then find product=a*b and print the product.
Step 6: If choice = 4 then find quotient=a/b and print the quotient.
Step 7: If choice = 5 then stop the process.
OUTPUT :
algin@ubuntu:~/shell$ sh arithmetic.sh
Enter the two numbers
56
Menu
1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit
Enter your choice:
1
The sum of 5 and 6 is 11
algin@ubuntu:~/shell$ sh arithmetic.sh
Enter the two numbers
23 15
Menu
1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit
Enter your choice:
2
The difference of 23 and 15 is 8
algin@ubuntu:~/shell$ sh arithmetic.sh
Enter the two numbers
20 2
Menu
1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit
Enter your choice:
3
The product of 20 and 2 is 40
algin@ubuntu:~/shell$ sh arithmetic.sh
Enter the two numbers
21 3
Menu
1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit
Enter your choice:
4
The quotient when 21 is divided by 3 is 7
RESULT :
Thus the shell program to perform the basic arithmetic operations has been executed
and verified.
EX.NO.4.8 SUM OF FIRST FIVE NATURAL NUMBER
AIM :
To write shell script to calculate the sum and to print the first five natural numbers.
ALGORITHM:
Step 1: Start the process.
Step 2: Assign sum=0.
Step 3: From 1 to 5 add the numbers with sum.
Step 4: Print the natural numbers from 1 to 5 and print their sum.
Step 5: Stop the process.
OUTPUT :
algin@ubuntu:~/shell$ sh sumn.sh
The first five natural numbers:
1
2
3
4
5
The sum of first 5 natural numbers is 15
RESULT :
Thus the shell program to calculate the sum and to print the first five natural numbers
has been executed and verified.
EX.NO : 4.9 SUM OF ODD NUMBERS UP TO N
AIM :
To write a Shell program to print and to calculate the sum of odd numbers up to n using
until loop.
ALGORITHM :
Step 1: Start the process.
Step 2: Read the input value n.
Step 3: Initialize i value as 1, sum as 0 and j as 0.
Step 4: Do until i>n then go to step 5 else go to step 6.
Step 5: Calculate sum=sum+i, j=j+1, i= i+2 and go to step 4.
Step 6: Print the odd numbers up to n and print sum of them.
Step 7: Stop the process.
OUTPUT :
algin@ubuntu:~/shell$ sh sumodd.sh
Enter the n value : 10
1
3
5
7
9
The sum of the first 5 odd numbers upto 10 is 25
RESULT :
Thus the shell program to print and to calculate the sum of odd numbers up to n using
until loop has been executed and verified.
EX.NO:4.10 SUM OF EVEN NUMBERS UPTO N
AIM :
To write a shell program to print and to calculate the sum of even numbers upto n using
while loop.
ALGORITHM:
Step 1: Start the process.
Step 2: Read the input value n.
Step 3: Initialize i value as 2, sum as 0 and j as 0.
Step 4: Check if i<n then go to step 5 else go to step 6.
Step 5: Calculate sum=sum+i, j=j+1, i= i+2 and go to step 4.
Step 6: Print the even numbers up to n and print sum of them
Step 7: Stop the process.
OUTPUT :
algin@ubuntu:~/shell$ sh sumeven.sh
Enter the n value : 10
2
4
6
8
10
The sum of first 5 even numbers upto 10 is 30
RESULT :
Thus the shell program to print and to calculate the sum of even numbers up to n using
while loop has been executed and verified.
EX.NO: 4.11 FACTORIAL OF A GIVEN NUMBER
AIM :
To write a shell program to find factorial of a given number using while loop.
ALGORITHM :
Step 1: Start the process.
Step 2: Read the input value n.
Step 3: Initialize i value as 1, fact as 1.
Step 4: Check if i<n then go to step 5 else go to step 6.
Step 5: Calculate fact=fact*i and i=i+1 and go to step 4.
Step 6: Print the factorial of given number n.
Step 7: Stop the process.
OUTPUT :
algin@ubuntu:~/shell$ sh fact.sh
Enter a number
5
Factorial value of 5 is 120
RESULT :
Thus the shell program to find factorial of a given number using while loop has been
executed and verified.
EX.NO : 4.12 CHECK ARMSTRONG NUMBER OR NOT
AIM :
To write Shell script to check whether a given number is armstrong or not.
ALGORITHM :
Step 1: Start the process.
Step 2: Read the input value n.
Step 3: Initialize sum as 0 and x as n.
Step 4: Check if n>0 then go to step 5 else go to step 6.
Step 5: Calculate y=n%10, z=y*y*y, sum=sum+z, n=n/10 and go to step 4.
Step 6: Check if x=sum then Print “The given number is Armstrong”
and go to step 7 else print “ The given number is not Armstrong”
and go to step 7.
Step 7: Stop the process.
OUTPUT :
algin@ubuntu:~/shell$ sh arm.sh
enter a number 123
123 is not an armstrong number
algin@ubuntu:~/shell$ sh arm.sh
enter a number 153
153 is an armstrong number
RESULT : Thus the shell program to check whether a given number is Armstrong or not has
been executed and verified.
EX.NO.5 CPU SCHEDULING
5.1. FIRST COME FIRST SERVE SCHEDULING ALGORITHM
AIM
To schedule the process based on FCFS Scheduling algorithm.
ALGORITHM
Step 1: Declare the variables .
Step 2: Get the no of processess.
Step 3: Get the burst times.
Step 4: Calculate turn around time and waiting time
Step 5: Find the average turn around time and waiting time and print them.
Step 6: Stop the program
OUTPUT:
ENTER NO OF PROCESS:5
ENTER PROCESS NAME:p1
p2
p3
p4
p5
ENTER BURST TIME FOR p1:3
ENTER BURST TIME FOR p2:2
ENTER BURST TIME FOR p3:5
ENTER BURST TIME FOR p4:7
ENTER BURST TIME FOR p5:1
ALGORITHM
Step 1: Initialise the variables.
Step 2: Get the no of processes.
Step 3: Get the burst times.
Step 4: Arrange the jobs based on their burst times with the job with the shortest burst
time first.
Step 5: Calculate turn around time and waiting time
Step6: Find the average turn around time and waiting time and print them.
Step 7: Stop the program
OUTPUT:
ENTER NO OF PROCESS:5
ENTER PROCESS NAME:p1
p2
p3
p4
p5
ENTER BURST TIME: p1:4
ENTER BURST TIME: p2:2
ENTER BURST TIME: p3:7
ENTER BURST TIME: p4:1
ENTER BURST TIME: p5:3
PROCESS BURSTTIME WAITING TIME TURNAROUNDTIME:
p4 1 0 1
p2 2 1 3
p5 3 3 6
p1 4 6 10
p3 7 10 17
TOTAL WAITING TIME:20
AVERAGE WAITING TIME:4.000000
Gantt chart:
----------------------------
|p4| p2| p5| p1| p3|
----------------------------
01 3 6 10 17
ALGORITHM
Step1: Initialize the variables.
Step2: Get the no of processes.
Step3: Get their burst times.
Step4: Get their priority.
Step5: Arrange the jobs based on their priority.
Step6: Calculate turn around time and waiting time.
Step7: Find the average turn around time and waiting time and print them.
OUTPUT:
ENTER NO OF PROCESS:5
ENTER PROCESS NAME:p1
p2
p3
p4
p5
ENTER BURST TIME p1:3
ENTER BURST TIME p2:5
ENTER BURST TIME p3:6
ENTER BURST TIME p4:4
ENTER BURST TIME p5:1
ENTER p1 PRIORITY:3
ENTER p2 PRIORITY:1
ENTER p3 PRIORITY:4
ENTER p4 PRIORITY:5
ENTER p5 PRIORITY:2
ALGORITHM
Step 1: Initialise the variables .
Step 2: Get the no of jobs.
Step 3: Get the burst times.
Step 4: Get the time slice.
Step 5: Calculate turn around time and waiting time.
Step 6: Find the average turn around time and waiting time and print them.
OUTPUT
$ ./a.out
RESULT:
Thus the CPU scheduling algorithms are implemented successfully.
EX.NO:6 IMPLEMENT SEMAPHORES
AIM:
To write a C program to implement the semphores.
ALGORITHM
Step 1: Start the program
Step 2: Initialize the variables
Step 3: Create producer that produces item and consumer that consumes item.
Step 4: Execute the program
Step 5: Stop the program
OUTPUT:
c3104068@rmk-desktop:~$ g++ semaphore.c
c3104068@rmk-desktop:~$ ./a.out
1.PRODUCER
2.CONSUMER
3.EXIT
ENTER YOUR CHOICE: 1
producer produces the item1
ENTER YOUR CHOICE:1
producer produces the item2
ENTER YOUR CHOICE:1
producer produces the item3
ENTER YOUR CHOICE:2
consumer consumes item3
ENTER YOUR CHOICE:2
consumer consumes item2
ENTER YOUR CHOICE:2
consumer consumes item1
ENTER YOUR CHOICE:1
producer produces the item1
ENTER YOUR CHOICE:2
consumer consumes item1
ENTER YOUR CHOICE:2
BUFFER IS EMPTY
RESULT:
Thus the semaphore program is executed successfully.
EX.NO:7 IMPLEMENT SHARED MEMORY AND IPC
AIM:
To implement the Shared memory and IPC using C program.
ALGORITHM
Step 1: Start the program
Step 2: Initialize variables
Step 3: Enter the limit for the series
Step 4: Calculate the Fibonacci series.
Step 5: Stop the program
OUTPUT:
c3104068@rmk-desktop:~$ g++ ipc.c
c3104068@rmk-desktop:~$ ./a.out
Parent Process
Fibonacci Series
Enter the limit for the series:8
Child Process
Fibonacci Series is: 0 1 1 2 3 5 8 13
RESULT:
Thus the implementation of the Shared memory and IPC program is executed
successfully.
EX.NO:8 IMPLEMENT BANKERS ALGORITHM FOR DEAD LOCK
AVOIDANCE
AIM:
To implement the Bankers Algorithm for Dead Lock Avoidance
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the number of processes and the process name
Step 4: Enter the number of resources and the resource name
Step 4: Allocate resources to processes
Step 5: Check for deadlock avoidance
Step 6: Display that the system is safe
Step 4: Stop the program
OUTPUT:
c3104068@rmk-desktop:~$ g++ bank.c
c3104068@rmk-desktop:~$ ./a.out
ENTER NO OF PROCESS:5
ENTER PROCESS NAME:
p0
p1
p2
p3
p4
Enter no.of Resources:4
Enter Resources name:
A
B
C
D
Enter Available:1 5 2 0
Enter Allocation:
Enter p0 :0 0 1 2
Enter p1 :1 0 0 0
Enter p2 :1 3 5 4
Enter p3 :0 6 3 2
Enter p4 :0 0 1 4
Enter Maximum:
Enter p0 :0 0 1 2
Enter p1 :1 7 5 0
Enter p2 :2 3 5 6
Enter p3 :0 6 5 2
Enter p4 :0 6 5 6
A B C D
p0: 0 0 0 0
p1: 0 7 5 0
p2: 1 0 0 2
p3: 0 0 2 0
p4: 0 6 4 2
System is Safe
RESULT:
Thus the implementation of Bankers Algorithm for Dead Lock Avoidance is executed
successfully.
EX.NO:9 IMPLEMENT DEADLOCK DETECTION ALGORITHM
AIM:
To implement the Deadlock Detection Algorithm
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the number of processes
Step 4: Enter the number of resources
Step 5: Create allocation vector
Step 6: Create availability vector
Step 7: Identify the process creating deadlock
Step 8: Stop the program
OUTPUT:
INPUT:
enter total no. of processes : 4
enter claim matrix :
01001
00101
00001
10101
enter allocation matrix :
10110
11000
00010
00000
enter resource vector :
21121
enter the availability vector :
00001
OUTPUT :
deadlock causing processes are : 1 2
Result:
Thus the deadlock detection algorithm is implemented successfully.
Ex No 10 MULTITHREADING AND SYNCHRONIZATION
AIM
To write a C program to implement multithreading and synchronization
ALGORITHM
OUTPUT
Worker 0: Doing Job 0
Worker 1: Doing Job 0
Worker 1: Doing Job 1
Worker 0: Doing Job 1
Worker 0: Doing Job 2
Worker 1: Doing Job 2
Worker 0: Doing Job 3
Worker 1: Doing Job 3
RESULT
Thus the C program to for multithreading and thread synchronization was executed
successfully
EX NO 11 MEMORY ALLOCATION
AIM
To write a C program to implement first fit, Worst fit and best fit memory allocation method
A) FIRST-FIT
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the number of blocks and the number of files
Step 4: Enter the size of blocks and the files
Step 5: Use First fit to allocate the memory
Step 6: Stop the program
INPUT
Enter the number of blocks: 3
Enter the number of files: 2
OUTPUT
File No File Size Block No Block Size Fragment
1 1 3 7 6
2 4 1 5 1
B)WORST-FIT
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the number of blocks and the number of files
Step 4: Enter the size of blocks and the files
Step 5: Use Worst fit to allocate the memory
Step 6: Stop the program
INPUT
Enter the number of blocks: 3
Enter the number of files: 2
OUTPUT
File No File Size Block No Block Size Fragment
1 1 1 5 4
2 4 3 7 3
C) BEST-FIT
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the number of blocks and the number of files
Step 4: Enter the size of blocks and the files
Step 5: Use Best fit to allocate the memory
Step 6: Stop the program
INPUT
Enter the number of blocks: 3
Enter the number of files: 2
OUTPUT
File No File Size Block No Block Size Fragment
1 1 2 2 1
2 4 1 5 1
RESULT
Thus the program for First fit,Worst fit and Best fit memory allocation is implemented
successfully
EX.NO.12 IMPLEMENT PAGING TECHNIQUE OF MEMORY MANAGEMENT
AIM:
To write a C program to implement Paging Technique of memory management.
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the number of pages
Step 4: Enter the page size
Step 5: Perform memory management using paging technique
Step 6: Stop the program
INPUT:
Enter how many pages: 5
Enter the page size:4
OUTPUT:
Page1 address: 1894
Page2 address: 1902
Page3 address: 1910
Page4 address: 1912
Page5 address: 1926
RESULT:
Thus the paging is simulated using memory management scheme.
EX.NO:13 IMPLEMENT PAGE REPLACEMENT ALGORITHMS
AIM:
To write C program to implement the Page replacement algorithms.
13 a) FIFO (First In First Out)
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the number of reference and frames
Step 4: Enter the reference string
Step 5: Use FIFO algorithm and calculate number of page fault
Step 6: Stop the program
OUTPUT:
$ cc fifo.c
$ ./a.out
Enter the number of reference:10
Enter the number of frames:3
Enter the reference string:7 0 1 2 0 3 0 4 2 6
FIFO ALGORITHM
7 -1 -1
7 0 -1
7 0 1
2 0 1
no page fault
2 3 1
2 3 0
4 3 0
4 2 0
4 2 6
number of page fault is:9
RESULT:
Thus the implementation of the page replacement algorithm based on FIFO is executed
successfully.
13 B) LRU (LEAST RECENTLY USED)
AIM:
To implement the page replacement algorithm based on LRU.
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the number of reference and frames
Step 4: Enter the reference string
Step 5: Use LRU algorithm and calculate number of page fault
Step 6: Stop the program
OUTPUT
$ cc lru.c
$ ./a.out
Enter the number of reference:10
Enter the number of frames:3
Enter the reference string:7 0 1 2 0 3 0 4 2 6
LRU ALGORITHM
7 -1 -1
7 0 -1
7 0 1
2 0 1
no page fault
2 0 3
no page fault
4 0 3
4 0 2
4 6 2
number of page fault is:8
RESULT:
Thus the implementation of page replacement algorithm based on LRU.
13 C) LFU (LEAST FREQUENTLY USED)
AIM:
To implement the page replacement algorithm based on LFU
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the number of reference and frames
Step 4: Enter the reference string
Step 5: Use LFU algorithm and calculate number of page fault
Step 6: Stop the program
OUTPUT:
$ cc lru.c
$ ./a.out
Enter the number of reference:10
Enter the number of frames:3
Enter the reference string:7 0 1 2 0 3 0 4 2 6
LRU ALGORITHM
7 -1 -1
7 0 -1
7 0 1
2 0 1
no page fault
2 0 3
no page fault
4 0 3
4 0 2
4 6 2
number of page fault is:8
RESULT:
Thus the implementation of the page replacement algorithm based on LRU is executed
successfully.
EX.NO:14 IMPLEMENT ALL FILE ORGANIZATION TECHNIQUES
EX.NO:14 A) SINGLE LEVEL DIRECTORY
AIM:
To implement the file organisation technique using single level directory.
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the number of directories and the files for each directory
Step 4: Display files using single level directory
Step 5: Stop the program
OUTPUT:
Enter the no. of Directories:2
Enter the name of the Directory 1:IIyear
Enter the no.of files in the directory IIyear:3
Enter the file names:
mpmc.txt
os.txt
daa.txt
Enter the name of the Directory 2:IIIyear
Enter the no.of files in the directory IIIyear:3
Enter the file names:
npm.txt
cns.txt
ooad.txt
Directory Structure..
IIyear
mpmc.txt
os.txt
daa.txt
IIIyear
npm.txt
cns.txt
ooad.txt
EX.NO:14 B) TWO LEVEL DIRECTORY
AIM:
To implement the file organisation technique using two level directory.
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the number of directories and the files for each directory
Step 4: Display files using two level directory
Step 5: Stop the program
OUTPUT:
Enter the no. of Directories:2
Enter the name of the Directory 1:IT
Enter the no.of sub directories in the directory IT:2
Enter the details of sub directories:
Enter the name of the Sub Directory 1:IIyear
Enter the no.of files in the Sub Directory IIyear:2
Enter the file names of the Sub Directory IIyear:
a.txt
b.txt
Enter the name of the Sub Directory 1:IIIyear
Enter the no.of files in the Sub Directory IIIyear:1
Enter the file names of the Sub Directory IIIyear:
a.txt
Enter the no.of files in the directory IT:1
Enter the file names:
mark.doc
Enter the name of the Directory 2:CSE
Enter the no.of sub directories in the directory CSE:0
Enter the no.of files in the directory CSE:1
Enter the file names:
staff.doc
Directory Structure..
IT
IIyear
a.txt
b.txt
IIIyear
a.txt
mark.doc
CSE
staff.doc
RESULT:
Thus the implementation of two level directory file organization technique is executed
successfully.
EX.NO:14 C) HIERARCHICAL
AIM:
To implement the file organisation technique using hierarchical level directory.
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the number of directories and the files for each directory
Step 4: Display files using hierarchical level directory
Step 5: Stop the program
OUTPUT:
Enter the no. of Directories:2
Enter the name of the Directory:
it
Enter the no.of sub directories in the directory it:2
Enter the details of sub directories:
Enter the name of the Directory:IIyear
Enter the no.of sub directories in the directory IIyear:2
Enter the details of sub directories:
Enter the name of the Directory:Subject
Enter the no.of sub directories in the directory Subject:0
Enter the no.of files in the directory Subject:5
Enter the file names:
PQT.txt
DAA.txt
OS.txt
MPMC.txt
SE.txt
Enter the name of the Directory:Staff
Enter the no.of sub directories in the directory Staff:0
Enter the no.of files in the directory Staff:1
Enter the file names:
staff.doc
Enter the no.of files in the directory IIyear:1
Enter the file names:
stud.doc
Enter the name of the Directory:IIIyear
Enter the no.of sub directories in the directory IIIyear:2
Enter the details of sub directories:
Enter the name of the Directory:Subject
Enter the no.of sub directories in the directory Subject:0
Enter the no.of files in the directory Subject:6
Enter the file names:
NM.txt
NPM.txt
CNS.txt
ES.txt
OOAD.txt
WT.txt
Enter the name of the Directory:Staff
Enter the no.of sub directories in the directory Staff:0
Enter the no.of files in the directory Staff:1
Enter the file names:
staff.doc
Enter the no.of files in the directory IIIyear:1
Enter the file names:
stud.doc
Enter the no.of files in the directory it:2
Enter the file names:
markII.xls
markIII.xls
Enter the name of the Directory:cse
Enter the no.of sub directories in the directory cse:1
Enter the details of sub directories:
Enter the name of the Directory:Staff
Enter the no.of sub directories in the directory Staff:0
Enter the no.of files in the directory Staff:1
Enter the file names:
staff.doc
Enter the no.of files in the directory cse:1
Enter the file names:
staff.xls
Directory Structure..
it
IIyear
Subject
PQT.txt
DAA.txt
OS.txt
MPMC.txt
SE.txt
Staff
staff.doc
stud.doc
IIIyear
Subject
NM.txt
NPM.txt
CNS.txt
ES.txt
OOAD.txt
WT.txt
Staff
staff.doc
stud.doc
markII.xls
markIII.xls
cse
Staff
staff.doc
staff.xls
RESULT:Thus the implementation of hierarchical level directory file organization technique is
executed successfully.
EX.NO 15 IMPLEMENTATION OF FILE ALLOCATION STRATEGIES
A) SEQUENTIAL ALLOCATION
AIM:
To implement file allocation strategies using sequential allocation
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the starting block and the length of the file
Step 4: Allocate file using sequential allocation
Step 5: Stop the program
OUTPUT
root@rmk-desktop:~/Desktop# ./a.out
Enter the starting block & length of file4
5
4->1
5->1
6->1
7->1
8->1
the file is allocated to disk
if u want to enter more files?(y-1/n-0)1
Enter the starting block & length of file5
2
Block already allocated
if u want to enter more files?(y-1/n-0)1
Enter the starting block & length of file9
10
9->1
10->1
11->1
12->1
13->1
14->1
15->1
16->1
17->1
18->1
the file is allocated to disk
if u want to enter more files?(y-1/n-0)0
RESULT:
Thus the sequential allocation program is executed successfully.
B) INDEXED ALLOCATION
AIM:
To implement file allocation strategies using indexed allocation
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Enter the starting block and the length of the file
Step 4: Allocate file using indexed allocation
Step 5: Stop the program
OUTPUT
enter index block 9
enter no of files on index 3
1
2
3
allocated
file indexed
9->1:1
9->2:1
9->3:1 Enter 1 to enter more files and 0 to exit 1
enter index block 10
enter no of files on index 6
2
3
4
5
6
7
Block already allocatedenter index block 2
Block already allocated
enter index block 10
Block already allocated
enter index block 11
enter no of files on index 2
1
2
Block already allocatedenter index block 11
Block already allocated
enter index block 14
enter no of files on index 2
45
34
allocated
file indexed
14->45:1
14->34:1 Enter 1 to enter more files and 0 to exit
RESULT:
Thus the indexed file allocation program is executed successfully.
CONTENT BEYOND SYLLABUS
MUTIPROGRAMMING VARIABLE TASK
AIM
To program MVT using c programming
ALGORITHM:
Step 1: Declare the necessary variables.
Step 2: Get the memory capacity and number of processes.
Step 3: Get the memory required for each process.
Step 4: If the needed memory is available for the particular process it will be allocated and
the remaining memory availability will be calculated.
Step 5: If not it has to tell no further memory remaining and the process will not be allocated
with memory.
Step 6: Then the external fragmentation of each process must be calculated.
INPUT
Enter the memory capacity: 80
Enter no of processes: 2
Enter memory req for process1: 23
OUTPUT:
The memory allocated for process1 is: 80
Remaining memory is: 57
External fragmentation for this process is: 57
Enter memory req for process2: 52
The memory allocated for process2 is: 57
Remaining memory is: 5
External fragmentation for this process is: 5
RESULT
Thus the program Multiprogramming variable task has been executed successfully.