0% found this document useful (0 votes)
8 views119 pages

CS3461_OS_Labmanual

The document is a lab manual for the Operating Systems Laboratory course at Saranathan College of Engineering for the academic year 2023-2024. It includes a list of experiments covering various topics such as Windows installation, UNIX commands, process management, CPU scheduling algorithms, and file organization techniques. Each experiment provides aims, procedures, and expected results for hands-on learning in operating systems.

Uploaded by

aiml261251
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views119 pages

CS3461_OS_Labmanual

The document is a lab manual for the Operating Systems Laboratory course at Saranathan College of Engineering for the academic year 2023-2024. It includes a list of experiments covering various topics such as Windows installation, UNIX commands, process management, CPU scheduling algorithms, and file organization techniques. Each experiment provides aims, procedures, and expected results for hands-on learning in operating systems.

Uploaded by

aiml261251
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 119

SARANATHAN COLLEGE OF ENGINEERING

Venkateswara Nagar, Panjappur, Tiruchirapalli-620012

CS3461
OPERATING SYSTEMS LABORATORY

LAB MANUAL

Academic Year
ODD SEMESTER 2023-2024

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


CS3461 - OPERATING SYSTEMS LABORATORY

LIST OF EXPERIMENTS

1. Installation of windows operating system

2. Illustrate UNIX commands and Shell Programming

3. Process Management using System Calls: Fork, Exit, Getpid, Wait, Close

4. Write C programs to implement the various CPU Scheduling Algorithms

5. Illustrate the inter process communication strategy

6. Implement mutual exclusion by Semaphore

7. Write C programs to avoid Deadlock using Banker’s Algorithm

8. Write a C program to Implement Deadlock Detection Algorithm

9. Write C program to implement Threading

10. Implement the paging Technique using C program

11. Write C programs to implement the following Memory Allocation Methods

a. First Fit b. Worst Fit c. Best Fit

12. Write C programs to implement the various Page Replacement Algorithms

13. Write C programs to Implement the various File Organization Techniques

14. Implement the following File Allocation Strategies using C programs

a. Sequential b. Indexed c. Linked

15. Write C programs for the implementation of various disk scheduling algorithms

16. Install any guest operating system like Linux using VMware.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex.No : 1 INSTALLATION OF WINDOWS OPERATING SYSTEM

AIM:

To install the windows operating system.


WINDOWS INSTALLATION REPORT:
HOW TO MAKE USB BOOTABLE USING RUFUS

Make sure that you are using USB Drive that is at least 4GB for the 32-bit version and
8GB for 64-bit version.
Rufus is one of several programs that allow you to create an ‘ISO Image’ on USB drive
To create a bootable USB using Rufus, all we need is:
• ISO of our choice Eg.Windows 10
• Any version of rufus
• A spare USB drive (an 8GB USB should be plenty for Windows
10 but make sure you have one that's large enough for the ISO
you're using)
DOWNLOADING WINDOWS ISO

STEP 1:Navigate to http://www.microsoft.com/en-us/software- download/windows 10


site choose the Download tool now button.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


STEP 2: (a) Run the Media Creation Tool.exe. to upgrade or download Windows 10.

STEP 3: At the next screen, choose Create Installation media for another PC & Next.
Important Notes
STEP 1: In order to perform a clean installation of Windows 10, you must own a valid
Windows 10 product key to activate windows.
STEP 2: If you bought a pre-installed Windows 10 computer (on which the OS installed
from the computer manufacturer), then the product key is in BIOS and it will be retrieved
automatically (from BIOS) during Windows installation.
STEP 3: If you're currently running Windows 8.1 or Windows 7 SP1 (already activated),
and you want to upgrade your computer to Windows 10* select "Upgrade this PC now" at
the next screen & then follow the onscreen instruction to upgrade your OS to Windows
10.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


STEP 4: Choose the Windows 10 Edition that you want to download and click Next.
STEP 5: Make sure that you have selected the correct installation media to create and OK.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


STEP 6: At the next screen choose the option ISO file and click Next.
Important Notes
1. By selecting ISO file, you will be able to store Windows 10 on your
computer for later usage or to burn a bootable Windows 10 DVD after Windows
10 ISO download is completed.
2. If you want to create a Windows 10 USB installation media select
USB flash drive and then follow the instructions on this post: How to create a
bootable Windows 10 USBdisk.

STEP 7: Choose the destination location (where the ISO file will be saved/stored) & press
Save.

STEP 8: When the Windows 10 ISO download is completed then:


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
1. Click Open DVD burner and place a blank DVD disk on the
DVRW tray in order to create immediately a bootable Windows 10 DVD
installation/repair disk, or
2. Click Finish.

RESULT:

Thus the installation of windows operating system has been done successfully.
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
EX.NO: 2 BASIC UNIX COMMANDS
Aim:
To study and execute UNIX commands.

Login:
Type telnet server IP address in run window. Users must authenticate themselves by providing a username
and password. Once verified, a greeting and $ prompt appear. The shell is now ready to receive commands
from the user. Options are suffixed with a hyphen (-), and arguments are separated by space.

General Commands:

1. date:

Description: It is used to check the date and time.

Syntax: $ date

Example:$date
Output:

Sat Mar 09

10:17:27

IST 2024

Formats:

1. date +%m

Description: Displays the month.

Syntax: $ date +%m

Example:$date+%m
Output: 03

2. date +%y

Description: It is used to print the last two digits of the year.

Syntax: $ date +%y

Example:$date+%y
Output: 24

3. date +%d

Description: Displays the day of the month.

Syntax: $ date +%d

Example:$date+%d
Output: 09

4. date +%h

Description: Displays the name of the month.

Syntax: $ date +%h

Example:$date+%h
Output: Mar
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
5. date +%H

Description: Displays the hour.

Syntax: $ date +%H

Example: $ date +%H

6. date +%M

Description: Displays the minute.

Syntax: $ date +%M

Example:$date+%M
Output: 17

7. date +%S

Description: Displays the second.

Syntax: $ date +%S

Example:$date+%S
Output: 27

2) cal

• Description: It is used to display the calendar.

• Syntax: $ cal

• Example:$cal
Output: Displays the current month's calendar.

(i) cal month year

• Description: Displays the calendar for the specified month and year.

• Syntax: $ cal <month> <year>

• Example:$cal52024
Output: Displays May 2024 calendar.

3) echo

• Description: It is used to print a message on the screen.

• Syntax: $ echo

• Example:$echo"HelloWorld"
Output: Hello World

4) LS-It is used to list the files and the files are kept in a directory

syntax: $ 18

Example: $ 18

os File Files

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


5) LP- It is used to take printouts

syntax: $ Lp filename

6) who- who displays the data about all the users who have logged into the system currently

Syntax $ who

Example: $ who

Lists the users login details

7) who am i - who am i displays the current user only.

syntax :$ who am i

Example: $ who am i

251046 Pts/17 2024-03-09 10:12 (V-lab2 - 39)

(8) uptime- uptime tells how long the computer has been sunning since its last reboot power off

Syntax: $ uptime

Example: $ uptime

10:21:53 up 169 days, 22:56, 25 users, load average: 1.00, 0.42, 0.15

9) hostname- hostname displays and set system host name

syntax: $ hostname

Example:$ hostname

telnet sce.com.

10) uname - uname displays the system information such as hardware platform, system name and
Processor OS type

syntax $ uname

Example: $ uname

Linux

11 bc- best calculator

press ctrl+d to quit

syntax :$ bc

Example: $ bc

15+2

17

sqrt (25)

for (i=0; 1<3; i++)

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


0

12) clear- It clears the terminal screen

syntax :$ clear

(13) history- It prints the command history in the current active session

syntax: & history

Example: & history

1. date

2. date +%m

3. date +%y

14) man- It is an interface to work with online reference manual

syntax :$ man

Example: $ man cal

Displays description of calender.

15)find-It is used to find directories and file.

Syntax:$ find filename/directoryname

$find ex1/sce

Example: $ find ex1

16) Pwd -If is used to find out what directory you are working with

syntax $ pwd

Example:

1) $ pwd

/name/SCE/251046

2) $ cd ex2

$ pwd

/name/SCE/251046/ex2

17) id user identity

syntax: $ id

Example: $ id

vid=16784259(251046) gid=16777220 (domain users)

groups = 16777220 (domain users), 16777217 (BUILTIN\users)


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
18) last shows the history of loggings into the System

Syntax: $ Last

File Manipulation commands

1) cat- create, view and concatenate files

i) cat> filename - To create a file with some contents

Syntax: $ cat > filename

Example: $ cat > ex1

Hello world

File has the contents stored

$18

Ex1

ii) cat filename -Displays the file contents.

Syntax: $ cat filename

Example: $ cat exi

Hello world

iii) cat >> filename -used to append contents to a file.

Syntax: $ cat >> filename

Example: $ cat >> exl

Linux is open source software

ctrl +d

content appended to the file.

$cat ex1

Hello world

Linux is open source Software

(2) grep- Used to search a related to that file particular word or pattern related to that file,

syntax: $ grep searchword filename

Example: $ grep Hello ex1

Hello

3) touch- It is used to create a blank file

syntax: $ touch filename


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Example: $ touch ex2

4) cp-copy the files or directories

syntax: $ cp source filename destinationfilename

Example:

$cp ex1 ex2

$ cat ex 2

Hello world

Linux is open source software

5) Cut- It cuts or pickup a given number of characters or fields of the file

i) cut -c filename It is used for cutting columns

syntax: $ cut - filename

Example: $ cut -ci ex2

prints the first character of each line.

ii) cut -f filename It is used for cutting fields

syntax: $ cut -f filename

6) mv- Rename the filename or directory

syntax: $ mv ddfilename Newfilename

Example $ mv ex1 ex4

$ cat ex1

No such file or directory

$ cat ex4

Hello world

Linux is open source software

7) head- Displays top 10 lines of a given file

Syntax: $ head filename

Example: $ head ex2

Prints first 10 lines of file ex2

Syntax: $head -5 filename -> prints first 5 lines,

8) tail- Displays bottom to lines of a file

syntax: $ tail filename

Example: $ tail ex 2

Prints last 10 lines of file ex2

syntax: $ tail -5 filename->prints last 5 lines.


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
9) chmod-It is used to change the permission of the file or directory.

Syntax: $chmod category operation permissionfile

10) wc- It counts the number of lines, words and characters in a file

syntax: $ wc filename

Example:

cat > csea

Hell

welcome

to

oslab

$ wc csea

5 5 24 csea

i)$wc -c csea

24 csea

ii) $ wc -w csea

5 csea

iii) $ wc -l ese

5 csea

11)rm- Deletes the directory from the filesystem.

Syntax: $ rm filename

Example: $ rm csea

Removed csea file

Directory command:

1)mkdir- It is used to create a directory.

syntax: $ mkdir directoryname

Example: $ mkdir sce

A directory created.

2) cd - It is used to change the directories.

syntax: $ cd directoryname

Example: $ cd sce

Directory changes to sce

3) rmdir -It is used to remove directory when it is empty.

Syntax: $ rmdir directory name

Example: $ rmdir Sce


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
RESULT:

Thus, all the basic UNIX commands are executed.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex No-3a BASIC SHELL PROGRAMMING

AIM:

To execute basic shell programming.

//SWAPPING OF TWO NUMBERS

ALGORITHM:

STEP 1: Start the program.

STEP 2: Read the value of a,b.

STEP 3: Calculate the swapping of two values by using a temporary variable temp.

STEP 4: Print the value of a and b.

PROGRAM:

echo "Enter two numbers to swap : "

read a

read b

temp=$a

a=$b

b=$temp

echo "After swapping "

echo $a

echo $b

[******@telnet ~]$ sh swap.sh

Enter two numbers to swap :

After swapping

//ARITHMETIC FUNCTION

ALGORITHM:

STEP 1: Start the program.

STEP 2: Read the value of a,b.


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
STEP 3: Perform the arithmetic operations such as +,-,*,/ ,%.

STEP 4: Display the result.

PROGRAM:

echo "Enter 1st num: "

read a

echo "Enter 2nd num: "

read b

c=`expr $a + $b`

echo "Sum: $c"

c=`expr $a - $b`

echo "Diff: $c"

c=`expr $a \* $b`

echo "Mul: $c"

c=`expr $a / $b`

echo "Div: $c"

c=`expr $a % $b`

echo "modulus: $c"

[******@telnet ~]$ sh arith.sh

Enter 1st num:

Enter 2nd num:

Sum: 12

Diff: -2

Mul: 35

Div: 0

modulus: 5

//AREA AND CIRCUMFERENCE

ALGORITHM:

STEP 1: Start the program.

STEP 2: Read the value of radius.

STEP 3: Calculate the circumference using the formula=2*pi*radius

STEP 4: Print the area and circumference.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


PROGRAM:

echo "Enter radius: "

read r

a=`expr "scale=2; $r * $r * 3.14"|bc`

echo "area: $a"

c=`expr "scale=2;$r * 2 * 3.14"|bc`

echo "circumference: $c"

[******@telnet ~]$ sh area.sh

Enter radius:

area:78.50

circumference: 31.40

//TEMPERATURE CONVERSION

ALGORITHM:

STEP 1: Start the program.

STEP 2: Read the Fahrenheit temperature.

STEP 3: Compute conversion for Fahrenheit to centigrade using (5/9)*($F-32)

STEP 4: Print the centigrade in temperature.

STEP 5: Read the centigrade to convert it to Fahrenheit using((9/5)*$c)+32

STEP 6: Print the result.

PROGRAM:

echo "Enter celsius temp:"

read c

f=`echo $c \* 1.8 +32 |bc`

echo "Fahrenheit temp : $f"

[******@telnet ~]$ sh temp.sh

Enter celsius temp:

45

Fahrenheit temp : 113.0

RESULT:

Thus, basic programs using shell program has been executed successfully.
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Ex No-3b SHELL PROGRAMMING

CONDITIONAL STATEMENTS

AIM:

To execute shell programming using conditional statements.

//ODD OR EVEN

ALGORITHM:

STEP 1: Start the program.

STEP 2: Read the number.

STEP 3: If number is divisible by 2 print “It is even”

STEP 4: Else print “It is odd”.

STEP 4: Display the result.

PROGRAM:

echo "Enter a num:"

read n

if [ `expr $n % 2` -eq 0 ]

then

echo $n "is even"

else

echo $n "is odd"

fi

[******@telnet ~]$ sh oddoreven.sh

Enter a num:

5 is odd

//BIGGEST OF THREE NUMBERS

ALGORITHM:

STEP 1: Start the program.

STEP 2: Read the value of a,b and c.

STEP 3: Check the condition.


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
STEP 4: Print the greatest value.

PROGRAM:

echo "Enter any 3 numbers:"

read x

read y

read z

if [ $x -gt $y -a $x -gt $z ]

then

echo $x "is greatest"

else

if [ $y -gt $z -a $y -gt $x ]

then

echo $y "is greatest"

fi

if [ $z -gt $y -a $z -gt $x ]

then

echo $z "is greatest"

fi

fi

[******@telnet ~]$ sh big3.sh

Enter any 3 numbers:

45

23

12

45 is greatest

//STUDENT GRADE

ALGORITHM:

STEP 1: Start the program.

STEP 2: Read the mark.

STEP 3: Check the condition.

STEP 4: Display the result.

PROGRAM:

echo "Student's Grade"


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
echo "Enter name"

read name

echo "Enter the mark"

read mark

if [ $mark -gt 90 -a $mark -lt 100 ]

then

echo "O grade"

fi

if [ $mark -gt 80 -a $mark -lt 90 ]

then

echo "A+ grade"

fi

if [ $mark -gt 70 -a $mark -lt 80 ]

then

echo "A grade"

fi

if [ $mark -gt 60 -a $mark -lt 70 ]

then

echo "B+ grade"

fi

if [ $mark -gt 50 -a $mark -lt 60 ]

then

echo "B grade"

fi

if [ $mark -gt 40 -a $mark -lt 50 ]

then

echo "C grade"

fi

if [ $mark -lt 40 ]

then

echo "ReAppear"

fi

[******@telnet ~]$ sh student.sh

Student's Grade
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Enter name

selena

Enter the mark

87

A+ grade

//LEAP YEAR OR NOT

ALGORITHM:

STEP 1: Read the value of year.

STEP 2: Check the condition if it is divisible by 4 and equal to zero or not.

STEP 3: Display it is “leap year” else “Not a Leap year”.

PROGRAM:

echo "Leap Year"

echo "Enter a year:"

read y

if [ `expr $y % 4 ` -eq 0 ]

then

echo $y "is leap year"

else

echo $y "is not leap year"

fi

[******@telnet ~]$ sh leap.sh

Leap Year

Enter a year:

2020

2020 is leap year

RESULT:
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Thus, the conditional statements using shell program has been executed successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex No-3c SHELL PROGRAMMING

LOOPING STATEMENTS

AIM:

To execute Shell programming using looping statements.

//FACTORIAL

ALGORITHM:

STEP 1: Start the program.

STEP 2: Read the value of n.

STEP 3: Initialize fact=1

STEP 4: Repeat step5 th through 7 until i=n

STEP 5: Compute fact=fact*i.

STEP 6: Increment i=i+1

STEP 7: Print fact value.

PROGRAM:

echo "factorial"

echo "echo n:"

read n

f=1

for (( i=n ; i>0 ; i--))

do

f=`expr $f \* $i`

done

echo "factorial $n = $f"

Output:

[******@telnet ~]$ sh fact.sh

factorial

echo n:

factorial 5 = 120

//FIBONACCI SEQUENCE
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
ALGORITHM:

STEP 1: Start the program.

STEP 2: Read the number for terms as n.

STEP 3: Intitalize 0 to a, 1 to b, 3 to i

STEP 4: Print the initial Fibonacci terms a,b.

STEP 5: Generate the next term using c=a+b

STEP 6: Print the value of c.

STEP 7: Increment I by 1.

STEP 8: Assign b to a and c to b.

STEP 9: Repeat the steps 5 to 9 until i less than or equal to n.

PROGRAM:

echo "Enter limit"

read n

f1=0

f2=1

temp=0

echo "The fibonacci sequence is"

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

do

echo $f1

temp=$f2

f2=`expr $f1 + $f2`

f1=$temp

done

Output:

[******@telnet ~]$ sh fibo.sh

Enter limit

The fibonacci sequence is

2
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
3

//ARMSTRONG NUMBER

ALGORITHM:

STEP1:Read the number as n.


STEP 2: Initialize 0 to num and n to temp.
STEP 3: Using a while loop, check if the given number is greater than 0.
STEP 4: Extract the last digit by computing the number’s modulo 10.
STEP 5: Cube the last digit and add it to sum.
STEP 6: Divide the number by 10.
STEP 7: Repeat STEP 4 to STEP 6 until the number becomes 0.
STEP 8: If sum = temp, then print “Armstrong number”, else print “Not an Armstrong number”.

PROGRAM:

echo "Armstrong number"

echo "Enter number:"

read num

n=$num

while [ $num -gt 0 ]

do

dig=`expr $num % 10`

val=`expr $val + $dig \* $dig \* $dig`

num=`expr $num / 10`

done

if [ $n -eq $val ]

then

echo "$n is an armstrong number"

else

echo "$n is not an armstrong number"

fi

Output:

[******@telnet ~]$ sh armstrong.sh


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Armstrong number

Enter number:

153

153 is an armstrong number

[******@telnet ~]$ sh armstrong.sh

Armstrong number

Enter number:

234

234 is not an armstrong number

//MULTIPLICATION TABLE

ALGORITHM:

STEP 1: Read the input number n.


STEP 2: If i ≤ 10, then compute a = n * i.
STEP 3: Print the value of a and i * n in multiplication table format.
STEP 4: Increment the value of i.

PROGRAM:

echo "Multiplication table"

echo "Enter n:"

read n

for ((i=1;i<=10;i++))

do

val=`expr $n \* $i`

echo "$i * $n = $val"

done

Output:

[******@telnet ~]$ sh mul.sh

Multiplication table

Enter n:

1*7=7

2 * 7 = 14

3 * 7 = 21
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
4 * 7 = 28

5 * 7 = 35

6 * 7 = 42

7 * 7 = 49

8 * 7 = 56

9 * 7 = 63

10 * 7 = 70

RESULT:

Thus, the looping statements using shell program has been executed successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex No-4a FORK SYSTEM CALL

AIM:

ALGORITHM:

STEP 1: Start the algorithm.


STEP 2: Include the header file.
STEP 3: Create a new child process using the fork() system call.
STEP 4: If the return value of fork is equal to -1, display an error message.
STEP 5: If the return value of fork is equal to 0, display it as a child process and print the child ID and
parent ID using the getpid() and getppid() system calls.
STEP 6: If the return value of fork is not equal to 0, display it as the parent process and print the
parent ID using the getpid() system call.
STEP 7: Print the corresponding result.

PROGRAM:

#include<stdio.h>

#include<unistd.h>

void main(void)

int childpid;

childpid=fork();

printf("\n%d",childpid);

if(childpid==-1)

printf("\n Can't fork.\n");

exit(0);

else if(childpid ==0)

{/*child process*/

printf("\n Child:Child pid = %d,Parent pid = %d\m",getpid(),getppid());

exit(0);

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


else

{/*Parent process*/

printf("\n Parent:child pid=%d,parent pid=%d\n",childpid,getpid());

printf("Hai\n");

exit(0);

Output:

[******@telnet ~]$ ./forkop.out

14233

Parent:child pid=14233,parent pid=14232

Hai

Child:Child pid = 14233,Parent pid = 14232

RESULT:

Thus, the Fork System call using C Program is done and the output is verified successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex No-4b Execute System Call

AIM:

To implement the program for executing system calls.

ALGORITHM:

STEP 1: Start the algorithm.


STEP 2: Get the command from the user.
STEP 3: Check the process ID value is equal to zero after creating a child process using the fork()
system call.
STEP 4: If it is equal to zero, print the command for using execl() system call:

excel("/bin/date", "date", 0);

STEP 5: Else, print "the file is not in existence."


STEP 6: The parent waits for the child process to complete with the wait() system call:

cid = wait(&status)

STEP 7: When the child process completes, the parent process resumes from the call to wait() where
it completes.

PROGRAM:

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <sys/types.h>

int main()

pid_t Pid;

switch(Pid=fork())

case -1:

printf("Fork failed");

exit(-1);

case 0:

printf("Child process\n");

execl("/bin/date","date",0);
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
exit(0);

default:

wait(NULL);

printf("Child Terminated \n");

exit(0);

Output:

[******@telnet ~]$ cc execute.c -o executeop.out

[******@telnet ~]$ ./executeop.out

Child process

Tue Mar 7 15:43:37 IST 2023

Child Terminated

Wait System Call

------------------------------------

#include<stdio.h>

#include<stdlib.h>

#include<unistd.h>

#include<sys/types.h>

#include<sys/wait.h>

int main()

int i,status;

pid_t pid;

pid =fork();

if(pid < 0)

printf(" \n process creation failure\n");

exit(-1);

else if(pid>0)

wait(NULL);

printf("\n Parent Starts \n Even no's:");


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
for(i=2;i<=10;i+=2)

printf("%3d",i);

printf("\n Parent ends \n");

else if(pid==0)

printf("Child starts \n Odd no's:");

for(i=1;i<10;i+=2)

printf("%3d",i);

printf("\n Child ends\n");

return 0;

Output:

[******@telnet ~]$ cc wait.c -o waitop.out

[******@telnet ~]$ ./waitop.out

Child starts

Odd no's: 1 3 5 7 9

Child ends

Parent Starts

Even no's: 2 4 6 8 10

Parent ends

RESULT:

Thus, the wait System call is done and the output is verified successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex No-4c GET PID AND CLOSE SYSTEM CALL

AIM:

To implement shell program for getpid and close system call.

ALGORITHM:

STEP 1: Declare the variables pid, parent_pid, child_id, and grand_child_id.


STEP 2: Get the child ID value using the system call fork().
STEP 3: If the child ID value is less than zero, print "Error at fork() child."
STEP 4: If the child ID is 0, then, using getpid() system call, get the process ID.
STEP 5: Print "I am parent" and print all process IDs.
STEP 6: Get the grandchild ID value using the system call fork().
STEP 7: If the grandchild ID value is less than zero, print "Error at fork() grandchild."
STEP 8: If the grandchild ID is not 0, then, using getpid() system call, get the process ID.
STEP 9: Assign the value of pid to my_pid.
STEP 10: Print "I am child" and print the value of my_pid.
STEP 11: Get my parent process ID value using the system call getppid().
STEP 12: Print "My parent's process ID" and its value.
STEP 13: Else, print "I am grandchild."
STEP 14: Get the grandchild's process ID using getpid() and print it as "My process ID."
STEP 15: Get the grandchild's parent process ID using getppid() and print it as "My parent's process ID."

PROGRAM:

#include <stdio.h>

#include <sys/types.h>

int main(void)

if((fork())<0)

printf("Process is not obtained");

exit(1);

else

int pid_t=getpid();

printf("Process id is :%d",pid_t);

sleep(1);
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
exit(0);

return 0;

Output:

[******@telnet ~]$ cc pid.c -o pidop.out

[******@telnet ~]$ ./pidop.out

Process id is :14121

[******@telnet ~]$ Process id is :14122

RESULT:

Thus, the getpid and exit System call algorithm has done and the output is verified successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex No-5a FCFS SCHEDULING ALGORITHM

AIM:

To implement Unix C program for FCFS scheduling algorithm.

ALGORITHM:

STEP 1: Initialize necessary variables.


STEP 2: Get the number of processes in a variable n.
STEP 3: Initialize wait[0] = 0, tw = 0, and ttq = 0.
STEP 4: Get the CPU burst time of n processes using looping statements.
STEP 5: Assign tt[0] = cpu[0].
STEP 6: Execute the following calculations till the loop condition is true:

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

wait[i] = wait[i-1] + cpu[i-1];

tt[i] = cpu[i] + wait[i];

STEP 7: Execute the following calculation till the loop condition is true:

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

tw = tw + wait[i];

ttq = ttq + tt[i];

STEP 8: Calculate average waiting time and average turn-around time:

avgw = tw / n;

avgtt = ttq / n;

STEP 9: Print the value of all process IDs, CPU burst time, waiting time, and turn-around time as in
the execution order of processes.
STEP 10: Print total waiting time, total turn-around time, average waiting time, and average turn-
around time.

PROGRAM:

#include <stdio.h>

int main()

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


int n,b[10],t=0,i,w=0,r=0,a=0;

float avg_wt,avg_tt;

printf("\n=============================================\n");

printf("\t\t CPU Scheduling \n\t\t First Come First Serve(FIFO)");

printf("\n=============================================\n");

printf("Enter the number of processes");

scanf("%d",&n);

printf("\n Enter burst time \n");

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

printf("P%d\t",i);

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

printf("\n=============================================\n");

printf("Process \t Burst \t Waiting \t \t TurnAround \n");

printf("\n=============================================\n");

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

t=t+w;

r=r+b[i];

printf("P%d \t\t %d\t\t %d\t\t %d\t\t\n",i,b[i],w,r);

w=w+b[i];

a=a+r;

printf("\n=============================================\n");

avg_wt=(float)t/n;

avg_tt=(float)a/n;

printf("\n Average waiting time is %2f",avg_wt);

printf("\n\n Average TurnAround time %.2f\n",avg_tt);

return 1;

Output:

[******@telnet ~]$ cc fcfs.c -o fcfsop.out


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
[******@telnet ~]$ ./fcfsop.out

=============================================

CPU Scheduling

First Come First Serve(FIFO)

=============================================

Enter the number of processes4

Enter burst time

P1 2

P2 1

P3 8

P4 4

=============================================

Process Burst Waiting TurnAround

=============================================

P1 2 0 2

P2 1 2 3

P3 8 3 11

P4 4 11 15

=============================================

Average waiting time is 4.000000

Average TurnAround time 7.75

RESULT:

Thus, FCFS Scheduling is done and the output is verified successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex No-5b SJF(NON-PREEMPTION) SCHEDULING ALGORITHM

AIM:

To implement Unix C program for SJF (Non pre-emption) scheduling algorithm.

ALGORITHM:

STEP 1: Initialise necessary variables.

STEP 2: Get the number of process in a variable”n”.

STEP 3: Get the CPU burst time of n processes using looping statement .

STEP 4: Arranged the process ID and CPU bus time based on ascending order.

STEP 5: Initialize wait[0]=0,tt[0x=cpu[0v,tw=0 and tta=0.

STEP 6: Execute the following calculation till the loop condition is true

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

Wait[i]=wait[i-1]+cput[i-1];

tt[i]=cpu[i]+wait[i];

STEP 7: Execute the following calculation till the loop condition is true

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

PROGRAM:

#include <stdio.h>

int main()

int n,w[100],tot[100],i,j,awt,atot;

float avwt,avtot;

struct {

int p,bt;

}sjf[10],temp;

printf("========================================================\n");

printf("\t\t CPU Scheduling \n\n\t\t Shortest Job Scheduling");

printf("\n========================================================\n");

printf("\n Enter the no of processes");

scanf("%d",&n);

printf("\n Enter the burst time :\n");


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
for(i=1;i<=n;i++)

printf("p%d : ",i);

scanf("%d",&sjf[i].bt);

sjf[i].p=i;

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

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

if(sjf[j].bt > sjf[i].bt)

temp=sjf[i];

sjf[i]=sjf[j];

sjf[j]=temp;

w[1]=0;

tot[1]=sjf[1].bt;

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

tot[i]=tot[i-1]+sjf[i].bt;

awt=0;

atot=0;

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

w[i]=tot[i]-sjf[i].bt;

awt+=w[i];

atot+=tot[i];

avwt=(float)awt/n;

avtot=(float)atot/n;
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
printf("\n\n========================================================\n");

printf("\t Process \t\t Waiting \t\t Turnaround\n");

printf("\n\n============================================================\n");

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

printf("\n\t%d\t\t%d\t\t%d",sjf[i].p,w[i],tot[i]);

printf("\n=======================================================\n");

printf("\n\n Total waiting time :%d ms",awt);

printf("\n\n Total Turnaround time: %d ms",atot);

printf("\n\n Average waiting time: %.2f ms",avwt);

printf("\n\n Average Turnaround time: %.2f ms",avtot);

return 0;

Output:

[******@telnet ~]$ cc sjf.c -o sjfop.out

[******@telnet ~]$ ./sjfop.out

========================================================================

CPU Scheduling

Shortest Job Scheduling

========================================================================

Enter the no of processes4

Enter the burst time :

p1 : 2

p2 : 1

p3 : 8

p4 : 4

========================================================================

Process Waiting Turnaround

========================================================================

2 0 1

1 1 3

4 3 7

3 7 15
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
========================================================================

Total waiting time :11 ms

Total Turnaround time: 26 ms

Average waiting time: 2.75 ms

Average Turnaround time: 6.50 ms

RESULT:

Thus, SJF Scheduling is done and the output is verified successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex No-5c PRIORITY SCHEDULING ALGORITHM

AIM:

To implement Unix C program for Priority scheduling algorithm.

ALGORITHM:

STEP 1: Initialize necessary variables.

STEP 2: Get the number of processes, stored in a variable n.

STEP 3: Retrieve the CPU burst time and priority for n processes using looping statements.

STEP 4: Arrange the process IDs, CPU burst times, and priorities in ascending order based on priority.

STEP 5: Initialize wait[0] = 0, tt[0] = cpu[0], and set twt = 0 and tta = 0.

STEP 6: Use a loop to calculate the waiting and turnaround times:

• For each process i (from 1 to n-1), update:

o wait[i] = wait[i-1] + cpu[i-1]

o tt[i] = cpu[i] + wait[i]

STEP 7: Calculate the total waiting time (twt) and total turnaround time (tta):

• Use a loop to iterate through all processes (i = 0 to n-1):

o twt = twt + wait[i]

o tta = tta + tt[i]

STEP 8: Compute the average waiting time and average turnaround time:

• avgwt = twt / n

• avgtt = tta / n

STEP 9: Print the process ID, priority, CPU burst time, waiting time, and turnaround time in the
execution order.

STEP 10: Print the total waiting time, total turnaround time, average waiting time, and average
turnaround time.

PROGRAM:

#include <stdio.h>

int main()

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


int n,temp=0,w[20],b[20],p[20],t2[20],j;

int t1,d[20],i,te=0,b1[20],t3=0;

float t,r; w[1]=0;

printf("\n=============================================\n");

printf("\t\t CPU Scheduling \n\t\t Priority Scheduling");

printf("\n=============================================\n");

printf("\nEnter the number of processes");

scanf("%d",&n);

printf("\nEnter the burst time:\n");

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

printf("P%d :",i);

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

d[i]=i;

printf("\nEnter the priority :\n");

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

printf("P%d :",i);

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

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

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

if(p[i]<p[j])

temp=p[i];

t1=d[i];

te=b[i];

p[i]=p[j];

d[i]=d[j];

b[i]=b[j];

p[j]=temp;

d[j]=t1;

b[j]=te;
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
}

printf("\n\n==============================================\n");

printf("Process\tPriority\tBurst\tWaiting\t\tTurnaround\n");

printf("=========================================");

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

t=d[i];

w[i+1]=w[i]+b[i];

t2[i]=b[i]+w[i];

t3+=t2[i];

printf("\nP%d\t%d\t\t%d\t%d\t\t%d",d[i],p[i],b[i],w[i],t2[i]);

printf("\n=======================================================\n");

temp=0;

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

temp+=w[i];

t=(float)temp/n;

r=(float)t3/n;

printf("\n Average Waiting time :%.2f ms\n",t);

printf("\nAverage Turnaround time :%.2f ms\n",r);

return 0;

Output:

[******@telnet ~]$ cc priority.c -o priority.out

[******@telnet ~]$ ./priority.out

=============================================

CPU Scheduling

Priority Scheduling

=============================================

Enter the number of processes4

Enter the burst time:

P1 :3
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
P2 :6

P3 :4

P4 :2

Enter the priority :

P1 :3

P2 :1

P3 :4

P4 :2

==============================================

Process Priority Burst Waiting Turnaround

=========================================

P3 4 4 0 4

P1 3 3 4 7

P4 2 2 7 9

P2 1 6 9 15

=======================================================

Average Waiting time :5.00 ms

Average Turnaround time :8.75 ms

RESULT:

Thus, Priority Scheduling is done and the output is verified successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex No-5D ROUND ROBIN SCHEDULING ALGORITHM

AIM:

To implement Unix C program for Round robin scheduling algorithm.

ALGORITHM:

STEP 1: Initialize necessary variables

STEP 2: Get the number of processes in a variable 'n' and time quantum value..

STEP 3: Get the CPU burst time and priority of 'n' processes using looping statements.

STEP 4: Initialize tw=0,count=0,exe=0 and tta = 0.

STEP 5: Initialize q[i]=0 for the value of I; From 0 to n and calculate the value of count.

STEP 6: Do the following till the value of count becomes zero, check whether p[i]>0, If it is TRUE,

exe=exe+t;

q[i]=q[i]-t;

decrement the value of count

otherwise,

exe=exe+p[i];

wait[i]=exe-p[i];

STEP 7: Execute the following calculation till the loop condition is true, For ((i=0; i<n; i++))

Tti[i =cpu[i]+wait[i];

tw= tut wait [];

tta=tta + ttt[i];

STEP 8: Calculate average waiting time and average turn around time

avgw=tw/n; avgtt=tta/n;

STEP 9: Print the values of all process id, priority, CPU burst time, waiting time and turn around time
as in Execution order of process..

STEP 10: Print total waiting time, total turnaround time, average waiting time and average turnaround
time.

PROGRAM:

#include<stdio.h>
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
int main()

int i,tbt=0,nop,ts=0,flag[20],rem[20];

int from,wt[20],tt[20],b[20],twt=0,ttt=0,dur;

float awt,att;

printf("==========================================\n");

printf("\t\t CPU Scheduling\n\n\t\tRound Robin Scheduling");

printf("\n========================================");

printf("\nEnter No of Processes:");

scanf("%d",&nop);

printf("\nEnter the Time Slice:");

scanf("%d",&ts);

printf("\nEnter the Burst Time:\n");

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

wt[i]=tt[i]=0;

printf("P%d:",i+1);

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

rem[i]=b[i];

tbt+=b[i];

flag[i]=0;

from=0;

i=0;

printf("\t\tGantt Chart");

printf("\n==============================================\n");

printf("Process\tFrom Time\tTo time");

printf("\n===============================================\n");

while(from<tbt)

if(!flag[i])

if(rem[i]<=ts)

{
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
dur=rem[i];

flag[i]=1;

tt[i]=dur+from;

wt[i]=tt[i]-b[i];

else

dur=ts;

printf("%7d%15d%15d\n",i+1,from,from+dur);

rem[i]-=dur;

from+=dur;

i=(i+1)%nop;

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

twt+=wt[i];

ttt+=tt[i];

printf("\n\n=========================================\n");

printf("\tProcess\t\tWaiting\t\tTurnAround\n");

printf("===============================================");

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

printf("\n\t%d\t\t%d\t\t%d",i+1,wt[i],tt[i]);

printf("\n==============================================\n");

awt=(float)twt/(float)nop;

att=(float)ttt/(float)nop;

printf("\nTotal Waiting Time:%d ms",twt);

printf("\n\nTotal Turn Around Time:%d ms",ttt);

printf("\n\n Average Waiting Time:%.2f ms",awt);

printf("\n\naverage Turn Around Time:%.2f ms",att);


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
return 0;

Output:

[******@telnet ~]$ cc roundrobin.c -o roundrobin.out

[******@telnet ~]$ ./roundrobin.out

==========================================

CPU Scheduling

Round Robin Scheduling

========================================

Enter No of Processes:5

Enter the Time Slice:5

Enter the Burst Time:

P1:7

P2:9

P3:7

P4:8

P5:4

Gantt Chart

==============================================

Process From Time To time

===============================================

1 0 5

2 5 10

3 10 15

4 15 20

5 20 24

1 24 26

2 26 30

3 30 32

4 32 35

=========================================

Process Waiting TurnAround

===============================================
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
1 19 26

2 21 30

3 25 32

4 27 35

5 20 24

Total Waiting Time:112 ms

Total Turn Around Time:147 ms

Average Waiting Time:22.40 ms

average Turn Around Time:29.40 ms

RESULT:

Thus, Round Robin Scheduling is done and the output is verified successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex No-6 INTERPROCESS COMMUNICATION USING SHARED MEMORY

AIM:

To implement Unix C program for Inter process communication using shared memory.

ALGORITHM:

STEP 1: Create the shared memory for parent process using shmget() system call.

STEP 2: Now allow the parent process to write in shared memory using shmget pointer which is
return type of shmget().

STEP 3: Now across and attach the same shared memory to the child process.

STEP 4: The data in the shared memory is read by the child process using the shmdt pointer

STEP 5: Now detach and reuse the shared memory.

SENDER:

#include <stdio.h>

#include <sys/shm.h>

#include <sys/ipc.h>

#define size 32

int main()

int shmid;

char *s[100],*str;

printf("\n :PC message passing using shared memory sender");

shmid=shmget(60,size,IPC_CREAT|0666);

str=shmat(shmid,0,0);

printf("\n Enter the message to be sent");

gets(s);

strcpy(str,s);

printf("\n Your message has been sent");

return 0;

RECEIVER:

#include <stdio.h>

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


#include <sys/shm.h>

#include <sys/ipc.h>

#define size 32

int main()

printf("\n:PC message passing using shared memory receiver");

int shmid;

char *str;

shmid=shmget(60,size,IPC_CREAT|0666);

str=shmat(shmid,0,0);

printf("\n Received message is");

puts(str);

return 0;

OUTPUT:

[******@telnet ~]$ cc ipc.c -o ipc_s.out

[******@telnet ~]$ ./ipc_s.out

PC message passing using shared memory sender

Enter the message to be sent:hello friends

Your message has been sent

[******@telnet ~]$ cc ipc_r.c -o ipc_r.out

[******@telnet ~]$ ./ipc_r.out

PC message passing using shared memory receiver

Received message is hello friends

RESULT:

Thus, the IPC program using shared memory has been written and executed successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex No-7 IMPLEMENTATION OF SEMAPHORE

AIM:

To implement Unix C program for Semaphore.

ALGORITHM:

STEP 1: Initialize the semaphore variables mutex=1, full= 0, empty=3.

STEP 2: Invoke the wait() to enter into critical section and signal() is for exit section.

STEP 3: The producer will produce until buffer is full.

mutex=wait (mutex);

Full=signal (Full);

empty=walt (empty);

x++;

Producer produces an item

mutex =signal (mutex);

STEP 4: The Consumer will consume till the buffer is empty.

Mutex=wait(mutex);

Full= wait (Full);

empty=signal (empty),

consumes an item

x--; mutex= signal (mutex);

STEP 5: If the Buffer s empty then the Consumer will not consume the items.

STEP 6: of the Buffer is full then the Producer will not produce the items.

STEP 7: Print the result.

PROGRAM:

#include<stdio.h>

#include<stdlib.h>

int mutex=1,full=0,empty=3,x=0;

int main()

int n;

void producer();

void consumer();

int wait(int);
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
int signal(int);

printf("\n1.Producer\n2.Consumer\n3.Exit");

while(1)

printf("\n enter your choice");

scanf("%d",&n);

switch(n)

case 1:

if((mutex==1)&&(empty!=0))

producer();

else

printf("Buffer is full!");

break;

case 2:

if((mutex==1)&&(full!=0))

consumer();

else

printf("Buffer is empty!!");

break;

case 3:

exit(0);

break;

return 0;

int wait(int s)

return(--s);

int signal(int s)

return(++s);
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
}

void producer()

mutex=wait(mutex);

full=signal(full);

empty=wait(empty);

x++;

printf("\n Producer produce the item%d",x);

mutex=signal(mutex);

void consumer()

mutex=wait(mutex);

full=wait(full);

empty=signal(empty);

printf("\n consumer consumes item%d",x);

x--;

mutex=signal(mutex);

Output:

[******@telnet ~]$ cc semaphore.c -o semaphore.out

[******@telnet ~]$ ./semaphore.out

1.Producer

2.Consumer

3.Exit

enter your choice:1

Producer produce the item1

enter your choice:1

Producer produce the item2

enter your choice:1


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Producer produce the item3

enter your choice:1

Buffer is full!

enter your choice:2

consumer consumes item3

enter your choice:2

consumer consumes item2

enter your choice:2

consumer consumes item1

enter your choice:2

Buffer is empty!!

enter your choice:3

RESULT:

Thus, the implementation of producer, consumer problem using semaphore has been executed
successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex.No:8 IMPLEMENTATION OF BANKERS ALGORITHM-DEADLOCK AVOIDANCE

AIM:

To implement Unix C program for banker’s algorithm for deadlock avoidance.

ALGORITHM:

STEP 1: Start the program.

STEP 2: Create a structure for all vectors.

STEP 3: Get the number of resources and processes.

STEP 4: Get the avail value, allocation and max value for all processes based on each resource.

STEP 5: Find the need value using max allocation.

STEP 6: Check whether it’s possible to allocate.

STEP 7: It it is possible then the system. Is in safe state.

STEP 8: Else the system is not in safety state

STEP 9: If the new request comes then check that the system is in safety or not if we allow the
request .

STEP10: Stop the program.

PROGRAM:

#include<stdio.h>

struct file

int all[10];

int max[10];

int need[10];

int flag;

};

void main()

struct file f[10];

int f1; int i,j,k,p,b,n,r,g,cnt=0,id,newr;

int avail[10],seq[10];

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


printf("Enter no of processes:");

scanf("%d",&n);

printf("Enter no of resources:");

scanf("%d",&r);

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

printf("Enter details for p%d",i);

printf("\nEnter allocation \t--\t");

for(j=0;j<r;j++)

scanf("%d",&f[i].all[j]);

printf("Enter max \t\t--\t");

for(j=0;j<r;j++)

scanf("%d",&f[i].max[j]);

f[i].flag=0;

printf("\nEnter available resources \t--\t");

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

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

printf("\nEnter new request details --");

printf("\nEnter pid \t--\t");

scanf("%d",&id);

printf("\nEnter request for resources \t--\t");

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

scanf("%d",&newr);

f[id].all[i]+=newr;

avail[i]=avail[i]-newr;

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

for(j=0;j<r;j++)

f[i].need[j]=f[i].max[j]-f[i].all[j];

if(f[i].need[j]<0)
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
f[i].need[j]=0;

cnt=0;

f1=0;

while(cnt!=n)

g=0;

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

if(f[j].flag==0)

b=0;

for(p=0;p<r;p++)

if(avail[p]>=f[j].need[p])

b=b+1;

else

b=b-1;

if(b==r)

printf("\np%d is visited",j);

seq[f1++]=j;

f[j].flag=1;

for(k=0;k<r;k++)

avail[k]=avail[k]+f[j].all[k];

cnt=cnt+1;

printf("(");

for(k=0;k<r;k++)

printf("%3d",avail[k]);

printf(")");

g=1;

}
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
}

if(g==0)

printf("\nREQUEST NOT GRANTED -- DEADLOCK OCCURRED");

printf("\nSYSTEM IS IN UNSAFE STATE");

goto y;

printf("\nSYSTEM IS IN SAFE STATE");

printf("\nThe safe sequence is --(");

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

printf("p%d",seq[i]);printf(")");

y:printf("\nProcess\t\tAllocation\t\tMax\t\t\tNeed\n");

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

printf("p%d\t",i);

for(j=0;j<r;j++)

printf("%6d",f[i].all[j]);

for(j=0;j<r;j++)

printf("%6d",f[i].max[j]);

for(j=0;j<r;j++)

printf("%6d",f[i].need[j]);

printf("\n");

OUTPUT:

[******@telnet ~]$ cc deadlock_avoidance.c -o deadlock_avoidance.out

[******@telnet ~]$ ./deadlock_avoidance.out

Enter no of processes:5

Enter no of resources:3

Enter details for p0


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Enter allocation -- 3

Enter max -- 7

Enter details for p1

Enter allocation -- 2

Enter max -- 3

Enter details for p2

Enter allocation -- 3

Enter max -- 9

Enter details for p3

Enter allocation -- 2

Enter max -- 2

Enter details for p4

Enter allocation -- 0

Enter max -- 4

3
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Enter available resources -- 3

Enter new request details --

Enter pid -- 1

Enter request for resources -- 1

p1 is visited( 5 3 2)

p3 is visited( 7 4 3)

p4 is visited( 7 4 5)

p0 is visited( 7 5 5)

p2 is visited( 10 5 7)

SYSTEM IS IN SAFE STATE

The Safe Sequence is -- (P1 P3 P4 P0 P2 )

Process Allocation Max Need

P0 0 1 0 7 5 3 7 4 3

P1 3 0 2 3 2 2 0 2 0

P2 3 0 2 9 0 2 6 0 0

P3 2 1 1 2 2 2 0 1 1

P4 0 0 2 4 3 3 4 3 1

[******@telnet ~]$

RESULT:

Thus, the banker’s algorithm for deadlock avoidance has been written and executed successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


ExNo-9 DEADLOCK DETECTION USING BANKER'S ALGORITHM

AIM:

To implement Unix C program for banker’s algorithm for deadlock detection.

ALGORITHM:

STEP 1: Mark each process that has a row in the Allocation matrix if all zeros.

STEP 2: Initialize a temporary vector W to equal the Available vector.

STEP 3: Find on index i such that process i is currently unmarked and the row of Q is less than or
equal to W. That is, Q ik..... Wk For 1...k...m. If no such now is found, terminate the algorithm.

STEP 4: If such a row is found, mark process and add the corresponding row of the allocation matrix
to W. That is, Set Wk=Wk+Aik, For l...k...m. Return to Step 3.

PROGRAM:

#include <stdio.h>

static int mark[20];

int i,j,np,nr;

int main()

int alloc[10][10],request[10][10],avail[10],r[10],w[10];

printf("\nEnter the no of process: ");

scanf("%d",&np);

printf("\nEnter the no of resources: ");

scanf("%d",&nr);

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

printf("\nTotal Amount of the Resource R%d : ",i+1);

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

printf("\nEnter the request matrix: ");

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

for(j=0;j<nr;j++)

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

printf("\nEnter the allocation matrix:");


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
for(i=0;i<np;i++)

for(j=0;j<nr;j++)

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

/*Available Resource calculation*/

for(j=0;j<nr;j++)

avail[j]=r[j];

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

avail[j]-=alloc[i][j];

//marking processes with zero allocation

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

int count=0;

for(j=0;j<nr;j++)

if(alloc[i][j]==0)

count++;

else

break;

if(count==nr)

mark[i]=1;

//initialize W with avail

for(j=0;j<nr;j++)

w[j]=avail[j];

//mark processes with request less than or equal to W

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

int canbeprocessed=0;

if(mark[i]!=1)
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
{

for(j=0;j<nr;j++)

if(request[i][j]<=w[j])

canbeprocessed=0;

else

canbeprocessed=0;

break;

if(canbeprocessed)

mark[i]=1;

for(j=0;j<nr;j++)

w[j]+=alloc[i][j];

//checking for unmarked processes

int deadlock=0;

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

if(mark[i]!=1)

deadlock=1;

if(deadlock)

printf("\n Deadlock detected");

else

printf("\n No Deadlock Possible");

Output:

[******@telnet ~]$ cc deadlockdetect.c -o deadlockdetect.out

[******@telnet ~]$ ./deadlockdetect.out

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Enter the no of process: 4

Enter the no of resources: 5

Total Amount of the Resource R1 : 2

Total Amount of the Resource R2 : 1

Total Amount of the Resource R3 : 1

Total Amount of the Resource R4 : 2

Total Amount of the Resource R5 : 1

Enter the request matrix: 0 1 0 0 1

00101

00001

10101

Enter the allocation matrix:1 0 1 1 0

11000

00010

00000

Deadlock detected

RESULT:

Thus, the deadlock detection algorithm has been written and executed successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex. No. 10 IMPLEMENT THREADING AND SYNCHRONIZATION APPLICATION

AIM:

To implement Unix C program for threading and synchronization application.

ALGORITHM:

STEP 1: Thread IO is represented by the type “pthread-t”

STEP 2: When a program starts up and becomes a process, it starts with a default thread. So, we can
say that every process has atleast one thread of control.

STEP 3: A process can create extra threads wing the following functions.

#include <pthread.h>

int pthread-create (pthread-t

*restrict tidp, const pthread attr_t *restrict attr. void (*start_rtn) (void), void *restrict avg).

STEP 4: Inside the function "defome Thing()” the thread uses pthread self() and pthread.equ
Functions to identify whether the execution thread is the first one or second one is created.

STEP 5: Also inside the same function dofome Thing() a For loop is run so as to stimulate sometime
consuming work.

PROGRAM:

#include <stdio.h>

#include <string.h>

#include <pthread.h>

#include <stdlib.h>

#include <unistd.h>

pthread_t tid[2]; int counter;

pthread_mutex_t lock;

void* trythis(void *arg)

pthread_mutex_lock(&lock);

unsigned long i = 0; counter += 1;

printf("\n Job %d has started\n", counter); for(i=0; i<(0xFFFFFFFF);i++);

printf("\n Job %d has finished\n", counter); pthread_mutex_unlock(&lock);

return NULL;

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


}

main()

int i = 0; int error;

if (pthread_mutex_init(&lock, NULL) != 0)

printf("\n mutex init has failed\n"); return 1;

while(i < 2)

err = pthread_create(&(tid[i]), NULL, &trythis, NULL); if (error != 0)

printf("\nThread can't be created :[%s]", strerror(error));

i++;

pthread_join(tid[0], NULL); pthread_join(tid[1], NULL); pthread_mutex_destroy(&lock);

return 0;

Output:

$ cc filename.c -lpthread

$ ./a.out

Job 1 started

Job 1 finished

Job 2 started

Job 2 finished

RESULT:

Thus, the implementation of the threading and synchronization application using C program has
been executed successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex.No 11A: FIRST FIT ALLOCATION

AIM:

To implement Unix C program for first fit contiguous memory allocation.

ALGORITHM:

STEP 1: Start.

STEP 2: Read the number of Free blocks and size of each Free block.

STEP 3: Get the process block size to be loaded.

STEP 4: Allocate the first hole that is big enough to load the process.

STEP 5: If no hole is big enough to load the process, then process cannot be allocate.

STEP 6: Display the size of all the free blocks.

STEP 7: Stop.

PROGRAM:

#include<stdio.h>

int main()

int i,j,bno,bsize[10],pno,psize[10];

printf("\nEnter the no of free block:");

scanf("%d",&bno);

printf("Size of free block:");

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

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

printf("No of process:");

scanf("%d",&pno);

printf("Size of process");

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

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

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

printf("\nSize of free block %d:%d",i+1,bsize[i]);

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

printf("\nSize of process %d:%d:",i+1,psize[i]);

printf("\nFirst fit");
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
printf("\npno\tallocated block\tallocated size\tfragment\n");

i=0;

while(i<pno)

for(j=0;j<bno;j++)

if(psize[i]<bsize[j])

bsize[j]-=psize[i];

break;

printf("%d\t\t%d\t\t%d\t\t%d\n",i+1,j+1,psize[i],bsize[j]);

i++;

printf("\nFragment size negative or more than max allocated block that process is out of memory otherwise
all process fit into memory"); 7,1 60%

return 0;

[******@telnet ~]$ cc firstfit.c -o firstfit.out

[******@telnet ~]$ ./firstfit.out

Enter the no of free block:5

Size of free block:100 500 200 300 600

No of process:4

Size of process:212 417 112 426

Size of free block 1:100

Size of free block 2:500

Size of free block 3:200

Size of free block 4:300

Size of free block 5:600

Size of process 1:212

Size of process 2:417

Size of process 3:112

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Size of process 4:426

First fit

pno allocated block allocated size fragment

1 2 212 288

2 5 417 183

3 2 112 176

4 6 426 32767

Fragment size negative or more than max allocated block that process is out of memory otherwise all
process fit into memory

[******@telnet ~]$

RESULT:

Thus, the dynamic storage allocation scheme using First Fit Algorithm has been written and executed
successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


EX.No 11B BEST FIT ALLOCATION

AIM:

To implement Unix C program for best fit contiguous memory allocation.

ALGORITHM:

STEP 1: Start.

STEP 2: Read the number of Free blocks and size of each Free block.

STEP 3: Get the process block size to be loaded.

STEP 4: Allocate the smallest hole that is big enough to load the process.

STEP 5: If no hole is big enough to load the process, then process cannot be allocated.

STEP 6: Display the size of all the free blocks.

STEP 7: Stop.

PROGRAM:

#include<stdio.h>

#define max 25

void main()

int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;

static int bf[max],ff[max];

printf("\nEnter the number of blocks:");

scanf("%d",&nb);

printf("Enter the number of files:");

scanf("%d",&nf);

printf("Enter the size of 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++)

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


printf("File %d",i);

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

for(i=1;i<=nf;i++)

for(j=1;j<=nb;j++)

if(bf[j]!=1)

temp=b[j]-f[i];

if(temp>=0)

if(lowest>temp)

ff[i]=j;

lowest=temp;

frag[i]=lowest;

bf[ff[i]]=1;

lowest=10000;

printf("\nFile_no\tFile_size\tBlock_no\tBlock_size\tFragment");

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

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

[******@telnet ~]$ cc bestfit.c -o bestfit.out

[******@telnet ~]$ ./bestfit.out

Enter the number of blocks:6

Enter the number of files:5

Enter the size of blocks:

Block 1:200

Block 2:400
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Block 3:600

Block 4:500

Block 5:300

Block 6:250

Enter the size of the files:

File 1:357

File 2:210

File 3:468

File 4:491

File 5:40

File_no File_size Block_no Block_size Fragment

1 357 2 400 43

2 210 6 250 40

3 468 4 500 32

4 491 3 600 109

5 40 1 200 160

[******@telnet ~]$

RESULT:

Thus, the dynamic storage allocation scheme using Best Fit Algorithm has been written and
executed successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


ExNo-11c WORST FIT ALGORITHM

AIM:

To implement Unix C program for worst fit contiguous memory allocation.

ALGORITHM:

STEP 1: Start.

STEP 2: Read the number of Free blocks and size of each Free block.

STEP 3: Get the process block size to be loaded.

STEP 4: Allocate the largest hole that is big enough to load the process.

STEP 5: If no hole is big enough to load the process, then process cannot be allocated.

STEP 6: Display the size of all the free blocks.

STEP 7: Stop.

PROGRAM:

#include <stdio.h>

#define max 25

void main()

int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;

static int bf[max],ff[max];

printf("\n\tMemory Management scheme-worst 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("\nEnter the size of the files:\n");

for(i=1;i<=nf;i++)

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


{

printf("File %d:",i);

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

for(i=1;i<=nf;i++)

for(j=1;j<=nb;j++)

if(bf[j]!=1)

temp=b[j]-f[i];

if(temp>=0)

if(highest<temp)

ff[i]=j;

highest=temp;

frag[i]=highest;

bf[ff[i]]=1;

highest=0;

printf("\nFile_no:\t File_size:\t Block_no:\t Block_size:\t Fragment");

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]);

Output:

[******@telnet ~]$ cc worstfit.c -o worstfit.out

[******@telnet ~]$ ./worstfit.out

Memory Management scheme-worst fit

Enter the number of blocks:6

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Enter the number of files:5
16,19 Bot

Enter the size of the blocks:

Block 1:200

Block 2:400
13,7 Bot

Block 3:600

Block 4:500

Block 5:300

Block 6:250

Enter the size of the files:

File 1:357

File 2:210

File 3:468

File 4:491

File 5:40

File_no: File_size: Block_no: Block_size: Fragment

1 357 3 600 243

2 210 4 500 290

3 468 0 1 0

4 491 0 1 0

5 40 2 400 360

RESULT:

Thus, the dynamic storage allocation scheme using Worst Fit Algorithm has been written and
executed successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex. No. 12 PAGING TECHNIQUE

AIM:

To implement Unix C program for paging technique.

ALGORITHM:

STEP 1: Get the memory size and page size.

STEP 2: Get the number of processes.

STEP 3: Get the number of pages, required is greater than the total number of available pages in
memory.

STEP 4: Then print Memory is full otherwise calculate remaining pages=$rem page-s[1]

STEP 5: Enter the page table info for each process and calculate the logical address to find physical
address.

STEP 6: When process is executed, pages loaded in available memory frames from their source.

PROGRAM:

#include <stdio.h>

#include <math.h>

main()

int size, m, n, pgno, pagetable[3]={5,6,7}, i, j, frameno; double m1;

int ra=0, ofs;

printf("Enter process size (in KB of max 12KB):");

scanf("%d", &size);

m1 = size / 4; n = ceil(m1);

printf("Total No. of pages: %d", n); printf("\nEnter relative address (in hexa) \n");

scanf("%d", &ra);

pgno = ra / 1000; ofs = ra % 1000;

printf("page no=%d\n", pgno);

printf("page table");

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

printf("\n %d [%d]", i, pagetable[i]);

frameno = pagetable[pgno];

printf("\nPhysical address: %d%d", frameno, ofs);

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


}

Output:

Enter process size (in KB of max 12KB):12 Total No. of pages: 3

Enter relative address (in hexa): 2643

page no=2 page table

0 [5]

1 [6]

2 [7]

Physical address : 7643

RESULT:

Thus, the paging technique of memory management is executed successfully and the output is
verified.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


ExNo-13a FIFO PAGE REPLACEMENT ALGORITHM

AIM:

To implement Unix C program for FIFO page replacement algorithm.

ALGORITHM:

STEP 1: Get length of the reference string, say l.

STEP 2: Get the reference string and store it in a array say rs.

STEP 3: Get the number of frocmes, say nf.

STEP 4: Initialize Frame array upto length nf to-1.

STEP 5: Initialize position of the oldest page, say j to 0.

STEP 6: Initialize no. of pages Faults, say Count=0

STEP 7: For each page in reference string in the given order, examine:

a) Check whether page exist in the frame array.

b). If it does exist then replace page in position j.

PROGRAM:

#include <stdio.h>

main()

int i,j,k,f,pf=0,count=0,rs[25],m[10],n;

printf("Enter the length of the reference string:");

scanf("%d",&n);

printf("\nEnter the reference string--");

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

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

printf("Enter the number of frames--");

scanf("%d",&f);

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

m[i]=-1;

printf("\nThe page replacement process is--\n");

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

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


{

for(k=0;k<f;k++)

if(m[k]==rs[i])

break;

if(k==f)

m[count++]=rs[i];

pf++;

for(j=0;j<f;j++)

printf("\t%d",m[j]);

if(k==f)

printf("\tPF NO. %d",pf);

printf("\n");

if(count==f)

count=0;

printf("\nThe number of page faults using FIFO are %d",pf);

return 0;

Output:

[******@telnet ~]$ cc fifo.c -o fifo.out

[******@telnet ~]$ ./fifo.out

Enter the length of the reference string:20

Enter the reference string--7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1

Enter the number of frames--3

The page replacement process is--

7 -1 0 PF NO. 1
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
7 -1 0

7 1 0 PF NO. 2

7 1 2 PF NO. 3

0 1 2 PF NO. 4

0 3 2 PF NO. 5

0 3 2

0 3 4 PF NO. 6

2 3 4 PF NO. 7

2 3 4

2 0 4 PF NO. 8

2 0 3 PF NO. 9

2 0 3

1 0 3 PF NO. 10

1 2 3 PF NO. 11

1 2 0 PF NO. 12

1 2 0

7 2 0 PF NO. 13

7 2 0

7 1 0 PF NO. 14

The number of page faults using FIFO are 14

RESULT:

Thus, page replacement was implemented using FIFO Algorithm.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


ExNo-13b LRU PAGE REPLACEMENT ALGORITHM

AIM:

To implement Unix C program for LRU page replacement algorithm.

ALGORITHM:

STEP 1: Get the length of the reference string, Say len

STEP 2: Get the reference string and store it in an array, say rs.

STEP 3: Get number of frames, say nf.

STEP 4: Create account access array to store counter that indicates a measure of recent usage.

STEP 5: Create a function as min that returns position of minimum of the given array.

STEP 6: Initialize frame array upto length of nF to -1.

STEP 7: Initialize position of the page replacement, Say j to 0.

STEP 8: Initialize frequency to 0 to track page frequency.

STEP 9: Initialize number of page faults, say count to 0.

STEP 10: For each page in reference starting in the given order, examine

a) check whether page exist in the Frame array.

b) If page exist in memory then

(1)Store incremented freq, for that page position in access array.

c) If page does not exist in memory Function then,

(1) Check for empty frames

(2) If there is an empty frame, Assign that frame to the page. Store incremented freq for that
position in accars array, Increment count.

(3). If there is no free frame then, Determine page to be replaced using as min function. Store
incremented freq For the page position in access array, Increment count

(4) Display pages in frame array

STEP 11: Print count

STEP 12: Stop

PROGRAM:
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
#include <stdio.h>

main()

int i,j,k,min,rs[25],m[10],count[10],flag[25],n,f,pf=0,next=1;

printf("Enter the length of reference string--");

scanf("%d",&n);

printf("Enter the reference string--");

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

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

flag[i]=0;

printf("Enter the number of frames--");

scanf("%d",&f);

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

count[i]=0;

m[i]=-1;

printf("\nThe page replacement process is--\n");

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

for(j=0;j<f;j++)

if(m[j]==rs[i])

flag[i]=1;

count[j]=next;

next++;

if(flag[i]==0)

if(i<f)
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
{

m[i]=rs[i];

count[i]=next;

next++;

else

min=0;

for(j=1;j<f;j++)

if(count[min]>count[j])

min=j;

m[min]=rs[i];

count[min]=rs[i];

count[min]=next;

next++;

pf++;

for(j=0;j<f;j++)

printf("%d\t",m[j]);

if(flag[i]==0)

printf("PF NO.__%d",pf);

printf("\n");

printf("\nThe number of page faults using LRU are %d",pf);

Output:

[******@telnet ~]$ cc lru.c -o lru.out

[******@telnet ~]$ ./lru.out

Enter the length of reference string--20

Enter the reference string--7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1

Enter the number of frames--3

The page replacement process is--


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
7 -1 -1 PF NO.__1

7 0 -1 PF NO.__2

7 0 1 PF NO.__3

2 0 1 PF NO.__4

2 0 1

2 0 3 PF NO.__5

2 0 3

4 0 3 PF NO.__6

4 0 2 PF NO.__7

4 3 2 PF NO.__8

0 3 2 PF NO.__9

0 3 2

0 3 2

1 3 2 PF NO.__10

1 3 2

1 0 2 PF NO.__11

1 0 2

1 0 7 PF NO.__12

1 0 7

1 0 7

The number of page faults using LRU are 12

RESULT:

Thus, page replacement was implemented using LRU Algorithm and the output is verified.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex.No.13c LFU PAGE REPLACEMENT ALGORITHM

AIM:

To implement Unix C program for LFU page replacement algorithm.

ALGORITHM:

STEP 1: Start the program

STEP 2: Read the length of the reference string and also get the reference string.

STEP 3: Read the number of frames

STEP 4: Allocate the pages in to frames by selecting the page that will not use for the longest period
of time.

STEP 5: Display the number of page faults

STEP 6: Stop the program.

PROGRAM:

#include <stdio.h>

void main()

int rs[50],i,j,k,m,f,cntr[20],a[20],min,pf=0;

printf("\n Enter the no of page refernces ---");

scanf("%d",&m);

printf("Enter the refernce string---");

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

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

printf("\nEnter the available no of frames:");

scanf("%d",&f);

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

cntr[i]=0;

a[i]=-1;

printf("\n Page replacement process is\n");

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

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


{

for(j=0;j<f;j++)

if(rs[i]==a[j])

cntr[j]++;

break;

if(j==f)

min=0;

for(k=1;k<f;k++)

if(cntr[k]<cntr[min])

min=k;

a[min]=rs[i];

cntr[min]=1;

pf++;

printf("\n");

for(j=0;j<f;j++)

printf("\t %d",a[j]);

if(j==f)

printf("\t pf not %d",pf);

printf("\n\n total no of page faults ----%d",pf);

Output:

[******@telnet ~]$ cc lfu.c -o lfu.out

[******@telnet ~]$ ./lfu.out

Enter the no of page refernces ---20

Enter the refernce string---7

2
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
0

Enter the available no of frames:3

Page replacement process is

7 -1 -1 pf not 1

7 0 -1 pf not 2

7 0 1 pf not 3

2 0 1 pf not 4

2 0 1 pf not 4

3 0 1 pf not 5

3 0 1 pf not 5

4 0 1 pf not 6

2 0 1 pf not 7

3 0 1 pf not 8

3 0 1 pf not 8

3 0 1 pf not 8

3 0 2 pf not 9

3 0 1 pf not 10

3 0 2 pf not 11
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
3 0 2 pf not 11

3 0 1 pf not 12

3 0 7 pf not 13

3 0 7 pf not 13

3 0 1 pf not 14

total no of page faults ----14

RESULT:

Thus, the LFU page replacement algorithm has been written and executed successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


EX:NO:14 A Implementation of the various File Organization Techniques

(Single level directory)

AIM:

To implement Unix C program for file organization techniques for single level directory.

ALGORITHM:

STEP 1: Get name of directory for the user to store all the files.

STEP 2: Display menu

STEP 3: If choice=1 then Accept filename without any collision.

STEP 4: If choice: 2 then Remove filename from the directory array

STEP 5: If choice = 3 the Accept Filename

STEP 6: Check for existence of file in the directory array.

STEP 7: If choice-4 then List all files in the directory array.

STEP 8: If choice 5 then stop

PROGRAM:

#include<stdio.h>

#include<string.h>

struct

char dname[10],fname[10][10];

int fcnt;

}dir;

void main()

int i,ch;

char f[30];

dir.fcnt = 0;

printf("\nEnter name of directory -- ");

scanf("%s", dir.dname);

while(1)

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


printf("\n\n1. Create File\t2. Delete File\t3. Search File \n4. Display Files\t5. Exit\n");

printf("Enter your choice -- ");

scanf("%d",&ch);

switch(ch)

case 1: printf("\nEnter the name of the file -- ");

scanf("%s",dir.fname[dir.fcnt]);

dir.fcnt++;

break;

case 2: printf("\nEnter the name of the file -- ");

scanf("%s",f);

for(i=0;i<dir.fcnt;i++)

if(strcmp(f, dir.fname[i])==0)

printf("File %s is deleted ",f);

strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);

break;

if(i==dir.fcnt)

printf("File %s not found",f);

else

dir.fcnt--;

break;

case 3:

printf("\nEnter the name of the file -- ");

scanf("%s",f);

for(i=0;i<dir.fcnt;i++)

if(strcmp(f, dir.fname[i])==0)

printf("File %s is found ", f);

break;
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
}

if(i==dir.fcnt)

printf("File %s not found",f);

break;

case 4:

if(dir.fcnt==0)

printf("\nDirectory Empty");

else

printf("\nThe Files are -- ");

for(i=0;i<dir.fcnt;i++)

printf("\t%s",dir.fname[i]);

break;

default: exit(0);

[******@telnet ~]$ cc 14.c

[******@telnet ~]$ ./a.out

Output:

Enter name of directory -- SecondCSE_A

1. Create File 2. Delete File 3. Search File

4. Display Files 5. Exit

Enter your choice -- 1

Enter the name of the file -- OS

1. Create File 2. Delete File 3. Search File

4. Display Files 5. Exit

Enter your choice -- 1

Enter the name of the file -- DBMS

1. Create File 2. Delete File 3. Search File

4. Display Files 5. Exit

Enter your choice -- 1


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Enter the name of the file -- CA

1. Create File 2. Delete File 3. Search File

4. Display Files 5. Exit

Enter your choice -- 1

Enter the name of the file -- DAA

1. Create File 2. Delete File 3. Search File

4. Display Files 5. Exit

Enter your choice -- 1

Enter the name of the file -- AIML

1. Create File 2. Delete File 3. Search File

4. Display Files 5. Exit

Enter your choice -- 4

The Files are -- OS DBMS CA DAA AIML

1. Create File 2. Delete File 3. Search File

4. Display Files 5. Exit

Enter your choice -- 3

Enter the name of the file -- DAA

File DAA is found

1. Create File 2. Delete File 3. Search File

4. Display Files 5. Exit

Enter your choice -- 2

Enter the name of the file -- DBMS

File DBMS is deleted

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


1. Create File 2. Delete File 3. Search File

4. Display Files 5. Exit

Enter your choice -- 4

The Files are -- OS CA DAA AIML

1. Create File 2. Delete File 3. Search File

4. Display Files 5. Exit

Enter your choice -- 5

[******@telnet ~]$

RESULT:

Thus, files are organized into a single-level directory.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


EX:NO:14B Implementation of the following File Allocation Strategies - Sequential

AIM:

To implement Unix C program for Sequential file allocation strategy.

ALGORITHM:

STEP 1: Assure number of blocks in the disk as 20 and all are free.

STEP 2: Display the status of disc blocks before Callocation

STEP 3: For each File to be allocated

a) Get the filename, start address and file length.

b) It start+ length >20, then gato step 2.

c) Check to see whether any black in the range (start, start, length-1) is allocated. If so, then go to
step 2.

d) Allocate blocks to the file contiguously from start block to start + length-1

STEP 4: Display directory entries.

STEP 5: Display status of disk blocks after allocation.

STEP 6: Stop.

PROGRAM:

#include < stdio.h>

#include<conio.h>

void main()

int f[50], i, st, len, j, c, k, count = 0;

clrscr();

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

f[i]=0;

printf("Files Allocated are : \n");

x: count=0;

printf(“Enter starting block and length of files: ”);

scanf("%d%d", &st,&len);

for(k=st;k<(st+len);k++)

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


if(f[k]==0)

count++;

if(len==count)

for(j=st;j<(st+len);j++)

if(f[j]==0)

f[j]=1;

printf("%d\t%d\n",j,f[j]);

if(j!=(st+len-1))

printf(” The file is allocated to disk\n");

else

printf(” The file is not allocated \n");

printf("Do you want to enter more file(Yes - 1/No - 0)");

scanf("%d", &c);

if(c==1)

goto x;

else

exit(0);

getch();

[******@telnet ~]$ cc sequential.c

[******@telnet ~]$ ./a.out

Output:

Files Allocated are :

Enter starting block and length of files:10

10 1

11 1

12 1

The file is allocated to disk


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Do you want to enter more file(Yes - 1/No - 0)1

Enter starting block and length of files:25 6

25 1

26 1

27 1

28 1

29 1

30 1

The file is allocated to disk

Do you want to enter more file(Yes - 1/No - 0)0

RESULT:

Thus, the sequential allocation is done for the file with the available free blocks.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


EX:NO:14 C Implementation of the following File Allocation Strategies - Indexed

AIM:

To implement Unix C program for Indexed file allocation strategy.

ALGORITHM:

STEP 1: Start the program

STEP 2: Get information about the number of files.

STEP 3: Get the memory requirement of each file

STEP 4: Allocate the memory to the file by selecting random location.

STEP 5: Check if the location that is selected is free or not.

STEP 6: It the location is allocated set the flag= 1 and if free set flag=0 .

STEP 7: Print the file number, length and the block allocated.

STEP 8: Gather information if more files must be stored.

STEP 9: If yes, then go to step2.

STEP 10: If no, stop the program.

PROGRAM:

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

void main()

int f[50], index[50],i, n, st, len, j, c, k, ind,count=0;

clrscr();

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

f[i]=0;

x:printf("Enter the index block: ");

scanf("%d",&ind);

if(f[ind]!=1)

printf("Enter no of blocks needed and no of files for the index %d on the disk : \n", ind);

scanf("%d",&n);
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
}

else

printf("%d index is already allocated \n",ind);

goto x;

y: count=0;

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

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

if(f[index[i]]==0)

count++;

if(count==n)

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

f[index[j]]=1;

printf("Allocated\n");

printf("File Indexed\n");

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

printf("%d-------->%d : %d\n",ind,index[k],f[index[k]]);

else

printf("File in the index is already allocated \n");

printf("Enter another file indexed");

goto y;

printf("Do you want to enter more file(Yes - 1/No - 0)");

scanf("%d", &c);

if(c==1)

goto x;

else

exit(0);
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
getch();

"index.c" [New] 41L, 818C written

[******@telnet ~]$ cc index.c

[******@telnet ~]$ ./a.out

Enter the index block: 5

Enter no of blocks needed and no of files for the index 5 on the disk :

1234

Allocated

File Indexed

5-------->1 : 1

5-------->2 : 1

5-------->3 : 1

5-------->4 : 1

Do you want to enter more file(Yes - 1/No - 0)1

Enter the index block: 4

4 index is already allocated

Enter the index block: 6

Enter no of blocks needed and no of files for the index 6 on the disk :

78

A5llocated

File Indexed

6-------->7 : 1

6-------->8 : 1

Do you want to enter more file(Yes - 1/No - 0)0

RESULT:

Thus, the blocks for file were allocation using Indexed Allocation Method.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


EX:NO:14d Implementation of the following File Allocation Strategies -Linked

AIM:

To implement Unix C program for Linked file allocation strategy.

ALGORITHM:

STEP 1: Get number of files

STEP 2: Accept filenames and number of blocks of each file.

STEP 3: Obtain start block for each file.

STEP 4: Obtain other blocks for each file.

STEP 5: Check block Availability before allocation.

STEP 6: If blade is unavailable then report error.

STEP 7: Accept File name

STEP 8: Display the linked File Allocation files blocks for that file.

STEP 9: Stop.

PROGRAM:

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

void main()

int f[50], p,i, st, len, j, c, k, a;

clrscr();

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

f[i]=0;

printf("Enter how many blocks already allocated: ");

scanf("%d",&p);

printf("Enter blocks already allocated: ");

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

scanf("%d",&a);

f[a]=1;

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


}

x: printf("Enter index starting block and length: ");

scanf("%d%d", &st,&len);

k=len;

if(f[st]==0)

for(j=st;j<(st+k);j++)

if(f[j]==0)

f[j]=1;

printf("%d-------->%d\n",j,f[j]);

else

printf("%d Block is already allocated \n",j);

k++;

else

printf("%d starting block is already allocated \n",st);

printf("Do you want to enter more file(Yes - 1/No - 0)");

scanf("%d", &c);

if(c==1)

goto x;

else

exit(0);

getch();

[******@telnet ~]$ cc 15c.c

[******@telnet ~]$ ./a.out

Enter how many blocks already allocated: 3


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Enter blocks already allocated: 1 3 5

Enter index starting block and length: 2 2

2-------->1-

3 Block is already allocated

4-------->1-

Do you want to enter more file(Yes - 1/No - 0)1

Enter index starting block and length: 10 4

10-------->1

11-------->1

12-------->1

13-------->1

Do you want to enter more file(Yes - 1/No - 0)1

Enter index starting block and length: 10 4

10 starting block is already allocated

Do you want to enter more file(Yes - 1/No - 0)1

Enter index starting block and length: 12 2

12 starting block is already allocated

Do you want to enter more file(Yes - 1/No - 0)0

[******@telnet ~]$

RESULT:

Thus, blocks for file were allocated using linked allocation method.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex.No 15A FCFS DISK SCHEDULING

AIM:

To implement Unix C program for FCFS disk scheduling algorithm.

ALGORITHM:

STEP 1: Let Request array represents an index of tracks that have been requested in ascending order
of their time of arrival. 'head' is the position of disk heads

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

STEP 3: Increment the total seek count with this distance.

STEP 4: Currently serviced trade position now becomes the new head position.

STEP 5: Go to Step 2 until all tracks in request array have not been serviced.

PROGRAM:

#include<stdio.h>

int main()

int queue[100],n,head,i,j,k,seek=0,diff;

float avg;

printf("==============================================================");

printf("\n\t\t\tDemonstration of\n\t\tFCFS Disk Scheduling\n");

printf("==============================================================\n");

printf("Enter the size of Queue\t");

scanf("%d",&n);

printf("Enter the Queue\t");

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

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

printf("Enter the initial head position\t");

scanf("%d",&head);

queue[0]=head;

printf("\n");

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


for(j=0;j<=n-1;j++)

diff=abs(queue[j+1]-queue[j]);

seek+=diff;

printf("Move from %d to %d with Seek %d\n",queue[j],queue[j+1],diff);

printf("\nTotal Seek Time is %d\t",seek);

avg=seek/(float)n;

printf("\nAverage Seek Time is %f\t",avg);

return 0;

"fcfs_disk_scheduling.c" 31L, 783C written

[******@telnet ~]$ ./fcfs_disk_scheduling.out

==============================================================

Demonstration of FCFS Disk Scheduling

==============================================================

Enter the size of Queue 8

Enter the Queue 98

183

37

122

14

124

65

67

Enter the initial head position 53

Move from 53 to 98 with Seek 45

Move from 98 to 183 with Seek 85

Move from 183 to 37 with Seek 146

Move from 37 to 122 with Seek 85

Move from 122 to 14 with Seek 108

Move from 14 to 124 with Seek 110

Move from 124 to 65 with Seek 59


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Move from 65 to 67 with Seek 2

Total Seek Time is 640

Average Seek Time is 80.000000

[******@telnet ~]$

RESULT:

Thus, the FCFS disk scheduling algorithm has been written and executed successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex.No 15B SSTF DISK SCHEDULING

AIM:

To implement Unix C program for SSTF disk scheduling algorithm.

ALGORITHM:

STEP 1: Let Request array represents an array storing indexes of tracks that have been requested.
'head' is the position of disk head.

STEP 2: Find the positive distance of all trade in the request array from head.

STEP 3: Find a track from requested array which has not been accessed / serviced yet and has
minimum distance from head.

STEP 4: Increment the total seek count with the distance

STEP 5: Currently serviced track position now becomes the new head position.

STEP 6: Go to step2 until all tracks in request array have not been serviced.

PROGRAM:

#include<stdio.h>

#include<math.h>

int main()

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

float avg;

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 position\t");

scanf("%d",&head);

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

t[i]=abs(head-queue[i]);

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


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;

"sstf.c" 44L, 717C written

[******@telnet ~]$ ./sstf.out

*** SSTF Disk Scheduling Algorithm ***

Enter the size of Queue 8

Enter the Queue 98

183

37

122

14
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
124

65

67

Enter the initial head position 53

Total Seek Time is 236

Average Seek Time is 22.125000

[******@telnet ~]$

RESULT:

Thus, the SSTF disk scheduling algorithm has been written and executed successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


ExNo.15c C-SCAN DISK SCHEDULING

AIM:

To implement Unix C program for C-SCAN disk scheduling algorithm.

ALGORITHM:

STEP 1: Arrange all the I/o request in ascending order.

STEP 2: The head will start moving in the right direction i.e from the 0 to size of the block.

STEP 3: When a request is encountered head movement is calculated.

Hed movement = current request-previous request

STEP 4: While moving in the right direction calculate the distance of the track from the head
movement.

STEP 5: Increment the total seek court with the distance.

STEP 6: Currently serviced track now become the new head.

STEP 7: This process is repeated until the head reaches.

STEP 8: If we reach the end, head will go from right to left and again stouts moving in the right
direction.

STEP 9: This process is completed, when all the requests are processed.

PROGRAM:

#include<stdio.h>

int main()

int queue[20],n,head,i,j,k,seek=0,max,diff,temp,queue1[20],queue2[20],temp1=0,temp2=0;

float avg;

printf("Enter the max range of disk\n");

scanf("%d",&max);

printf("Enter the initial head position\n");

scanf("%d",&head);

printf("Enter the size of queue request\n");

scanf("%d",&n);

printf("Enter the queue of disk positions to be read\n");

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

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


{

scanf("%d",&temp);

if(temp>=head)

queue1[temp1]=temp;

temp1++;

else

queue2[temp2]=temp;

temp2++;

for(i=0;i<temp1-1;i++)

for(j=i+1;j<temp1;j++)

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

temp=queue1[i];

queue1[i]=queue1[j];

queue1[j]=temp;

for(i=0;i<temp2-1;i++)

for(j=i+1;j<temp2;j++)

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

temp=queue2[i];

queue2[i]=queue2[j];

queue2[j]=temp;
CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
}

for(i=1,j=0;j<temp1;i++,j++)

queue[i]=queue1[j];

queue[i]=max;

queue[i+1]=0;

for(i=temp1+3,j=0;j<temp2;i++,j++)

queue[i]=queue2[j];

queue[0]=head;

for(j=0;j<=n+1;j++)

diff=abs(queue[j+1]-queue[j]);

seek+=diff;

printf("Disk head moves from %d to %d with seek %d\n",queue[j],queue[j+1],diff);

printf("Total seek time is %d\n",seek);

avg=seek/(float)n;

printf("Average seek time is %f\n",avg);

return 0;

Output:

[******@telnet ~]$ cc cscan.c -o cscan.out

[******@telnet ~]$ ./cscan.out

Enter the max range of disk

200

Enter the initial head position

50

Enter the size of queue request

Enter the queue of disk positions to be read

90 120 35 122 38 128 65 68

Disk head moves from 50 to 65 with seek


CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE
Disk head moves from 65 to 68 with seek

Disk head moves from 68 to 90 with seek

Disk head moves from 90 to 120 with seek

Disk head moves from 120 to 122 with seek

Disk head moves from 122 to 128 with seek

Disk head moves from 128 to 200 with seek

Disk head moves from 200 to 0 with seek

Disk head moves from 0 to 35 with seek

Disk head moves from 35 to 38 with seek

Total seek time is 388

Average seek time is 48.500000

RESULT:

Thus, the C-Scan disk scheduling algorithm has been written and executed successfully.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Ex.No:16 INSTALL ANY GUEST OPERATING SYSTEM USING VMWARE

AIM:

To install any guest operating system (linux) using vmware.


PROCEDURE:

Install any Guest Operating System like Linux using VM ware


Steps to install and configure VMWare:
Step 1: Download and VMWare workstation. Set up is around 307MB. Currently,
version 12 is available. Please note we have set up screens on version 11.
Step 2: Install VMWare on your machine. Setup is simple and requires clicking Next
button a couple of times.
Step 3: After installation open the VMWare workstation by using either the start menu
or shortcut created on the desktop.
Step 4: Click on “Create a New Virtual Machine”.

Step 5: With default “Typical” selected click on the Next button.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Step 6: Specify the path of the operating system setup file.

Step 7: In the Next step you need to specify a key or a serial number of the operating
system. If you are using the trial version then that part can be skipped.
Step 8: Enter the name for the virtual machine and specify a path to the directory
where you want to create your virtual machine. It is recommended that the drive
you're selecting to install a virtual machine should have sufficient space.

Step 9: Specify the amount of disk space you want to allocate for a virtual machine.
Allocate disk space according to the size of the software you are going to install on the
virtual machine.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Step 10: On the next screen it will show the configuration your selected for a virtual
machine.

Step 11: It will allocate Hardware according to the default settings but you can
change it by using Customize Hardware button in the above screen.
You can specify what amount of RAM, a processor has to be allocated for a virtual
Also, do not allocate very little RAM or processor. Leave default settings or allocate
in machine. Do not allocate complete RAM or a complete Processor for a virtual
machine, such a way that your application should be able to run on the virtual
machine. Else it will result in a slow virtual machine.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE


Step 12: Click on the Finish button to create the virtual machine at the
specified location and with specified resources.
If you have specified a valid file (.iso, .rar., nrg) for the operating system it
will take standard time to complete the operating system setup on the
virtual machine, and then it will be ready to use your regular.

Result:
Thus, guest operating system Linux installed using vmware.

CS3461-OPERATING SYSTEMS LABORATORY E SHAPNA RANI, AP-CSE

You might also like