0% found this document useful (0 votes)
2 views

OS lab Manual

The document outlines various exercises related to the installation of Windows operating systems and the basics of UNIX commands, including file manipulation, directory commands, and general-purpose commands. It also includes shell programming exercises for converting Fahrenheit to Centigrade, calculating area and circumference of a circle, computing simple interest, swapping two numbers, checking even or odd numbers, finding the biggest of three numbers, and designing a simple calculator. Each section provides aims, algorithms, program codes, and outputs demonstrating successful execution.

Uploaded by

it2022boys
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

OS lab Manual

The document outlines various exercises related to the installation of Windows operating systems and the basics of UNIX commands, including file manipulation, directory commands, and general-purpose commands. It also includes shell programming exercises for converting Fahrenheit to Centigrade, calculating area and circumference of a circle, computing simple interest, swapping two numbers, checking even or odd numbers, finding the biggest of three numbers, and designing a simple calculator. Each section provides aims, algorithms, program codes, and outputs demonstrating successful execution.

Uploaded by

it2022boys
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 132

Ex.

No:1 INSTALLATION OF WINDOWS OPERATING SYSTEM


Date:

AIM:
To study about Installation of Windows Operating Systems.
PROCEDURE:
Installing a Windows operating system
The wizard provides a step by step guidance for installing an operating system. Follow the
instructions on the screen and the tips listed below to install a Windows operating system.
1. Drive Selection
Figure 1. Drive Selection step (for Windows)

Attention: The selected drive will be formatted during the installation. Back up all data on it
before the installation.
Note: The drivers will be installed automatically after the OS installation. It is recommended to
restart your server to ensure that all installed drivers take effect.
2. OS Selection
Figure 2. OS Selection step (for Windows)
The IP address is made up of four parts separated by dots. The following table lists the valid
value range for each part.
IP Address Part 1 Part 2 Part 3 Part 4
Valid values 1 – 223 0 – 255 0 – 255 0 – 255
3. Installation Settings
Figure 3. Installation Settings step – 1 (for Windows)

Administrator Password: You can change your administrator password later from the operating
system.
If you want to do advanced configurations, expand the list by clicking the arrow icon next
to Advanced.
Figure 4. Installation Settings step – 2 (for Windows)

Refer to the following table for the valid values when you type the required address information.
Address Part 1 Part 2 Part 3 Part 4
IP Address 1 – 126; 128 – 223 0 – 255 0 – 255 1 – 254
Subnet Mask 0 – 255 0 – 255 0 – 255 0 – 255
Default Gateway 0 – 255 0 – 255 0 – 255 0 – 255
Preferred DNS Server 1 – 126; 128 – 223 0 – 255 0 – 255 0 – 255
Alternate DNS Server 1 – 126; 128 – 223 0 – 255 0 – 255 0 – 255
Figure 5. Installation Settings step – 3 (for Windows)
Components: You can select one or more components for installation according to your
requirements.
Include run-once commands: If you want to run specified commands at the end of the
installation process, select the check box. A command-type area is displayed. Type one
command and click Add. The command is added to the command list. You can add five
commands at most. If you want to remove a certain command, select it and click Remove. The
commands in the command list will be run one time only and in the order you type them.
4. Partition Options
Figure 6. Partition Options step (for Windows)

If no existing partition is detected on the drive, select Repartition the drive during installation.

RESULT:
The above program has been executed successfully
Ex.No:2.a BASICS OF UNIX COMMANDS
Date:

AIM
To study various UNIX command in detail.

FILE MANIPULATION COMMANDS

Command : Cat
Purpose : It is used to display the contents of the file as well as used to create a new file.

Syntax : cat <file name >


Example : $ cat devi

Command : More

Purpose : It is used to display the contents of the file on the screen at a time.

Syntax : more <file name >


Example : $ more devi

Command : Wc

Purpose : It is used to count the number of lines ,words and characters in a file or group of files.

Syntax : wc [options] <file name >


Example : $ wc –l devi

Command : File

Purpose : It is used to determine the type of the file.

Syntax : file <file name >


Example : $ file devi

Command : Spell

Purpose : It is used to find the spelling errors in the file.

Syntax : spell [options] <file name >


Example : $ spell -b devi
Command : Split

Purpose : It is used to split the given file into smaller pieces of given size.
Syntax : split –size <file name > < splitted file name >
Example : $ split –2 devi de

Command : Cp

Purpose : It is used to copy one or more files.

Syntax : cat <source file name > <destination file name>


Example : $ cp devi latha

Command : Mv

Purpose : It is used to move a file within a directory with different names and also used to move
a file to different directory with its original name.

Syntax : mv <source file name > <destination file name>


Example : $ mv devi jeya

Command : Rm

Purpose : It is used to remove a file from the disk.

Syntax : rm <file name >


Example : $ rm devi

Command : chmod
Purpose : It is used to change the file permissions. In the terminal, the command to use to change
file permission is “ chmod “. In short, “chmod 777” means making the file readable, writable
and executable by everyone.

Syntax : chmod file_permission <file name


> Example : $ chmod 777 devi

DIRECTORY COMMANDS AND PROCESS MANAGEMENT COMMANDS


Command : mkdir
Purpose : It is used to create new directory or more than one directory.

Syntax : mkdir <directory name >


Example : $ mkdir riya
Command : rmdir
Purpose : It is used to remove the directory if it is empty.

Syntax : rmdir <directory name >


Example : $ rmdir riya

Command : cd

Purpose : It is used to change the control from one working directory to another specified
directory.

Syntax : cd <directory name >


Example : $ cd riya

Command : cd ..

Purpose : It is used to quit from current directory and move to the previous
directory.

Syntax : cd ..
Example : $ cd ..

GENERAL PURPOSE COMMANDS


Command : Banner
Purpose : It is used to display its argument in large letters.

Syntax : banner < string >


Example : $ banner BOOM

Command : Who
Purpose : It is used to get the information about all the users currently working in the system.

Syntax : who
Example : $ who

Command : Who am i

Purpose : It is used to know in which terminal the user is currently logged on.

Syntax : who am i
Example : $ who am I
Command : Date
Purpose : It is used to display the system date and time.

Syntax : date
Example : $ date

Command : Cal

Purpose : It prints the calender for the specified year and month.

Syntax : cal <month> <year>


Example : $ cal 05 2003

Command : Id
Purpose : It is used to display the login name.

Syntax : id
Example : $
id

Command : Clear

Purpose : It is used to clear the screen.

Syntax : clear
Example : $ clear

Command : Uname

Purpose : It is used to display the details about the OS in which we are working.

Syntax : uname [options]


Example : $ uname –n

Command : Tty

Purpose : It is used to know the terminal name on which we work.

Syntax : tty
Example : $ tty

Command : Pwd
Purpose : It is used to display the absolute pathname of current working directory.
Syntax : pwd
Example : $ pwd

Command : Bc

Purpose : It is used to perform simple mathematical calculations.

Syntax : bc <operation>
Example : $ bc 3+5 8 ^d

Command : Ls

Purpose : It is used to display the files in the current working directory.

Syntax : ls [options] <arguments>


Example : $ ls –p

Command : Echo

Purpose : It echoes the argument on the standard output device.

Syntax : echo [options] <string>


Example : $ echo “HELLO WORLD”

Command : Man
Purpose : It gives details about the unix commands.

Syntax : man < command name >


Example : $ man echo

COMMAND GROUPING & FILTER COMMANDS


Command : Head

Purpose : It is used to display the top portion of the file.

Syntax : head [options] <file name>


Example : $ head -5 devi

Command : Tail

Purpose : It is used to display the bottom portion of the file.

Syntax : tail [options] <file name >


Example : $ tail –5 devi

Command : Pr
Purpose : It is used to display the contents of the file by separating them into pages and each
page begins with the header information.

Syntax : pr [options] <file name >


Example : $ pr devi

Command : Cut
Purpose : It is used to extract selected fields or columns from each line of one or more files and
display them on the standard output device.

Syntax : cut [options] <file name >


Example : $ cut –c5 devi

Command : Paste
Purpose : It concatenates the line from each input file column by column with tab characters in
between them.

Syntax : paste [options] <file name >


Example : $ paste f1 f2

Command : Join

Purpose : It is used to extracts common lines from two sorted files and there should be the
common field in both file.

Syntax : join [options] <file name1 > <file name 2>


Example : $ join –a1 f1 f2

Command : Uniq
Purpose : It compares adjacent lines in the file and displays the output by eliminating duplicate
adjacent lines in it.

Syntax : uniq [options] <file name >


Example : $ uniq -c devi

Command : Sort

Purpose : It sorts one or more files based on ASCII sequence and also to merge the file.
Syntax : sort [options] <file name >
Example : $ sort -r devi

Command : Nl
Purpose : It is used to add the line numbers to the file.

Syntax : nl [options] [filename]


Example : $ nl devi

Command : grep
Purpose : It is used to search the specified pattern from one or more files.

Syntax : grep [options] <pattern> <file name >


Example : $ grep “anand” devi

RESULT:

The above program has been executed successfully


SHELL PROGRAMMING

EX NO:2.B FARENHEIT TO CENTIGRADE


CONVERSION DATE:

AIM
To write a shell PROGRAM to convert the given Fahrenheit value to centigrade value.

ALGORITHM
Step 1 : Start
Step 2 : Read Fahrenheit value
Step 3 : Convert Fahrenheit to centigrade using the formulae: (Fahrenheit – 32) × 5/9
Step 4 : Print centigrade
Step 5 : Stop

PROGRAM (degconv.sh)
# Degree conversion
echo "Enter Fahrenheit : "
read f
c=`expr \( $f - 32 \) \* 5 / 9`
echo "Centigrade is : $c"

OUTPUT
[Cse@localhost ~]$ sh degconv.sh
Enter Fahrenheit : 213
Centigrade is : 100

RESULT
The above program has been executed successfully
EX NO: 2.C AREA AND CIRCUMFERENCE OF A
CIRCLE DATE:
AIM
To write a shell PROGRAM to find area and circumference of the circle

ALGORITHM
Step 1: Start
Step 2: read the value of radius in r
Step 3: Calculate area using the formula 3.14*r*r
Step 4: Calculate circumference using the formula 2*3.14*r
Step 5: print the area and circumference
Step 6: stop

PROGRAM (area.sh)
echo "Enter the radius of the circle"
read r
area=`expr 22 / 7 \* $r \* r`
cf=`expr 2 \* 22 / 7 $r`
echo "Area of circle=
$area"
echo "circumference of circle= $cf"

OUTPUT
[Cse@localhost ~]$ sh area.sh
Enter the radius of the circle
3
Area of circle= 28
Circumference of circle= 18

RESULT
The above program has been executed successfully
EX NO:2.D SIMPLE INTEREST
CALCULATION DATE:
AIM
To write a shell PROGRAM to calculate simple interest.

ALGORITHM
Step 1 : Start
Step 2 : Read the values principal, rate and years
Step 3 : Compute simpleinterest using the formulae: (principal × rate × years) / 100
Step 4 : Print simpleinterest
Step 5 : Stop PROGRAM

PROGRAM (simpint.sh)
echo "Enter Principal amount : "
read p
echo "Enter number of years : "
read n
echo "Enter rate of interest : "
read r
si=`expr "scale=2; $p * $n *$r / 100" | bc`
echo "Simple Interest : $si"

OUTPUT
[Cse@localhost ~]$ sh simpint.sh
Enter Principal amount : 1285 Enter number of years : 3
Enter rate of interest : 5
Simple Interest: 192.75

RESULT
The above program has been executed successfully
EX NO: 2.E PROGRAM TO SWAP THE TWO
NUMBERS DATE:

AIM
To write a shell PROGRAM to swap the values of two variables without using third variable.

ALGORITHM
Step 1 : Start
Step 2 : Read the values of x and y
Step 3 : Print the value of x and y before swapping
Step 4 : swap the values of two variables without using third variable
Step 5 : Print the value of x and y after swapping
Step 6 : Stop the PROGRAM

PROGRAM(swap.sh)
echo "Enter the value of x and y"
read x y
echo "Before swapping x=$x
y=$y" x=`expr $x + $y`
y=`expr $x - $y`
x=`expr $x - $y`
echo "After swapping x=$x y=$y"

OUTPUT
[Cse@localhost ~]$ sh swap..sh
Enter the value of x and y
35
Before swapping x=3 y=5
After swapping x=5 y=3
RESULT
The above program has been executed successfully
EX NO: 2.F ODD OR
EVEN DATE:
AIM
To write a shell PROGRAM to check the given number is even or odd.
ALGORITHM
Step 1 : Start
Step 2 : Read number
Step 3 : If number divisible by 2 then Print "Number is Even"
Step 3.1 : else Print "Number is Odd"
Step 4 : Stop
PROGRAM (oddeven.sh)
echo "Enter a non-zero number :
" read num rem=`expr $num % 2`
if [ $rem -eq 0 ]
then
echo "$num is Even"
else
echo "$num is Odd"
fi
OUTPUT
[Cse@localhost ~]$ sh oddeven.sh
Enter a non-zero number: 12
12 is Even

RESULT

The above program has been executed successfully


EX NO: 2.G BIGGEST OF 3
NUMBERS DATE:
AIM
To write a shell PROGRAM to check the biggest number among the three given numbers
ALGORITHM
Step 1 : Start
Step 2 : Read values of a, b and c
Step 3 : If a > b and a > c then Print "A is the biggest"
Step 3.1 : else if b > c then Print "B is the biggest "
Step 3.2 : else Print "C is the biggest"
Step 4 : Stop

PROGRAM (big3.sh)
echo "Give value for A B and C: "
read a b c
if [ $a -gt $b -a $a -gt $c ]
then
echo "A is the Biggest number"
elif [ $b -gt $c ]
then
echo "B is the Biggest number"
else
echo "C is the Biggest number"
fi

OUTPUT
[Cse@localhost ~]$ sh big3.sh
Give value for A B and C: 4 3 6
C is the Biggest number

RESULT
The above program has been executed successfully
EX NO: 2.H SIMPLE
CALCULATOR DATE:
AIM
To write a shell PROGRAM to design the simple calculator using case statement.
ALGORITHM
Step 1 : Start
Step 2 : Read operands a and b
Step 3 : Read option
Step 4 : If option = 1 then Calculate c = a + b
Step 4.1 : else if option = 2 then Calculate c = a – b
Step 4.2 : else if option = 3 then Calculate c = a * b
Step 4.3 : else if option = 4 then Calculate c = a / b
Step 4.4 : else if option = 5 then Calculate c = a % b
Step 4.5 : else Print "Invalid option"
Step 5 : Print c
Step 6 : Stop Shell PROGRAM.

PROGRAM (calc.sh)
echo "Enter the two numbers : "
read a b
echo " 1. Addition"
echo " 2. Subtraction"
echo " 3. Multiplication"
echo " 4. Division"
echo " 5. Modulo Division"
echo "Enter the option : "
read option
case $option in
1) c=`expr $a + $b` echo "$a + $b = $c";;
2) c=`expr $a - $b` echo "$a - $b = $c";;
3) c=`expr $a \* $b` echo "$a * $b = $c";;
4) c=`expr $a / $b` echo "$a / $b = $c";;
5) c=`expr $a % $b` echo "$a % $b = $c";;
*) echo "Invalid Option"
esac
OUTPUT
[Cse@localhost ~]$ sh calc.sh
Enter the two numbers : 2 4
1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Modulo Division
2. Enter the option : 1
3. 2 + 4 = 6
RESULT
The above program has been executed successfully
EX NO: 2.I EXECUTE VARIOUS UNIX COMMANDS USING CASE STATEMENTS
DATE:
AIM
To write a shell PROGRAM to do the execution of various unix commands using case
statement.
ALGORITHM
Step 1 : Start
Step 2 : Read choice from user
Step 3 : Perform the operation of corresponding unix commands as per the choice given
by the user.
Step 4 : Stop Shell PROGRAMming

PROGRAM (case.sh)
echo “Enter your choice”
read choice
case $choice in
1) pwd ;;
2) date ;;
3) ls ;;
4) who am i ;;
5) exit ;;
*)echo “Invalid
choice” esac

OUTPUT:
[Cse@localhost ~]$ sh arithmetic.sh
Enter your choice
3
area.sh simple.sh swap.sh oddoreven.sh leap.sh positive.sh
biggest.sh studentgrade.sh arithmetic.sh

RESULT
The above program has been executed successfully
EX NO: 2.J FACTORIAL OF A GIVEN
NUMBER DATE:
AIM:
To find the factorial of a given number.

ALGORITHM:
Step 1: Begin the
PROGRAM. Step 2: Read the
value of n.
Step 3: set the initial value, fact=1 and i=1.
Step 4: while(i<=n), then fact=fact*i and
i=i+1. Step 5: print fact.
Step 6: End the PROGRAM.

PROGRAM (fact.sh)
echo "Enter the Number :
" read n
f=1
i=1
while [ $i -le $n ]
do
f=`expr $f \* $i`
i=`expr $i + 1`
done
echo "The factorial $n! = $f"

OUTPUT
[Cse@localhost ~]$ sh fact.sh
Enter a positive number : 10
Factorial value : 3628800

RESULT:
The above program has been executed successfully
EX NO: 2.K PROGRAM TO FIND AND DISPLAY STUDENT
GRADE DATE:

AIM
To write a shell PROGRAM for finding and displaying student grade.

ALGORITHM
Step 1 : Start
Step 2 : Read student name, register number and 5 subject marks
Step 3 : If any of the subject mark is < 50 then
Print "fail"
Step 3.1 : else calculate the total and average (avg) for the given marks
Step 4 : if avg > 75 then
Print "First class with distinction"
Step 4.1 : else if avg > 65 then
Print "First Class"
Step 4.2 : else if avg > 65 then
Print "Second Class"
Step 4.3 : else Print "Third class"
Step 5: Stop

PROGRAM (studentgrade.sh)
echo “Enter student name”
read name
echo “Enter the student register no”
read no
echo “Enter the 5 subject marks”
read m1 m2 m3 m4 m5
total=`expr $m1 + $m2 + $m3 + $m4 + $m5`
avg=`expr $total / 5`
echo ” TOTAL MARKS = $total”
echo “AVERAGE = $avg”
if [ $m1 -lt 50 -o $m2 -lt 50 -o $m3 -lt 50 -o $m4 -lt 50 -o $m5 -lt 50 ]
then
echo “RESULT = FAIL”
exit
else
echo “RESULT = PASS”
fi
if [ $avg -ge 75 ]
then
echo “Grade = FIRST CLASS WITH DISTINCTION”
elif [ $avg -ge 65 ]
then
echo “Grade = FIRST CLASS”
elif [ $avg -lt 65 ]
then
echo “Grade = SECOND CLASS”
else
echo “Grade = THIRD CLASS”
fi

OUTPUT
[Cse@localhost ~]$ sh studentgrade.sh
Enter student
name XXX
Enter the student register no
12345
Enter the 5 subject marks
75 80 82 93 90
TOTAL MARKS = 420
AVERAGE = 84
RESULT = PASS
Grade = FIRST CLASS WITH DISTINCTION

RESULT:

The above program has been executed successfully


EX NO: 2.L FIBONACCI SERIES
DATE:
AIM:
To write a PROGRAM to generate the fibbonaci series
ALGORITHM:
Step-1 Begin the
PROGRAM Step-2 Enter the
number
Step-3 Assign a=1 to print first fibonacci value, then assign b=1 for further
operations. Step-4 Set a loop up to the given number.
Step-5: Print 'a' value, then
a=a+b
a=b
b=c, continue the loop upto the given condition.
Step-6 Every increment in the loop prints the value of a (fibonacci
value). Step-7 After the execution of the loop end the PROGRAM

PROGRAM (fibo.sh)
echo "Enter the Limit : "
read n
a=0
b=1
echo "FIBONACCI SERIES"
while [ $a -lt $n ]
do
echo "$a"
c=`expr $a + $b`
a=$b
b=$c
done
OUTPUT
[Cse@localhost ~]$ sh fibo.sh
Enter number of terms : 8
Fibonacci Series
0 1 1 2 3 5 8 13

RESULT:

The above program has been executed successfully


EX NO: 2.M PRIME NUMBER OR
NOT DATE:
AIM:
To write a PROGRAM to find whether the number is prime Or not.
ALGORITHM:
Step 1 : Start
Step 2 : Read the value of n
Step 3 : Initialize i to 2
Step 4 : If n is divisible by i then
Print “Not Prime” and Stop
Step 5 : Increment i by 1
Step 6 : Repeat steps 4 and 5 until i n/2
Step 7 : Print "Prime"
Step 8 : Stop

PROGRAM (prime.sh)
echo "Enter the number : "

read num

i=2

while [ $i -lt $num ]

do

if [ `expr $num % $i` -eq 0 ]

then

break;

fi

i=`expr $i + 1`
done

if [ $i -eq $num -o $num -eq 1 ]

then

echo "The number $num is prime"

else

echo "The number $num is not prime"

fi

OUTPUT
[Cse@localhost ~]$sh prime.sh
Enter the number : 17
The number 17 is prime

RESULT:
The above program has been executed successfully
EX NO: 2.N PALINDROME OR
NOT DATE:
AIM:
To find sum of Digits, Reverse and the given Number is Palindrome or not.
ALGORITHM:
Step-1 Begin the
PROGRAM. Step-2 Enter the
number.
Step-3 when n=num, rev=0 & num>0 then goto step 4.
Step-4 when condition in step 3 is satisfied, perform a=n%10, rev=rev*10+a and n=n/10.
Step-6 Find whether the reverse number is equal to the given number or not.
If equal the number is palindrome
Step-7: If not equal the given number is not
palindrome Step-8: End the PROGRAM.
PROGRAM (palindrome.sh)
echo "Enter the number : "
read num
n=$num
rev=0
while [ $n -gt 0 ]
do
a=`expr $n % 10`
rev=`expr $rev \* 10 +
$a` n=`expr $n / 10`
done

echo "The Reverse of $num is


$rev" if [ $num -eq $rev ]
then
echo "The number $num is Palindrome"
else
echo "The number $num is not Palindrome"
fi
OUTPUT
[Cse@localhost ~]$sh palindrome.sh
Enter the number : 171
The number 171 is Palindrome

RESULT:
The above program has been executed successfully
EX NO: 2.O TO CHECK WHETHER THE GIVEN STRING IS PALINDROME OR NOT
DATE:
AIM:
To write a shell PROGRAM to check whether the given string is palindrome or not.
ALGORITHM:
Step 1:Begin the PROGRAM.

Step 2: Enter the string.

Step 3: Reverse the string by using rev command and assign it into revstr variable.

Step 4: If the given string = revstr, then print the given string is Palindrome. Otherwise print the
given string is NOT Palindrome.

Step 5: End the PROGRAM.


PROGRAM(spalindrome.sh)
echo "Enter the string"

read str

revstr=`echo "$str" | rev`

if [ $str = $revstr ]

then

echo "$str is palindrome"

else

echo "$str is Not a palindrome"

fi
OUTPUT: [Cse@localhost ~]$ sh spalindrome.sh
Enter the string
Malayalam
Malayalam is palindrome
RESULT:
The above program has been executed successfully
EX NO: 2.P PROGRAM TO COUNT THE NUMBER OF VOWELS,
CONSONANTS DATE: AND DIGITS IN THE GIVEN TEXT
AIM
To write a shell script to count the number of vowels, consonants and digits in the given text.
ALGORITHM
Step 1: Begin the PROGRAM.
Step 2: Get the string and find the length of the string.
Step 3: Initially vowel count=0 and consonant count=0.
Step 4: Use while loop and get the character one by one in the string, If it is vowel then take it as
vowel count. If it is not vowel take it as consonant count.
Step 5: Finally print the vowel count and consonant
count. Step 6: End the PROGRAM.

PROGRAM (vowels.sh)

eho "Enter the string"

read str

i=1

vc=0

cc=0

dig=0

len=`echo "$str"|wc -

c` while((i<=len))

do

ch=`echo "$str"|cut -

i` case $ch in
[aAeEiIoOuU]) ((vc++)) ;;

[0123456789]) ((dig++));;

*))((cc++)) ;;

esac

((i++))

done

echo "No of vowels=$vc"

echo "No of

consonants=$cc" echo “No

of Digits=$dig”

OUTPUT:
[Cse@localhost ~]$ sh vowels.sh
Enter the string

Ams2016

No of vowels=1

No of

consonants=2 No

of Digits=4

RESULT
The above program has been executed successfully
PROGRAMS USING SYSTEM CALLS

EX.NO: 3A FORK SYSTEM


CALL DATE:

AIM

To write a UNIX C program to create a child process from parent process using fork()
system call.

ALGORITHM

Step 1: Start the program.


Step 2: Invoke a fork() system call to create a child process that is a duplicate of parent
process. Step 3: Display a message.
Step 4: Stop the program.

PROGRAM

#include<stdio.h>
#include<unistd.h>
main()
{
fork();
printf("Hello World\n");
}

OUTPUT

[it1@localhost ~]$ vi ex1a.c


[it1@localhost ~]$ cc ex1a.c
[it1@localhost ~]$ ./a.out
Hello World
Hello World

RESULT
The above program has been executed successfully
EX.NO: 3.B SIMULATION OF FORK, GETPID AND WAIT SYSTEM CALLS
DATE:

AIM
To write a UNIX C program simulate fork(),getpid() and wait() system call.

ALGORITHM

Step 1: Invoke a fork() system call to create a child process that is a duplicate of parent
process. Step 2: Retrieve the process id of parent and child process.
Step 3: If return value of the fork system call=0(i.e.,child process),generate the fibonacii series.
Step 4: If return value of the fork system call>0(i.e.,parent process),wait until the child
completes.

PROGRAM

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<conio.h>
main()
{
int a=-1,b=1,i,c=a+b,n,pid,cpid;
printf("\nenter no. of terms ");
scanf("%d",&n);
pid=getpid();
printf("\nparent process id is %d",pid);
pid=fork();
cpid=getpid();
printf("\nchild process:%d",cpid);
if(pid==0)
{
printf("\nchild is producing fibonacci series ");
for(i=0;i<n;i++)
{
c=a+b; printf("\n
%d",c); a=b;
b=c;
}
printf("\nchild ends");
}
else
{
printf("\nparent is waiting for child to complete");
wait(NULL); printf("\
nparent ends");
}
}

OUTPUT
[it27@mm4 ~]$ cc fork.c
[it27@mm4 ~]$ a.out

enter no. of terms 5

parent process id is
8723 child process:8723
parent process id is
8723 child process:8732
child is producing fibonacci series
0
1
1
2
3
child endsparent is waiting for child to complete

RESULT

The above program has been executed successfully


EX.NO:3.C EXECUTION OF EXIT SYSTEM
CALL DATE :

AIM
To write a UNIX C program to implement execlp() system call.

ALGORITHM
Step 1:Use fork() system call to create a child process and assigns its id to pid variable.
Step 2: If the pid<0,an error message is displayed.
Step 3:If the pid is equal to zero,execlp() system call is invoked and the child process is
overwritten by the files in the directory.
Step 4:If the pid is greater than zero,display a message.

PROGRAM
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
main()
{
int pid;
pid=fork();
if(pid<0)
{
fprintf(stderr,"fork failed\n");
exit(-1);
}
else if(pid==0)
{
execlp("/bin/ls","ls",NULL);
}
else
{
wait(NULL);
printf("Child Complete");
exit(0);
}
OUTPUT
[it1@localhost ~]$ cc ex1c.c
[it1@localhost ~]$ ./a.out
a1 ara.c arunv ex1aa.c facts itbgals kp matrix.v pre.c rad2.sh rad.c sk
wooow
a2 arain.c baabaaa ex1a.c fib.c k1 lee obu priya rad3.sh rad.sh ss xxx
a.c arav.c cat ex1b.c fio k2 lyffactz os rad1.c rad4.c sat sum.c

RESULT
The above program has been executed successfully
X. NO: 3.D SIMULATION OF I/O SYSTEM
CALLS DATE:
AIM
To write a UNIX C program to simulate I/O system calls such as open, read and write.
ALGORITHM
Step 1: Start the program.
Step 2: Enter the filename to be opened.
Step 3: Using open () system call, open the file in read only mode.
Step 4: Using read () system call, read the content through the file descriptors and put it in a
buffer.
Step 5: Display the content of the buffer.
Step 6: Stop the program.
PROGRAM
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
#include<stdio.h>
int main()
{
int fd;
char buf1[100],fname[30];
printf("Enter the filename:");
scanf("%s",fname);
fd=open(fname,O_RDONLY);
read(fd,buf1,30);
printf("\n The content is %s:",buf1);
close(fd);
}
OUTPUT
[it3@localhost ~]$ cc io.c
[it3@localhost ~]$ ./a.out
Enter the filename:f1
The content is : hi
Hello

RESULT
The above program has been executed successfully
EXP NO:4A
FIRST COME FIRST SERVE SCHEDULING
DATE:

AIM

To write the c program to implement first come first serve CPU scheduling algorithm.

ALGORITHM

1. Start the program.

2. Declare the required variables.

3. Get the no of process and burst time of each process using for loop.

4. Find the waiting time of each process and turnaround time of each process.

5. Find the total waiting time and total turnaround time form individual process.

6. Find the average of waiting and turnaround time of all process.

7. Print the calculated values.

8. Stop the process


PROGRAM

#include<stdio.h>

#include<stdlib.h>
int main()

int i,j,k,l,n,bt[10],wt[10],tn[10];
float avgwt=0,avgtn=0;

printf(" enter the number of process");


scanf("%d",&n);

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

printf(" enter the %d bursttime \n",i);


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

wt[1]=0;

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

{
wt[j+1]=bt[j]+wt[j];

avgwt=avgwt+wt[j];

}
for(k=1;k<=n;k++)

tn[k]=wt[k]+bt[k];

avgtn=avgtn+tn[k];

}
printf(" first come first serve\n");

printf("bt\t wt\t tn\t \n"); for(l=1;l<=n;l++)

printf("%d\t %d\t %d\t \n",bt[l],wt[l],tn[l]);

avgwt=avgwt/n;

avgtn=avgtn/n;

printf(" the average waiting time is %f \n",avgwt); printf(" the average turn around time is %f
\n",avgtn);

}
OUTPUT

enter the number of process3

enter the 1 bursttime

4
enter the 2 bursttime

5
enter the 3 bursttime

6
First come first serve
t
BT wt m

4 0 4

5 4 9

6 9 15

the average waiting time is 4.333333

the average turnaround time is

9.333333

RESULT
The above program has been executed successfully
EXP NO : 4B

SHORTEST JOB FIRST SCHEDULING


DATE:

AIM

To write the c program to implement shortest job first CPU scheduling algorithm.

ALGORITHM

1. Start the program.

2. Declare the required variables.

3. Get the no of process and burst time of each process using for loop.

4. Find the shortest burst time process.

5. Allow that process to run and find the waiting time and

6. turnaround time of process.

7. Continue the step 4 and 5 until no process remaining.

8. Calculate the total waiting and turnaround time of all process.

9. Calculate average waiting time and turnaround time of process.

10. Print the calculated values.

11. Stop the process.


PROGRAM

#include<stdio.h> int

main()

{
int n,i,j,temp,temp1,pr[10],b[10],t[10],w[10],p[10]; float
att=0,awt=0;

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

{ b[i]=0;

w[i]=0;
}
printf("enter the number of processes");
scanf("%d",&n);

printf("enter the burst time");


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

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

p[i]=i;

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

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

{
if(b[i]>b[j])

temp=b[i];
temp1=p[i];

b[i]=b[j];

p[i]=p[j];

b[j]=temp;

p[j]=temp1;

}
}
}

w[0]=0;

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

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

for(i=0;i<n;i++)
{
t[i]=w[i]+b[i];

awt=awt+w[i];

att=att+t[i];
}
awt=awt/n;

att=att/n;

printf("\n\t process\t waiting time\t turnaround time\n");

for(i=0;i<n;i++) printf("\t%d]\t%d\t\t%d\

n",p[i],w[i],t[i]);

printf("the average waiting time is %f\n",awt);

printf("the average turnaround time is %f\n",att);

}
OUTPUT

enter the number of


processes4 enter the burst
time

Process waiting time turnaround time

1 0 4

2 4 9

0 9 15

3 15 21

the average waiting time is 7.000000


the average turnaround time is
5.250000

RESULT

The above program has been executed successfully


EX NO:4C
PRIORITY SCHEDULING
DATE:

AIM

To write the c program to implement priority CPU scheduling algorithm

ALGORITHM

1. Start the program.

2. Declare the required variables.

3. Get the no of process and burst time of each process using for loop.

4. Get the priority of each process.

5. Find the smallest priority number process.

6. Allow that process to execute and calculate the waiting and turnaround time of process.

7. Continue step 5 and 6 until no process is remaining.

8. Calculate the total waiting and turnaround time of all process.

9. Calculate average waiting time and turnaround time of process.

10. Print the calculated values.


PROGRAM

#include<stdio.h>

#include<stdlib.h>
int main()

int i,j,k,l,m,p,n,bt[10],wt[10],tn[10],temp,pr[10];
float avgwt=0,avgtn=0;

printf("enter the number of processor");


scanf("%d",&n);

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

{
printf("enter the %d burst time",i);
scanf("%d",&bt[i]);

printf("enter the %d priority",i);


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

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

for(p=m;p<=n;p++)
{

if(pr[m]>pr[p])
{

temp=pr[m];
pr[m]=pr[p];
pr[p]=temp

temp=bt[m];

bt[m]=bt[p];

bt[p]=temp;
}

wt[1]=0;

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

wt[j]=wt[j-1]+bt[j-1]; avgwt=avgwt+wt[j];

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

tn[k]=wt[k]+bt[k];

avgtn=avgtn+tn[k];

}
printf("PRIORITY SCHEDULING \n");
printf("pr \t bt \t wt \t tn \t \n"); for(l=1;l<=n;l++)
{

printf("%d \t %d \t %d \t %d \t \n",pr[l],bt[l],wt[l],tn[l]);

avgwt=avgwt /n

avgtn=avgtn /n;

printf("the average waiting time is %f\n",avgwt);


printf("the average turn around time is %f\n",avgtn);

printf("enter the %d burst time",i);

}
OUTPUT

enter the number of processor2

enter the 1 burst time2

enter the 1 priority2

enter the 2 burst time3

enter the 2 priority4

PRIORITY SCHEDULING

pr bt wt tn

2 2 0 2

4 3 2 5

the average waiting time is 1.000000

the average turn around time is 3.500000

RESULT
The above program has been executed successfully
EXP NO : 4D
ROUND ROBIN ALGORITHM
DATE:

AIM

To write the c program to implement priority CPU scheduling algorithm.

ALGORITHM

1. Start the program.

2. Declare the required variables.

3. Get the number of process and burst time of each process using for loop.

4. Get the time slice of the process.

5. Take the first process and execute for the given time slice.

6. Take the next process and execute for the given time slice.

7. Continue step 6 until no process is remaining with burst time.

8. Calculate the waiting and turnaround time of each process.

9. Calculate total and average value of waiting and turnaround time.

10. Print the calculated values.

11. Stop the process.


PROGRAM

#include<stdio.h>

#include<string.h>

int main()

char p[10][5];

int et[10],wt[10],timer,count,pt[10],rt,i,j,totwt=0;

int n,found=0,m,tottt=0,tt[10];

float avgwt,avgtt;

printf(" ENTER THE NO OF PROcESS:");


scanf("%d",&n);

for(i=0;i<n;i++)
{
printf(" ENTER THE PROCESS NAME:");
scanf("%s",&p[i]);

printf(" ENTER THE BURST TIME :");


scanf("%d",&pt[i]);
}
printf(" ENTER THE TIME SLICE:");
scanf("%d",&timer);
m=n;

wt[0]=0;

i=0;

do
if(pt[i]>timer)

{
rt=pt[i]-timer;

strcpy(p[n],p[i]);

pt[n]=rt;

et[i]=timer; n+

+;

else

et[i]=pt[i];

} i+

+;
wt[i]=wt[i-1]+et[i-1];

while(i<n);

count=0;

for(i=0;i<m;i++)
{
for(j=i+1;j<=n;j++)
{
if(strcmp(p[i],p[j])==0)

count++;

found=j
}
}
if(found!=0)
{
wt[i]=wt[found]-(count*timer);
count=0;

found=0;
}
}
for(i=0;i<m;i++)
{
tt[i]=wt[i]+pt[i];

totwt+=wt[i];

tottt+=tt[i];
}
avgwt=(float)totwt/m;

avgtt=(float)tottt/m;

for(i=0;i<m;i++)
{
printf("\n %s \t %d\t %d\t %d",p[i],pt[i],wt[i],tt[i]);
}
printf("\n TOTAL WAITING TIME %d \n",totwt); printf("\n Average

waiting time %f",avgwt); printf("\n Total turnaround time %d \n",tottt);

printf("\n Average turnaround time %f",avgtt);

}
OUTPUT

Enter the process name : aa


Enter the burst time:4
Enter the process name : bb
Enter the burst time : 3
Enter the process name : cc
Enter the burst time : 2
Enter the process name : dd
Enter the burst time : 5
Enter the process name : ff
Enter the burst time : 3
Enter the time slice :3

PROCESS BURST WAITING TOTAL


TIME TIME TURNAROUND
TIME
aa 4 11 15
bb 3 3 6
cc 2 6 8
dd 5 12 17
ff 3 11 14

Total waiting time: 43

Average waiting time: 8.600000 Total turnaround time: 60

Average turnaround time: 12.000000

Particulars Marks allocated Marks obtained


Performance 50
Viva-Voce 10
Record 15
Total 75

RESULT

The above program has been executed successfully


EXP NO : 5
IMPLEMENTATION OF INTER-PROCESS COMMUNICATION
DATE:

AIM

To write the c program to implement the inter process communication.

ALGORITHM

1. start the program.

2. Create the sender process

3. Create the message queue using msgget() system call.

4. Write the message to queue using msgsnd() system call.

5. Create the receiver process.

6. Get the queue which is created by sender using queue id.

7. Read the message from queue using msgrcv() system call.

8. Stop the process.


PROGRAM

SENDER PROGRAM

#include <stdio.h>

#include<sys/types.h>

#include <sys/ipc.h>

#include<sys/msg.h>

#include <unistd.h>

#include<string.h>

int main()

int mid;

char mess[20];

printf("\n\n INTER PROCESS COMMUNICATION USING MESSAGE QUEUE...");

mid=msgget(27,IPC_CREAT|0777);

if(mid==-1)

printf("\n\t invalid message id..");


exit(1);
}
printf("\n enter the message text:");
scanf("%s",mess);
msgsnd(mid,mess,strlen(mess),0); printf("\
n\n message has beensent..\n"); printf("\n
the sent message is:%s\n",mess);
}
RECEIVER PROGRAM

#include <stdio.h>

#include<sys/types.h>

#include <sys/ipc.h>

#include<sys/msg.h>

#include <unistd.h>

#include<string.h>

int main()

int i,mid,len; char mess[20];


printf("\n\n INTER PROCESS COMMUNICATION USING MESSAGE QUEUE...");

mid==msgget(27,IPC_CREAT|0777);

if(mid==-1)

printf("\n\t invalid message id..");

exit(0);
}

msgrcv(mid,mess,100,0,0);

printf("\n\n message has been recieved..\n"); printf("\

n\n the recieved message is:%s\n",mess); }


OUTPUT
FOR
SENDER

INTER PROCESS COMMUNICATION USING MESSAGE QUEUE...

enter the message text:hai

message has been sent..

the sent message is:hai

OUTPUT FOR RECEIVER

INTER PROCESS COMMUNICATION USING MESSAGE QUEUE...

message has beenrecieved..


the recieved message is:hai

RESULT

The above program has been executed successfully


EXP NO : 6
IMPLEMENTATION OF MUTUAL EXCLUSION BY
DATE:
SEMAPHORE

AIM

To write a c program to implement producer consumer problem using semaphore.

ALGORITHM

1. Start the program.

2. Declare the semaphore variables mutex=1, full=0, empty=3.

3. Declare the wait(), signal() method.

4. if((mutex==1)&&(empty!=0)) producer produce the item by executing wait() method.

5. Producer stop to produce the item by executing signal() method.

6. if((mutex==1)&&(full!=0)) consumer consumes the item by executing wait() method.

7. Consumer stop to consumes the item by executing signal() method.

8. Stop the program.


PROGRAM

#include<stdio.h>

int mutex=1,full=0,empty=3,x=0; main()

int n;

void producer(); void

consumer(); int

wait(int);

int signal(int); printf("\n1.PRODUCER\n2.CONSUMER\

n3.EXIT\n"); while(1)

{
printf("\nENTER YOUR CHOICE\n");
scanf("%d",&n);

switch(n)

case 1: if((mutex==1)&&(empty!

=0)) producer();

else

printf("BUFFER IS FULL");
break;

case 2: if((mutex==1)&&(full!
=0))
consumer();
else

printf("BUFFER IS EMPTY");
break;

case 3:

exit(0);

break;

int wait(int s)

return(--s);

int signal(int s)

return(++s);
}
void producer()

mutex=wait(mutex);

full=signal(full);

empty=wait(empty);

x++;

printf("\nproducer produces the item%d",x);


mutex=signal(mutex);

void consumer()

mutex=wait(mutex);

full=wait(full);

empty=signal(empty);

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

x--;

mutex=signal(mutex);

OUTPUT

1. PRODUCER

2. CONSUMER

3. EXIT

ENTER YOUR CHOICE 1


producer produces the item1
ENTER YOUR CHOICE

producer produces the item2


ENTER YOUR CHOICE

producer produces the item3


ENTER YOUR CHOICE 1
BUFFER IS FULL
ENTER YOUR CHOICE

consumer consumes item3

ENTER YOUR CHOICE

consumer consumes item2

ENTER YOUR CHOICE

consumer consumes item1

ENTER YOUR CHOICE

BUFFER IS EMPTY

ENTER YOUR CHOICE 3

RESULT
The above program has been executed successfully
EXP NO : 7
IMPLEMENTATION OF DEADLOCK DETECTION
DATE: USING BANKERS ALGORITHM

AIM

To write a c program to implement bankers ALGORITHM for dead lock avoidance

ALGORITHM

1. Start the program.

2. Get the number of process.

3. Get the max need of each process.

4. Get the currently allocated resource for each process.

5. Calculate the remaining need of each process like max-allocation.

6. Get the available no of resource in system.

7. Allocate the resource for each process based on available and need of process.

8. Print the safe sequence of process.

9. Stop the program.


PROGRAM

#include<stdio.h>

void main()

int max[20],all[20],need[20],seq[20],avail,work,i,j=0,d,m,n,e;

printf("Enter no of process");
scanf("%d",&n);

printf("Enter max allocated resources for eachprocess:");


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

printf("max of p %d is",i);

scanf("%d",&max[i]); printf("\

nAllocation of p %d is",i);

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

need[i]=max[i]-all[i];

printf("\nneed of p %d is : %d",i,need[i]);

printf("\nEnter available
resources"); scanf("%d",&avail);

printf("\nMax allocation need \n");


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

printf("%d %d
%d",max[i],all[i],need[i]); m=d=n;

e=m+1;
while(m>0)

if(d==e)

m=0 ;

else

d=e;

e=0;

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

if((need[i]>0)&&(need[i]<=avail))

need[i]=0;

work=all[i]+avail;

avail=work;

seq[j]=i;

m--;

j++;

else

e++;

if(d==e)
printf("\n process are in unsafe state");
else
{

printf("\n process are in safe state"); printf("\

nThe sequence of process is :"); for(i=0;i<n;i+

+)

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

OUTPUT:

Enter the no of process:4


Enter the maximum allocated resources for each process:
Max of process p0:6
Allocation of process p0:2
Need of process p0 is 4.
Max of process p1:8
Allocation of process p1:5
Need of process p1 is 3.
Max of process p2:5
Allocation of process p2:2
Need of process p2 is 3
Max of process p3:6
Allocation of process p3:2
Need of process p3 is 4
Enter the available no.of resources:3
Process max allocated need

P0 6 2 4

P1 8 5 3

P2 5 2 3

P3 6 2 4

Therefore The process is in safe state.

Safe sequence: p1->p0->p2->p3

RESULT

The above program has been executed successfully


EXP NO : 8
IMPLEMENTATION OF DEAD LOCK DETECTION
DATE:

AIM

To write a c program to implement dead lock detection.

ALGORITHM

1. start the program.

2. Get the number of process and resource instance.

3. Get the maximum matrix,allocation matrix,and available resource.

4. Get the need matrix from max and allocation matrix.

5. Display the process,max matrix,allocation matrix,and available resource.

6. Find the safe sequence in system.

7. If sequence present , print no deadlock in system.

8. Else print the list of process cause the deadlock.

9. stop the program.


PROGRAM

#include<stdio.h>

int max[100][100];

int alloc[100][100];

int need[100][100];

int avail[100];

int n,r;

void input();

void show();

void cal();

int main()

int i,j;

printf("********** Deadlock Detection Algo ************\n");

input();

show();

cal();

getch();

return 0;

void input()

int i,j;

printf("Enter the no of Processes\t");

scanf("%d",&n);

printf("Enter the no of resource instances\t");


scanf("%d",&r);

printf("Enter the MaxMatrix\

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

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

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

printf("Enter the AllocationMatrix\

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

for(j=0;j<r;j++)
{
scanf("%d",&alloc[i][j]);
}
}
printf("Enter the availableResources\
n"); for(j=0;j<r;j++)
{
scanf("%d",&avail[j]);

void show()

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

}
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
need[i][j]=max[i][j]-alloc[i][j];
}
}
while(flag)
{
flag=0; for(i=0;i<n;i+
+)
{
int c=0; for(j=0;j<r;j+
+)
{
if((finish[i]==0)&&(need[i][j]<=avail[j]))
{ c+
+;
if(c==r)
{
for(k=0;k<r;k++)
{
avail[k]+=alloc[i][j];
finish[i]=1;
flag=1;
}
if(finish[i]==1)
{
i=n;
}
}
}
}
}
}
j=0;
flag=0;
for(i=0;i<n;i++)
{
if(finish[i]==0)
{
dead[j]=i; j+
+;
flag=1;
}
}
if(flag==1)
{
printf("\n\nSystem is in Deadlock and the Deadlock process are\n");
for(i=0;i<n;i++)
{
printf("P%d\t",dead[i]);
}
}
else
{
printf("\n No Deadlock Occur");
}
}
OUTPUT

RESULT

The program has been executed successfully


EX NO : 9
IMPLEMENTATION OF THREADING
DATE:

AIM

To create the threads in application and make the synchronization using mutex
lock.

ALGORITHM

1. Start the program.

2. Include the pthread.h library file.

3. Create the two child threads using pthread_create() system call.

4. Each thread execute the assigned method dosomething().

5. Synchronization for method dosomething() is given using mutex_lock() method.

6. Main thread call the join() system call to wait for child threads are terminated.

7. Terminate the child threads when task is completed.

8. Terminate the main thread.

9. Stop the process.


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* doSomeThing(void *arg)

unsigned long i = 0;

counter += 1;

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

i<(0xFFFFFFFF);i++);

printf("\n Job %d finished\n", counter);

return NULL;

}
int main(void)

int i = 0;
int err;

while(i < 2)

err = pthread_create(&(tid[i]), NULL, &doSomeThing,

NULL); if (err != 0)

printf("\ncan't create thread :[%s]", strerror(err));

i++;

pthread_join(tid[0], NULL);

pthread_join(tid[1], NULL);

return 0;

OUTPUT

$cc –pthread pthreadexp.c $ ./a.out

Job 1 started

Job 1 finished

Job 2 started

Job 2 finished

Particulars Marks allocated Marks obtained


Performance 50
Viva-Voce 10
Record 15
Total 75

RESULT

The above program has been executed successfully


EXP NO :10
IMPLEMENTATION OF PAGING TECHNIQUE
DATE:

AIM
To write the c program to implement the paging technique.

ALOGORITHM

1. Start the program.

2. Enter the no of pages in program.

3. Enter the no of frames for program.

4. Enter the page table details i.e. frame no for each page if not available put -1.

5. Get the logical address of page from user.

6. Index the page table using page no.

7. Find the frame no and combine with offset(frameno+offset).

8. Display the calculated physical address.

9. Stop the process.


PROGRAM

#include<stdio.h>

#define MAX 50

int main()

{
int page[MAX],i,n,f,ps,off,pno;

printf("\nEnter the no of pages of program");


scanf("%d",&n);

printf("\nEnter page size");


scanf("%d",&ps);

printf("\nEnter no of frames for program");


scanf("%d",&f);

for(i=0;i<n;i++)
page[i]=-1;

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

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


printf("\npageno\tframeno\n-------\t-------");

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

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

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

}
printf("\n\nEnter the logical address(i.e,page no & offset):"); scanf("%d
%d",&pno,&off);
if(page[pno]==-1)

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


else

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

}
OUTPUT

Enter the no of pages of program 5

Enter the page size 2

Enter the no of frames for program 4

Enter the page table

Pageno frameno

0 2

1 3

2 -1

3 8

4 10

Enter the logical address(i.e,page no & offset): 1 8

Physical address(i.e,frame no & offset):3 , 8

RESULT
The above program has been executed successfully
EXP NO :11
IMPLEMENTATION OF MEMORY ALLOCATION METHODS
DATE:

AIM
To write the c program to implement Memory allocation methods technique.

ALOGORITHM

1. Start the program.

2. Enter the no of pages in program.

3. Enter the no of frames for program.

4. Enter the page table details i.e. frame no for each page if not available put -1.

5. Get the logical address of page from user.

6. Index the page table using page no.

7. Find the frame no and combine with offset(frameno+offset).

8. Display the calculated physical address.

9. Stop the process.


PROGRAM

a)WORST-FIT

#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
clrscr();
printf("\n\tMemory Management Scheme - First Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n"); for(i=1;i<=nb;i+
+)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
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)
{
ff[i]=j;
break;
}
}
}
frag[i]=temp;
bf[ff[i]]=1;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++) printf("\n%d\t\t%d\t\t%d\t\t%d\t\t
%d",i,f[i],ff[i],b[ff[i]],frag[i]); getch();
}

INPUT
Enter the number of blocks: 3
Enter the number of files: 2

Enter the size of the blocks:-


Block 1: 5
Block 2: 2
Block 3: 7

Enter the size of the files:-


File 1: 1
File 2: 4

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

b) Best-fit

#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
static int bf[max],ff[max];
clrscr();
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n"); for(i=1;i<=nb;i+
+)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
if(lowest>temp)
{
ff[i]=j;

lowest=temp;
}
}
}
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
}
printf("\nFile No\tFile Size \tBlock No\tBlock Size\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]); getch();
}

INPUT
Enter the number of blocks: 3
Enter the number of files: 2

Enter the size of the blocks:-


Block 1: 5
Block 2: 2
Block 3: 7

Enter the size of the files:-


File 1: 1
File 2: 4

OUTPUT
File No File Size Block No Block
Size Fragment
1 1 2 2

2 4 1 5

c) First-fit

#include<stdio.h>
#include<conio.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];
clrscr();
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("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{

for(j=1;j<=nb;j++)
{
if(bf[j]!=1) //if bf[j] is not allocated
{
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:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++) printf("\n%d\t\t%d\t\t%d\t\t%d\t\t
%d",i,f[i],ff[i],b[ff[i]],frag[i]); getch();
}

INPUT

Enter the number of blocks: 3


Enter the number of files: 2

Enter the size of the blocks:-


Block 1: 5
Block 2: 2
Block 3: 7

Enter the size of the files:-


File 1: 1
File 2: 4

OUTPUT
File No File Size Block No Block
Size Fragment
1 1 3 7

2 4 1 5

RESULT

The above program has been executed successfully


EXP NO :12A
FIFO PAGE REPL ACEMENT ALGORITHM
DATE:

AIM

To write a c program to implement FIFO page replacement ALGORITHM

ALGORITHM

1. Start the process

2. Declare the size with respect to page length

3. Check the need of replacement from the page to memory

4. Check the need of replacement from old page to new page in memory

5. Form a queue to hold all pages

6. Insert the page require memory into the queue

7. Check for bad replacement and page fault

8. Get the number of processes to be inserted

9. Display the values

10. Stop the process


PROGRAM

#include<stdio.h>

int main()

int i,j,n,a[50],frame[10],no,k,avail,count=0;

printf("\n ENTER THE NUMBER OFPAGES:\

n");

scanf("%d",&n);

printf("\n ENTER THE PAGE NUMBER:\n");


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

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

printf("\n ENTER THE NUMBER OF FRAMES:");


scanf("%d",&no);

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

frame[i]= -1;

j=0;

printf("\tref string\t page frames\n");


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

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

avail=0;

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

if(frame[k]==a[i])

avail=1;

if (avail==0)

{
frame[j]=a[i];

j=(j+1)%no; count+

+; for(k=0;k<no;k+

+)

printf("%d\t",frame[k]);

printf("\n");

}
printf("Page Fault Is%d",count);

}
OUTPUT

ENTER THE NUMBER OF PAGES : 12

ENTER THE PAGE NUMBER : 1 2 3 4 1 2 5 1 2 3 4 5


ENTER THE NUMBER OF FRAMES : 3

ref string page frames

1 1 -1 -1

2 1 2 -1

3 1 2 3

4 4 2 3

1 4 1 3

2 4 1 2

5 5 1 2

3 5 3 2

4 5 3 4

No. of Page Fault Is: 9

RESULT

The above program has been executed successfully


EXP NO :12B
LRU PAGE REPLACEMENT
DATE:

AIM

To write a c program to implement LRU page replacement algorithm.

ALGORITHM

1. Start the program

2. Get the no. of pages, reference strings and the no. of frames.

3. Now find the page no. that has not been used for the longest period of time and
replace those page numbers with new arriving page numbers.

4. Record the number of page faults that has occurred during the page replacement

5. Stop the program


PROGRAM

#include<stdio.h>

main()

{
int q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20];

printf("Enter no of pages:");

scanf("%d",&n);

printf("Enter the reference

string:"); for(i=0;i<n;i++)

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

printf("Enter no of frames:");
scanf("%d",&f);

q[k]=p[k]; printf("\n\t%d\

n",q[k]); c++;

k++;

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

{ c1=

0;

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

{
if(p[i]!=q[j])

c1++;

if(c1==f)
{ c+

+;

if(k<f)

q[k]=p[i];

k++;

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

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

printf("\n");

else
{

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

{ c2[r]=

0;

for(j=i-1;j<n;j--)
{
if(q[r]!=p[j])

c2[r]++;

else

break;

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

b[r]=c2[r];
for(r=0;r<f;r++)

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

if(b[r]<b[j])

t=b[r];

b[r]=b[j];

b[j]=t;

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

if(c2[r]==b[0])

q[r]=p[i]; printf("\t

%d",q[r]);

printf("\n");

}
}

printf("\nThe no of page faults is %d",c);

}
OUTPUT

Enter no of pages:10

Enter the reference string:7 5 9 4 3 7 9 6 2 1

Enter no of frames:3

7 5

7 5 9

4 5 9

4 3 9

4 3 7

9 3 7

9 6 7

9 6 2

1 6 2

The no of page faults is 10

RESULT

The above program has been executed successfully


EXP NO:12C
OPTIMAL PAGE REPLACEMENT
DATE:

AIM

To write a c program to implement OPTIMAL page replacement ALGORITHM

ALGORITHM

1. Start the process

2. Declare the size with respect to page length

3. Check the need of replacement from the page to memory

4. Check the page that will not be used for the longest period of time.

5. Form a queue to hold all pages

6. Insert the page require memory into the queue

7. Check for bad replacement and page fault

8. Get the number of processes to be inserted

9. Display the values

10. Stop the process


PROGRAM

#include<stdio.h>

main()

int fr[5],i,j,k,t[5],p=1,flag=0,page[25],psz,nf,t1,u[5];

printf("enter the no of frames:\n");

scanf("%d",&nf);

printf("\n enter the pagesize");

scanf("%d",&psz);

printf("\n enter the page sequence:");

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

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

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

+) fr[i]=-1;

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

{
if(full(fr,nf)==1)

break;

else

flag=0;

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

{
if(page[i]==fr[j])

flag=1;

printf(" \t%d:\t",page[i]);

break;

if(flag==0)

fr[p]=page[i];

p++;

for(j=1; j<=nf; j+
+) printf(" %d
",fr[j]);

printf("\n");

}
}

p=0;

for(; i<=psz; i++)

flag=0;

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

if(page[i]==fr[j])
{

flag=1;

break;

if(flag==0)

{ p+

+;

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

for(k=i+1; k<=psz; k++)

if(fr[j]==page[k])

u[j]=k;

break;

else

u[j]=21;

for(j=1; j<=nf; j+

+) t[j]=u[j];
for(j=1; j<=nf; j++)

for(k=j+1; k<=nf; k++)

if(t[j]<t[k])

t1=t[j];

t[j]=t[k];

t[k]=t1;

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

if(t[1]==u[j])

fr[j]=page[i];

u[j]=i;

printf("page fault\t");

else printf("\

t");
printf("%d:\t",page[i]);

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

printf(" %d ",fr[j]);

printf("\n");

printf("\n total page faults: %d",p+3);

int full(int a[],int n)

int k;

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

if(a[k]==-1)

}
OUTPUT

Enter no.of frames :5

Enter page size:2

Enter page sequence 1 2 3

1: 1 -1 -1 -1 -1

2: 1 2 -1 -1 -1

3: 1 2 3 -1 -1

RESULT
The above program has been executed successfully
EXP NO : 13
IMPLEMENTATION OF FILE ORGANIZATION TECHNIQUES

DATE:

AIM

To write a c program for the implementation of single level directory.

ALGORITHM

1. Start the program.

2. Get number of directories and name of the directories.

3. Get size of directory and filename.

4. Display the directory and its size.

5. Display the filename.

6. stop the program.

PROGRAM

#include<stdio.h>
void main()
{
int master,s[20];

char f[20][20][20]; char d[20][20];

int i,j;
printf("enter number of master directorios:");
scanf("%d",&master);
printf("enter names of master directories:");
for(i=0;i<master;i++)
scanf("%s",&d[i]);

for(i=0;i<master;i++)
printf("enter size of master directorie:%s",d[i]); scanf("%d",&s[i]);

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

printf("enter the file names of master directory:%s",d[i]); for(j=0;j<s[i];j++)

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

printf("\n");

printf(" directory\tsize\tfilenames\n");

printf("*************************************************\n");

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

printf("%s\t\t%2d\t",d[i],s[i]);

for(j=0;j<s[i];j++) printf("%s\

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

printf("\t\n");

}
OUTPUT

Enter the no of master

directory 2

Enter the names of master directory Master1

Master2

Enter the size of master directory:Master1 2

Enter the size of master directory:Master1 3

Enter the file names of master directory:Master1 aa

bb

Enter the file names of master directory:Master1 cc

dd

ee

directory size filenames

********************************************

Master1 2 aa bb
Master2 3 cc dd ee

Particulars Marks allocated Marks obtained


Performance 50
Viva-Voce 10
Record 15
Total 75
RESULT
The above program has been executed successfully
EXP NO : 14A
INDEXED FILE ALLOCATION TECHNIQUE
DATE:

AIM

To write the c program for implement the Indexed file allocation technique.

ALGORITHM

1. Start the program.

2. Declare the structure file.

3. Get the file name and file size.

4. Get the segment size of the disk.

5. Allocate the required no of free segment to that file.

6. Select one segment as an index for the given file and store all the allocated blocks to
that segment.

7. Print the allocated segment along with its index.

8. Stop the process


PROGRAM

#include<stdio.h>

#include<stdlib.h>

struct file

char name[20];
int size;

}file;

int mem[200];
void indexed()

int loc[30],count=0,i,j,n,first=-1; printf("\

nEnter memory segment size:");

scanf("%d",&n);

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

if(mem[i]==1)

first=i;

mem[first]=1;

break;

for(i=0,j=0;i<200;i++)
{
if((mem[i]==-1)&&(file.size >0))

loc[j]=i;

count++;

j++; file.size-=n;

else if(file.size<=0)

loc[j]=-1; j++;

break;

printf("%s :- ",file.name); for(i=0;i<=count;i++)

printf("\n %d -> %d",first,loc[i]);

printf("\n");

}
int main()
{

int i;
for(i=0;i<200;i++)
{

mem[i]=1;

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

{
if((i%2!=0)&&(i%3!=0))

mem[i]=-1;

printf("\nEnter file name:");

scanf("%s",file.name);

printf("\nEnter file size: ");

scanf("%d",&file.size);

indexed();

}
OUTPUT

[cs28103@localhost cs28103]$ cc indexed.c

[cs28103@localhost cs28103]$ ./a.out

Enter file name: file1

Enter file size: 23

Enter memory segment size: 3


pmr :-

1 -> 5

1 -> 7

1 -> 11

1 -> 13

1 -> 17

1 -> 19

1 -> 23

1 -> 25

1 -> -1

RESULT
The above program has been executed successfully
EXP NO : 14B
SEQUENTIAL FILE ALLOCATION
DATE:

AIM

To write the c program for implement the sequential file allocation technique.

ALGORITHM

1. Start the program.

2. Declare the required variable.

3. Get the starting block and length of file.

4. Allocate the file to disk.

5. Print the allocated block.

6. Stop the process


PROGRAM

#include<stdio.h>
#include<stdlib.h>

main()

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

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

f[i]=0;

X:

printf("\n enter starting block & length of files");


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

printf("\n file not allocated(yes-1/no-0)");


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

if(f[k]==0)

count++;

if(len==count)

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

if(f[i]==0)

{ f[j]=

1;

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

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

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

}
}

else
printf("file is not allocated");
count=0;
printf("\n if u want to enter more files(y-1/n-0)");
scanf("%d",&c);

if(c==1)

goto X;

else

exit(0);

}
OUTPUT

[cs28103@localhost cs28103]$ cc sequential.c [cs28103@localhost cs28103]$ ./a.out

Enter the starting block and length of the file 4 5

The file is allocated to following blocks 4 5 6 7 8

if u want to enter more files(y-1/n-0) 1 5 4

File is not allocate

RESULT The above program has been executed successfully


EXP NO : 14C
LINKED LIST ALLOCATION
DATE:

AIM

To write the c program for implement the linked list file allocation technique.

ALGORITHM

1. Start the program.

2. Declare the two structure file and link.

3. Get the file name and file size.

4. Get the segment size of the disk.

5. Allocate the required no of free segment to that file using linked list.

6. Print the allocated block with its number.

7. Stop the process.


PROGRAM

#include<stdio.h>

struct file

char name[20];
int size;

}file;

struct link

{
int present,next;

}ln[100];

int mem[200];

void linked()

{
int first=-1,count=0,i=0,j=0,n; printf("\

nEnter memory segment size:");

scanf("%d",&n);

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

{
if(mem[i]==-1)
{
first=i;
break;

}
}

ln[0].present=first;
for(i=1,j=1;i<200;i++)

if(mem[i]==-1)

file.size-=n;

ln[j].present=i;

ln[j-1].next=ln[j].present;

count++;

j++;

if(file.size<=0)

ln[j-1].next=-1;
break;

printf("%s : %d ",file.name,first);

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

printf(" -> %d ",ln[i].next);

int main()

{
int i; for(i=0;i<200;i++)

mem[i]=1;
}
for(i=0;i<200;i++)
{ if((i%2!=0)&&(i%3!
=0))
{
mem[i]=-1;
}
}
printf("\nEnter file name: ");

scanf("%s",file.name); printf("\nEnter file size: "); scanf("%d",&file.size); linked();

}
OUTPUT

[cs28105@localhost cs28105]$ cc

linked.c [cs28105@localhost

cs28105]$ ./a.out Enter file name: pmr

Enter file size: 25

Enter the block size: 5

pmr : 1 -> 5 -> 7 -> 11 -> 13 -> -1

RESULT The above program has been executed successfully


EX NO : 15A(i)
IMPLEMENTATION OF FCFS DISK SCHEDULING ALGORITHM
DATE:

AIM

To write a program to implement FCFS disk scheduling algorithm.

ALGORITHM

1. Enter all the processes and their burst time.


2. Find waiting time, WT of all the processes.
3. For the 1st process, WT = 0.
4. For all the next processes i, WT[i] = BT[i-1] + WT[i-1].
5. Calculate Turnaround time = WT + BT for all the processes.
6. Calculate average waiting time = total waiting time/no. of processes.
7. Calculate average turnaround time = total turnaround time/no. of processes.
PROGRAM

#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);

// logic for FCFS disk scheduling

for(i=0;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}

printf("Total head moment is %d",TotalHeadMoment);


return 0;

OUTPUT

$cc –fcfs.c $ ./a.out


Enter the number of
Request 8
Enter the Requests Sequence
95 180 34 119 11 123 62 64
Enter initial head position
50
Total head movement is 644

RESULT
The above program has been executed successfully
EX NO : 15A(ii)
IMPLEMENTATION OF SCAN DISK SCHEDULING ALGORITHM
DATE:

AIM
To write a program to implement SCAN disk scheduling algorithm.

ALGORITHM

1. Start the program

2. This algorithm scans all the cylinders of the disk back and forth.
3. Head starts from one end of the disk and move towards the other end servicing all
the requests in between.

4. After reaching the other end, head reverses its direction and move towards the
starting end servicing all the requests in between.
5. The same process repeats.
6. Stop

PROGRAM

#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
printf("Enter total disk size\n");
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
// logic for Scan disk scheduling

/*logic for sort the request array */


for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(RQ[j]>RQ[j+1])
{

int temp;
temp=RQ[j];
RQ[j]=RQ[j+1];
RQ[j+1]=temp;
}

}
}

int index;
for(i=0;i<n;i++)
{
if(initial<RQ[i])

{
index=i;
break;
}

// if movement is towards high value


if(move==1)
{
for(i=index;i<n;i++)

{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
// last movement for max size
TotalHeadMoment=TotalHeadMoment+abs(size-RQ[i-1]-1);
initial = size-1;

for(i=index-1;i>=0;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];

}
}

// if movement is towards low value


else
{

for(i=index-1;i>=0;i--)

{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
// last movement for min size
TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-0);
initial =0;

for(i=index;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];

}
}

printf("Total head movement is %d",TotalHeadMoment);


return 0;
}

}
OUTPUT

$cc –scan.c $ ./a.out


Enter the number of Request
8
Enter the Requests Sequence
95 180 34 119 11 123 62 64
Enter initial head position
50
Enter total disk size
200
Enter the head movement direction for high 1 and for low 0
1
Total head movement is 337

RESULT The above program has been executed successfully


EX NO: 15B INSTALLATION OF LINUX OPERATING SYSTEM

DATE:

AIM

To Install Linux operating system using VMware.

PROCEDURE

1. Select the menu command to mount the VMware Tools virtual disk on the
guest operating system.

VMware
Product Action
vSphere Client Right-click the virtual machine and select Guest OS > Install
VMware Tools... or Guest OS > Upgrade VMware Tools...
Fusion Virtual Machine > Install (or Upgrade) VMware Tools
Workstation VM > Install (or Upgrade) VMware Tools
VMware
Product Action
Pro
Workstation Player > Manage > Install (or Upgrade) VMware Tools
Player

2. In the virtual machine, open a terminal window. Run the mount command with no
arguments to determine whether your Linux distribution automatically mounted
the VMware Tools virtual CD-ROM image.

If the CD-ROM device is mounted, the CD-ROM device and its mount point are listed in
a manner similar to the following output:

/dev/cdrom on /mnt/cdrom type iso9660 (ro,nosuid,nodev)


If the VMware Tools virtual CD-ROM image is not mounted, mount the CD-ROM drive.
a. If a mount point directory does not already exist, create it.

mkdir /mnt/cdrom
Some Linux distributions use different mount point names. For example, on some
distributions the mount point is /media/VMware Tools rather than /mnt/cdrom.
Modify the command to reflect the conventions that your distribution uses.

b. Mount the CD-ROM drive.

mount /dev/cdrom /mnt/cdrom

Some Linux distributions use different device names or organize


the /dev directory differently. If your CD-ROM drive is not /dev/cdrom or if the
mount point for a CD-ROM is not /mnt/cdrom, modify the command to reflect the
conventions that your distribution uses.

3. Change to a working directory, for example, /tmp and extract the tar file
into this /tmp folder.

cd /tmp

4. Delete any previous vmware-tools-distrib directory before you install VMware Tools.

The location of this directory depends on where you placed it during the previous
installation. Often this directory is placed in /tmp/vmware-tools-distrib.

List the contents of the mount point directory and note the file name of the VMware
Tools tar installer.

ls mount-point
Uncompress the installer.
tar zxpf /mnt/cdrom/VMwareTools-x.x.x-yyyy.tar.gz
The value x.x.x is the product version number, and yyyy is the build number of the
product release.

5. If necessary, unmount the CD-ROM image.

umount /dev/cdrom

If your Linux distribution automatically mounted the CD-ROM, you do not need to
unmount the image.

6. Run the installer and configure VMware Tools as a root user

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

Follow the prompts to accept the default values, if appropriate for your configuration.

Follow the instructions at the end of the script.

Depending on the features you use, these instructions can include restarting the X
session, restarting networking, logging in again, and starting the VMware User process.
You can alternatively reboot the guest operating system to accomplish all these tasks.

Usually, the vmware-config-tools.pl configuration file runs after the installer file finishes
running. If you attempt to install a tar installation over an RPM installation, or the
reverse, the installer detects the previous installation and must convert the installer
database format before continuing.
RESULT
The above program has been executed successfully

You might also like