CS3451 Introduction To Operating Systems
CS3451 Introduction To Operating Systems
NO:1
AIM:
Operating System
In simple words, Operating System is system software that is required to run applications programs and
utilities.
Requirement:
Now, It’s time to insert a media installation (USB or DVD) into the computer. Make sure all the windows files
have been copied to the flash drive.
Boot the computer
click on the windows icon and choose the option “Shut down or sign out” and then “Restart“. as pc reboot,
press F10, F11, F12, or ESC in order to enter the boot menu.Press F1, F2, F3, or ESC to enter the BIOS
(Basic Input Output System).
In Boot Options Priorities, Select the Boot Option #1. Click it and select the flash drive option.
Install Now
Windows operating system comes in two-bit options 32-bit and 64-bit. x86 denotes 32-bit and x64 denotes 64-
bit.
• “The 32 bit OS can store and handle lesser data than the 64 bit OS. it addresses a maximum of
4,294,967,296 bytes (4 GB) of RAM. The 64 bit OS, on the other hand, can handle more data than the 32 bit
OS.”
• x86 or 32-bit operating system supports only 32-bit software programme
• x64 or 64-bit operating system supports both 32-bit and 64-bit software programme.
go for “Windows 10 Home” mostly used OS for personal computers. now click “NEXT”.
Before proceeding further, accept the license terms and then click next to continue the installation.
Choose: Custom install window only or Upgrade:
Upgrade: This option is useful when installing the latest OS to your existing supporting versions of the
operating system.
Custom Installation: This option is useful while installing OS to brand new or existing computer, which
doesn’t have an OS.
Choose the correct partition where you are going to install your operating system and then click on “Delete”.
Select a drive with unallocated space and click “Next”
Choose the drive with unallocated space and click “Next” to continue the installation of windows. This might
take little time to copy data to hard drive, as it’s done move on to the next step.
As you can see, you have successfully installed the operating system to the computer system. Now, remove the
USB flash drive and restart your computer.
Setting Up Windows
RESULT:
Thus the installation of windows operating system was executed successfully.
EX.NO:2(a) BASICS OF UNIX COMMANDS
DATE:
AIM:
To study and execute Unix commands.
PROCEDURE:
Unix is security conscious, and can be used only by those persons who have an account.
Telnet (Telephone Network) is a Terminal emulator program for TCP/IP networks that
enables users to log on to remote servers.
To logon, type telnet server_ip address in run window.
User has to authenticate himself by providing username and password. Once verified, a
greeting and $ prompt appears. The shell is now ready to receive commands from the user.
Options suffixed with a hyphen (–) and arguments are separated by space.
GENERAL COMMANDS
Command Function
Date Used to display the current system date and time.
date +%D Displays date only
date +%T Displays time only
date +% Y Displays the year part of date
date +% H Displays the hour part of time
Cal Calendar of the current month
Calyear Displays calendar for all months of the specified year
calmonth year Displays calendar for the specified month of the year
Who Login details of all users such as their IP, Terminal No, User
name,
who am i Used to display the login details of the user
Tty Used to display the terminal name
Uname Displays the Operating System
uname –r Shows version number of the OS (kernel).
uname –n Displays domain name of the server
echo "txt" Displays the given text on the screen
echo $HOME Displays the user's home directory
Bc Basic calculator. Press Ctrl+dto quit
Lpfile Allows the user to spool a job along with others in a print
queue.
man cmdname Manual for the given command. Press q to exit
History To display the commands used by the user since log on.
Exit Exit from a process. If shell is the only process then logs out
DIRECTORY COMMANDS
Command Function
Pwd Path of the present working directory
Mkdirdir A directory is created in the given name under the current
directory
mkdirdir1 dir2 A number of sub-directories can be created under one stroke
cd subdir Change Directory. If the subdirstarts with / then path starts from
root (absolute) otherwise from current working directory.
FILE COMMANDS
Command Function
cat >filename To create a file with some contents. To end typing press
Ctrl+d.
The >symbol means redirecting output to a file. (<for input)
cat filename Displays the file contents.
cat >>filename Used to append contents to a file
cpsrc des Copy files to given location. If already exists, it will be
overwritten
cp –i src des Warns the user prior to overwriting the destination file
cp –r src des Copies the entire directory, all its sub-directories and files.
mv old new To rename an existing file or directory. –i option can also be
used
mv f1 f2 f3 dir To move a group of files to a directory.
mv –v old new Display name of each file as it is moved.
Rmfile Used to delete a file or group of files. –i option can also be used
rm * To delete all the files in the directory.
rm –r * Deletes all files and sub-directories
rm –f * To forcibly remove even write-protected files
Ls Lists all files and subdirectories (blue colored) in sorted
manner.
Lsname To check whether a file or directory exists.
lsname* Short-hand notation to list out filenames of a specific pattern.
ls –a Lists all files including hidden files (files beginning with .)
ls –x dirname To have specific listing of a directory.
ls –R Recursive listing of all files in the subdirectories
ls –l Long listing showing file access rights (read/write/execute-rwx
for user/group/others-ugo).
cmpfile1 file2 Used to compare two files. Displays nothing if files are
identical.
OUTPUT
GENERAL COMMANDS
[student@veccse ~]date
Sat May 06 06:10:34 UTC 2023
[student@veccse ~]date +%D
05/06/23
[student@veccse ~]date +%T
10:13:11
[student@veccse ~]date +%Y
2023
[student@veccse ~]date +%H
10
[student@veccse ~]who
studentpts/1 May 06 10:05 (172.16.1.14)
[student@veccse ~]who am i
studentpts/1 May 16 10:05 (172.16.1.14)
[student@veccse ~]tty
/dev/pts/1
[student@veccse ~]uname
Linux
[student@veccse ~]echo "hello"
hello
[student@veccse ~]echo $HOME
/home/student
[student@veccse ~]bc bc
1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software
with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
[student@veccse ~]man lp
lp(1) Easy Software Products lp(1)
NAME
lp - print files cancel - cancel jobs SYNOPSIS
lp [ -E ] [ -c ] [ -d destination ] [ -h server ] [ -m ] [ -n num- copies [ -o option ] [ -q priority ] [
-s ] [ -t title ] [ -H handling
] [ -P page-list ] [ file(s) ]
lp [ -E ] [ -c ] [ -h server ] [ -i job-id ] [ -n num-copies [ -o option ] [ -q priority ] [ -t title ] [ -
H handling ] [ -P page-list ] cancel [ -a ] [ -h server ] [ -u username ] [ id ] [ destination ] [
destination-id ]
DESCRIPTION
lpsubmits files for printing or alters a pending job. Use a filename of "-" to force printing
from the standard input.
cancelcancels existing print jobs. The -a option will remove all jobs from the specified
destination.
OPTIONS
The following options are recognized by lp:
[student@veccse ~]history
1 date
2 date +%D
3 date +%T
4 date +%Y
5 date +%H
6 who
7 who am i
8 tty
9 uname
10 uname -r
11 uname -n
12 echo "helloi"
13 echo $HOME
14 bc
15 man lp
16 history
DIRECTORY COMMANDS
[student@veccse]$ pwd
/home/student
FILE COMMANDS
[student@vecit ~]$ cat>test
hi welcome operating systems lab
[student@vecit ~]$ cat test
hi welcome operating systems lab [student@vecit ~]$
cat>>test fourth semester [student@vecit ~]$ cat test
hi welcome operating systems lab fourth semester
[student@vecit ~]$ cat>test1
[student@vecit ~]$ cp test test1
[student@vecit ~]$ cat test1
hi welcome operating systems lab fourth semester [student@vecit ~]$
cp -i test test1 cp: overwrite `test1'? y [student@vecit ~]$ cp -r test
test1
[student@vecit ~]$ ls
s s2 san swap.sh temp.sh test TEST test1
[student@vecit ~]$ mv san san1 [student@vecit ~]$
ls
s s2 san1 swap.sh temp.sh test TEST test1
[student@vecit ~]$ mv test test1 san1 [student@vecit
~]$ mv -v san1 sannew
`san1' -> `sannew'
[student@vecit ~]$ ls
s s2 sannew swap.sh temp.sh TEST
[student@vecit ~]$ cmp test test1 cmp:
test: No such file or directory
RESULT
Thus the study and execution of Unix commands has been completed successfully.
EX. NO: 1(b) SIMPLE SHELL PROGRAMS
DATE:
AIM:
To write simple shell scripts using shell programming fundamentals.
DESCRIPTION:
The activities of a shell are not restricted to command interpretation alone. The shell also
has Rudimentary programming features. When a group of commands has to be executed
regularly, they are stored in a file (with extension .sh). All such files are called shell scripts
or shell programs. Shell programs run in interpretive mode.
Preliminaries
1. Comments in shell script start with #. It can be placed anywhere in a line; the shell
ignores contents to its right. Comments are recommended but not mandatory
2. Shell variables are loosely typed i.e. not declared. Their type depends on the value
assigned. Variables when used in an expression or output must be prefixed by $.
3. The read statement is shell's internal tool for making scripts interactive.
4. Output is displayed using echo statement. Any text should be within quotes.
Escape sequence should be used with –e option.
5. Commands are always enclosed with ` ` (back quotes).
6. Expressions are computed using the expr command. Arithmetic operators are + -
* / %. Meta characters * ( ) should be escaped with a \.
7. Multiple statements can be written in a single line separated by ;
8. The shell scripts are executed using the sh command (sh filename).
Swapping values of two variables
Algorithm
Step 1 : Start
Step 2 : Read the values of a and b
Step 3 : Interchange the values of a and b using another variable t as follows:t = a ,a = b,
b =t
Step 4 : Print a and b
Step 5 : Stop
Program (swap.sh) # Swapping values
echo -n "Enter value for A : " read a
echo -n "Enter value for B : " read b t=$a
a=$b b=$t
echo "Values after Swapping" echo "A Value is $a" echo
"B Value is $b"
Output
[student@vecit ~]$ sh swap.sh Enter Value for A:5 Enter
Value for B:6 Values after Swapping A value is 6 B values is
5 [student@vecit ~]$
Farenheit to Centigrade Conversion
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
# Degree conversion
echo -n "Enter Fahrenheit : " read f
c=`expr\( $f - 32 \) \* 5 / 9`
echo "Centigrade is : $c"
Output
[student@vecit ~]$ sh temp.sh Enter Fahrenheit:4 Centrigrade is: -15 [student@vecit ~]$
RESULT
Odd or even
Algorithm
Step1:Start
Step 2 : Read number
Step 3 : If number divisible by 2 then Print "Number is Even"
Output
[student@vecit ~]$ sh oddeven.sh
Enter a non-zero number : 12 12 is Even
String comparison
Algorithm
Step 1 : Start
Step 2 : Read strings str1 and str2
Step 3 : If str1 = str2 then Print "Strings are the same"
RESULT
Thus using if statement scripts with conditional expressions were executed
MULTI-WAY BRANCHING
AIM:
To write shell scripts using case construct to match patterns.
DESCRIPTION:
The case statement is used to compare a variables value against a set of constants (integer,
character, string, range). If it matches a constant, then the set of statements followed after )is
executed till a ;; is encountered. The optional default block is indicated by *. Multiple
constants can be specified in a single pattern separated by
|.
case variable in
constant1)
statements ;;
constant2)
statements ;;
...
constantN) statements ;;
*) statements
esac
Simple Calculator
Algorithm
Step 1 : Start
Step 2 : Read operands a and b
RESULT
Thus using case statement, shell scripts were executed.
LOOPING
AIM
To write shell scripts using looping statements.
DESCRIPTION:
Shell supports a set of loops such as for, while and until to execute a set of statements repeatedly. The
body of the loop is contained between do and done statement.
The for loop doesn't test a condition, but uses a list instead.
For variable in list do
statements
done
The while loop executes the statements as long as the condition remains true.
while [ condition ] do
statements
done
The until loop complements the while construct in the sense that the statements are
executed as long as the condition remains false.
until [ condition ]
do
statements
done
Armstrong Number
Algorithm
Step 1 : Start
Step 2 : Read number
Step 3 : Initialize 0 to sum and number to num
Step 4 : Extract last digit by computing number modulo 10
RESULT:
Thus using loops, iterative scripts were executed
IMPLEMENTATION OF FORK, EXEC, GETPID, EXIT,
EX.NO:3 WAIT, AND CLOSE SYSTEM CALLS.
DATE:
AIM:
To write a program for implementing process management using the following
system calls of UNIX operating system: fork, exec, getpid, exit, wait, close.
ALGORITHM:
1. Start the program.
2. Read the input from the command line.
3. Use fork() system call to create process, getppid() system call used to get the
parent process ID and getpid() system call used to get the current process ID
4. execvp() system call used to execute that command given on that command line
argument
5. execlp() system call used to execute specified command.
6. Open the directory at specified in command line input.
7. Display the directory contents.
8. Stop the program.
PROGRAM:
#include<stdio.h> main(int
arc,char*ar[])
{
int pid; char s[100]; pid=fork(); if(pid<0)
printf("error"); else if(pid>0)
{
wait(NULL);
printf("\n Parent Process:\n"); printf("\n\tParent Process
id:%d\t\n",getpid()); execlp("cat","cat",ar[1],(char*)0);
error("can’t execute cat %s,",ar[1]);
}
else
{
printf("\nChild process:");
printf("\n\tChildprocess parent id:\t %d",getppid());
printf(s,"\n\tChild process id :\t%d",getpid());
write(1,s,strlen(s));
printf(" ");
printf(" ");
printf(" "); execvp(ar[2],&ar[2]);
error("can’t execute %s",ar[2]);
}
}
OUTPUT:
[root@localhost ~]# ./a.out tst date Child process:
Child process id :
3137 Sat Apr 10 02:45:32 IST 2010
Parent Process:
Parent Process id:3136 sd
dsaASD[root@localhost ~]# cat tst sd
dsaASD
RESULT:
Thus the program for process management was written and successfully executed.
EX.NO:4A
IMPLEMENTATION OF FCFS
SCHEDULING ALGORITHM
DATE:
AIM
To write a C program to implement First Come First Serve scheduling algorithm.
DESRIPTION:
For FCFS scheduling algorithm, read the number of processes/jobs in the system, their
CPU burst times. The scheduling is performed on the basis of arrival time of the processes
irrespective of their other parameters. Each process will be executed according to its arrival
time. Calculate the waiting time and turnaround time of each of the processes accordingly.
.ALGORITHM:
Step 1: Start the program.
Step 2: Get the input process and their burst time.
Step 3: Sort the processes based on order in which it requests CPU.
Step 4: Compute the waiting time and turnaround time for each process.
Step 5: Calculate the average waiting time and average turnaround time.
for(i=0;i<n;i++)
sum1=sum1+bt[i]+wt[i]; att=sum1/n;
printf("\n\nAverage waiting time:%f",awt);
printf("\n\nAverage turnaround time:%f",att);
}
OUTPUT:
enter the number of process 3
Enter the process name and burst-time: p1
2
p2 3
p3 4
Enter the arrival-time:0 1 2
GANTT CHART
| p1 | p2 | p3 |
0 2 5 9
RESULT:
The FCFS scheduling algorithm has been implemented in C.
EX.NO:4B
IMPLEMENTATION OF SJF SCHEDULING
DATE: ALGORITHM
AIM:
To write a C program to implement shortest job first (non-pre-emptive) scheduling algorithm.
DESCRIPTION:
For SJF scheduling algorithm, read the number of processes/jobs in the system, their CPU
burst times. Arrange all the jobs in order with respect to their burst times. There may be
two jobs in queue with the same execution time, and then FCFS approach is to be
performed. Each process will be executed according to the length of its burst time. Then
calculate the waiting time and turnaround time of each of the processes accordingly.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the input process and their burst time.
OUTPUT:
enter the no.of process3
enter the process number,burst time and arrival time 1 8 1
251
331
p3 3 1 0 2
p2 5 1 2 6
p1 8 1 7 14
RESULT:
The SJF scheduling algorithm has been implemented in C.
EX.NO.4C:
IMPLEMENTATION OF ROUND ROBIN
DATE: SCHEDULING ALGORITHM
AIM:
To write a C program to implement Round Robin scheduling algorithm.
DESCRIPTION:
For round robin scheduling algorithm, read the number of processes/jobs in the system, their
CPU burst times, and the size of the time slice. Time slices are assigned to each process in
equal portions and in circular order, handling all processes execution. This allows every
process to get an equal chance. Calculate the waiting time and turnaround time of each of
the processes accordingly.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the input process and their burst time.
p1 2 0
p2 3 1
p3 4 2
GANTT CHART
ROUND ROBIN
RESULT
The Round Robin scheduling algorithm has been implemented in C.
EX.NO:4D IMPLEMENTATION OF PRIORITY
SCHEDULING ALGORITHM
DATE:
AIM:
To write a C program to implement Priority Scheduling algorithm.
DESCRIPTION:
For priority scheduling algorithm, read the number of processes/jobs in the system, their
CPU burst times, and the priorities. Arrange all the jobs in order with respect to their
priorities. There may be two jobs in queue with the same priority, and then FCFS approach
is to be performed. Each process will be executed according to its priority. Calculate the
waiting time and turnaround time of each of the processes accordingly.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the input process and their burst time.
}
} wt[0]=0;
for(i=1;i<=np;i++)
wt[i]=wt[i-1]+bt[i-1]; ft[0]=bt[0];
for(i=1;i<np;i++)
ft[i]=ft[i-1]+bt[i]; printf("\n\n\t\tGANTT
CHART\n"); printf("\n \n");
for(i=0;i<np;i++)
printf("|\t%s\t",p[i]);
printf("|\t\n");
printf("\n \n");
printf("\n");
for(i=0;i<=np;i++)
printf("%d\t\t",wt[i]); printf("\n \n");
printf("\n");
for(i=0;i<np;i++)
wat[i]=wt[i]-at[i]; for(i=0;i<np;i++)
tat[i]=wat[i]-at[i]; printf("\nPRIORITY
SCHEDULING:\n");
printf("\nProcess Priority Burst-time Arrival-time Waiting-time Turnaround- time");
for(i=0;i<np;i++)
printf("\n\n%d%s\t%d\t\t%d\t\t%d\t%d\t\t%d",i+1,p[i],pr[i],bt[i],a t[i],wt[i],tat[i]);
for(i=0;i<np;i++)
sum=sum+wat[i]; awt=sum/np;
for(i=0;i<np;i++)
sum1=sum1+tat[i]; att=sum1/np;
printf("\n\nAverage waiting time:%f",awt); printf("\n\nAverageturn around time is:%f",att);
}
OUTPUT:
Enter the number of process3
Enter the process, burst-time and priority: p1 3 3
p2 4 2
p3 5 1
| p3 | p2 | p1 |
0 5 9 12
PRIORITY SCHEDULING:
Process Priori Burst- Arrival- Waiting- Turnaround-
ty time time time time
p3 1 5 0 0 0
p2 2 4 1 5 3
p1 3 3 2 9 5
Average waiting time: 3.666667 Average
turnaround time is: 2.666667
RESULT
The Priority scheduling algorithm has been implemented in C.
EX.NO:5
IMPLEMENTATION OF SHARED
ME MO R Y AND INTER PROCESS
DATE:
COMMUNICATION
AIM:
To write a program for developing Application using Inter Process communication
with pipes.
ALGORITHM:
1. Start the program.
2. Read the input from parent process and perform in child process.
3. Write the date in parent process and read it in child process.
4. Data is read.
5. Stop the program.
SHARED MEMORY FOR WRITER PROCESS
#include <iostream>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h> using
namespace std; int main()
{
// ftok to generate unique key key_t key =
ftok("shmfile",65);
// shmget returns an identifier in shmid
int shmid = shmget(key,1024,0666|IPC_CREAT);
// shmat to attach to shared memory
char *str = (char*) shmat(shmid,(void*)0,0); printf("Write
Data : ");
gets(str);
printf("Data written in memory: %s\n",str);
//detach from shared memory shmdt(str);
return 0;
}
RESULT:
Thus the program was executed successfully.
EX.NO:6
PRODUCER CONSUMER PROBLEM
USING SEMAPHORE
DATE:
AIM:
To write a C program to implement the Producer & consumer Problem (Semaphore)
DESCRIPTION:
Producer-consumer problem, is a common paradigm for cooperating processes. A producer
process produces information that is consumed by a consumer process. One solution to the
producer-consumer problem uses shared memory. To allow producer and consumer processes
to run concurrently, there must be available a buffer of items that can be filled by the producer
and emptied by the consumer. This buffer will reside in a region of memory that is shared by
the producer and consumer processes. A producer can produce one item while the consumer is
consuming another item. The producer and consumer must be synchronized, so that the
consumer does not try to consume an item that has not yet been produced.
ALGORITHM:
Step 1: The Semaphore mutex, full & empty are initialized.
Step 2: In the case of producer process
i) Produce an item in to temporary variable.
ii) If there is empty space in the buffer check the mutex value for enter into the
critical section.
iii) If the mutex value is 0, allow the producer to add value in the temporary
variable to the buffer.
Step 3: In the case of consumer process
i) It should wait if the buffer is empty
ii) If there is any item in the buffer check for mutex value, if the mutex==0,
remove item from buffer
iii) Signal the mutex value and reduce the empty value by 1.
iv) Consume the item.
Step 4: Print the result
PROGRAM :
#define BUFFERSIZE 10
int mutex,n,empty,full=0,item,item1; int
buffer[20];
int in=0,out=0,mutex=1; void
wait(int s)
{
while(s<0)
{
printf(“\nCannot add an item\n”);
exit(0);
}
s--;
}
void signal(int s)
{
s++;
}
void producer()
{
do
{
wait (empty); wait(mutex);
printf(“\nEnter an item:”); scanf(“%d”,&item);
buffer[in]=item;
in=in+1; signal(mutex); signal(full);
}
while(in<n);
}
void consumer()
{
do
{
wait(full); wait(mutex);
item1=buffer[out];
printf(“\nConsumed item =%d”,item1); out=out+1;
signal(mutex); signal(empty);
}
while(out<n);
}
void main()
{
printf(“Enter the value of n:”); scanf(“%d
“,&n);
empty=n; while(in<n)
producer(); while(in!=out)
consumer();
}
OUTPUT:
$ cc prco.c
$ a.out
Enter the value of n :3 Enter
the item:2
Enter the item:5 Enter the
item:9 consumed item=2
consumed item=5
consumed item=9
$
RESULT:
Thus the program for solving producer and consumer problem using semaphore was executed
successfully.
EX.NO: 7 DEADLOCK AVOIDANCE
DATE:
AIM:
To Simulate Algorithm for Deadlock avoidance
DESCRIPTION:
In a multiprogramming environment, several processes may compete for a finite number of
resources. A process requests resources; if the resources are not available at that time, the
process enters a waiting state. Sometimes, a waiting process is never again able to change
state, because the resources it has requested are held by other waiting processes. This
situation is called a deadlock. Deadlock avoidance is one of the techniques for handling
deadlocks. This approach requires that the operating system be given in advance additional
information concerning which resources a process will request and use during its lifetime.
With this additional knowledge, it can decide for each request whether or not the process
should wait. To decide whether the current request can be satisfied or must be delayed, the
system must consider the resources currently available, the resources currently allocated to
each process, and the future requests and releases of each process. Banker’s algorithm is a
deadlock avoidance algorithm that is applicable to a system with multiple instances of each
resource type
ALGORITHM:
Step 1: Start the Program
Step 2: Get the values of resources and processes.
for(i=1;i<= pno;i++)
{
printf("\n"); for(j=1;j<= rno;j++)
{
printf("%4d",allocated[i][j]);
}
printf("|"); for(j=1;j<= rno;j++)
{
printf("%4d",max[i][j]);
}
printf("|"); for(j=1;j<= rno;j++)
{
printf("%4d",need[i][j]);
}
}
prc=0;
for(i=1;i<= pno;i++)
{
if(flag[i]==0)
{
prc=i;
for(j=1;j<= rno;j++)
{
if(work[j]< need[i][j])
{
prc=0; break;
}
}
}
if(prc!=0) break;
}
if(prc!=0)
{
printf("\n Process %d completed",i); count++;
printf("\n Available matrix:"); for(j=1;j<= rno;j++)
{
work[j]+=allocated[prc][j];
allocated[prc][j]=0; max[prc][j]=0;
flag[prc]=1;
printf(" %d",work[j]);
}
}
}while(count!=pno&&prc!=0);
if(count==pno)
printf("\nThe system is in a safe state!!");
else
printf("\nThe system is in an unsafe state!!");
getch();
}
OUTPUT:
Enter number of process:5 Enter
number of resources:3
Enter total numbers of each resources:10 5 7 Enter Max
resources for each process:
for process 1: 7 5 3
for process 2: 3 2 2
for process 3: 9 0 2
for process 4: 2 2 2
for process 5: 4 3 3
Enter allocated resources for each process: for
process 1: 0 1 0
for process 2: 3 0 2
for process 3: 3 0 2
for process 4: 2 1 1
for process 5: 0 0 2
available resources:
2 3 0
0 1 0| 7 5 3| 7 4 3
3 0 2| 3 2 2| 0 2 0
3 0 2| 9 0 2| 6 0 0
2 1 1| 2 2 2| 0 1 1
0 0 2| 4 3 3| 4 3 1
Process 2 completed
Available matrix: 5 3 2 Allocated
matrix Max need
0 1 0| 7 5 3| 7 4 3
0 0 0| 0 0 0| 0 0 0
3 0 2| 9 0 2| 6 0 0
2 1 1| 2 2 2| 0 1 1
0 0 2| 4 3 3| 4 3 1
Process 4 completed
Available matrix: 7 4 3 Allocated
matrix Max need
0 1 0| 7 5 3| 7 4 3
0 0 0| 0 0 0| 0 0 0
3 0 2| 9 0 2| 6 0 0
0 0 0| 0 0 0| 0 0 0
0 0 2| 4 3 3| 4 3 1
Process 1 completed
Available matrix: 7 5 3 Allocated
matrix Max need
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
3 0 2| 9 0 2| 6 0 0
0 0 0| 0 0 0| 0 0 0
0 0 2| 4 3 3| 4 3 1
Process 3 completed
Available matrix: 10 55
Allocated matrix Max need
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 2| 4 3 3| 4 3 1
Process 5 completed
Available matrix: 10 57
The system is in a safe state!!
RESULT:
Thus the program to implement the deadlock avoidance was executed
and verified.
EX.NO:8 DEADLOCK DETECTION
DATE: ALGORITHM
AIM:
To Simulate Algorithm for Deadlock detection
ALGORITHM:
Step 1: Start the Program
Step 2: Get the values of resources and processes.
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 Max Matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
scanf("%d",&max[i][j]);
}
}
printf("Enter the Allocation Matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
scanf("%d",&alloc[i][j]);
}
}
printf("Enter the available Resources\n"); for(j=0;j<r;j++)
{
scanf("%d",&avail[j]);
}
}
void show()
{
int i,j;
printf("Process\t Allocation\t Max\t Available\t");
for(i=0;i<n;i++)
{
printf("\nP%d\t ",i+1);
for(j=0;j<r;j++)
{
printf("%d ",alloc[i][j]);
}
printf("\t");
for(j=0;j<r;j++)
{
printf("%d ",max[i][j]);
}
printf("\t");
if(i==0)
{
for(j=0;j<r;j++) printf("%d ",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;
}
//find need matrix
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;
}
//printf("\nP%d",i); 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++)
{
} }
else
{
printf("P%d\t",dead[i]);
}
}
OUTPUT:
Enter the no. Of processes 3
Enter the no of resources instances 3 Enter
the max matrix
368
433
344
RESULT:
Thus the program to implement the deadlock detection was executed
successfully.
EX.NO: 9
IMPLEMENTATION OF THREADING
DATE:
AIM:
To write a c program to implement Threading and Synchronization Applications.
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_t tid[2];
void* doSomeThing(void *arg)
{
unsigned long i = 0;
pthread_t id = pthread_self();
if(pthread_equal(id,tid[0]))
{
printf("\n First thread processing\n");
}
else
{
printf("\n Second thread processing\n");
}
for(i=0;
i<(0xFFFFFFFF);
i++);
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));
else
printf("\n Thread created successfully\n");
i++;
}
sleep(5);
return 0;
}
OUTPUT:
RESULT:
AIM:
To write a C program to implement paging concept for memory management.
ALGORIHTM:
Step 1: Start the program.
Step 2: Enter the logical memory address.
Step 3: Enter the page table which has offset and page frame.
Step 4: The corresponding physical address can be calculate by, PA = [ pageframe* No. of
page size ] + Page offset.
Step 5: Print the physical address for the corresponding logical address.
Step 6: Terminate the program.
PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
int ms, ps, nop, np, rempages, i, j, x, y, pa, offset;
scanf("%d",&ms);
printf("\nEnter the page size -- ");
scanf("%d",&ps);
nop = ms/ps;
printf("\nThe no. of pages available in memory are -- %d ",nop);
for(j=0;
j<s[i];j++)
scanf("%d",&fno[i][j]);
}
getch();
}
OUTPUT:
Enter the memory size – 1000 Enter
the page size -- 100
The no. of pages available in memory are 10
Enter number of processes -- 3
RESULT:
Thus C program for implementing paging concept for memory management has been
executed successfully.
Ex.NO: 11 IMPLEMENTATION OF MEMORY ALLOCATION
TECHNIQUES
DATE:
AIM:
To write a C program to implement Memory Management concept using the
technique best fit, worst fit and first fit algorithms.
ALGORITHM:
1. Get the number of process.
2. Get the number of blocks and size of process.
3. Get the choices from the user and call the corresponding switch cases.
4. First fit -allocate the process to the available free block match with the size of the
process
5. Worst fit –allocate the process to the largest block size available in the list
6. Best fit-allocate the process to the optimum size block available in the list
7. Display the result with allocations
PROGRAM:
#include<stdio.h> main()
{
int p[10],np,b[10],nb,ch,c[10],d[10],alloc[10],flag[10],i,j;
scanf("%d",&nb);
printf("\nEnter the size of each process:");
for(i=0;i<np;i++)
{
printf("\nProcess %d:",i); scanf("%d",&p[i]);
}
printf("\nEnter the block sizes:"); for(j=0;j<nb;j++)
{
printf("\nBlock %d:",j);
scanf("%d",&b[j]);c[j]=b[j];d[j]=b[j];
}
if(np<=nb)
{
printf("\n1.First fit 2.Best fit 3.Worst fit"); do
{
printf("\nEnter your choice:"); scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nFirst Fit\n"); for(i=0;i<np;i++)
{
for(j=0;j<nb;j++)
{
if(p[i]<=b[j])
{
alloc[j]=p[i];
printf("\n\nAlloc[%d]",all oc[j]);
printf("\n\nProcess %d of size %d is allocated in block:%d of size:%d",i,p[i],j,b[j]);
flag[i]=0,b[j]=0;
break;
}
else
flag[i]=1;
}
}
for(i=0;i<np;i++)
{
if(flag[i]!=0)
printf("\n\nProcess %d of size %d is not allocated",i,p[i]);
}
break;
c[i]=c[j]; c[j]=temp;
}
}
}
printf("\nAfter sorting block sizes:");
for(i=0;i<nb;i++)
printf("\nBlock %d:%d",i,c[i]);
for(i=0;i<np;i++)
{
for(j=0;j<nb;j++)
{
if(p[i]<=c[j])
{
alloc[j]=p[i];
printf("\n\nAlloc[%d]",all oc[j]);
printf("\n\nProcess %d of size %d is
allocated in block %d of size
%d",i,p[i],j,c[j]); flag[i]=0,c[j]=0;
} break;
else
} flag[i]=1;
}
for(i=0;i<np;i++)
{
if(flag[i]!=0)
printf("\n\nProcess %d of size %d is not
allocated",i,p[i]);
}
break;
case 3: printf("\nWorst Fit\n"); for(i=0;i<nb;i++)
{
for(j=i+1;j<nb;j++)
{
if(d[i]<d[j])
{
int temp=d[i]; d[i]=d[j]; d[j]=temp;
}
}
}
printf("\nAfter sorting block sizes:"); for(i=0;i<nb;i++)
printf("\nBlock %d:%d",i,d[i]); for(i=0;i<np;i++)
{
for(j=0;j<nb;j++)
{
if(p[i]<=d[j])
{
alloc[j]=p[i];
printf("\n\nAlloc[%d]",alloc[j]);
printf("\n\nProcess %d of size %d is allocated in block %d of size
%d",i,p[i],j,d[j]
flag[i]=0,d[j]=0;break;
}
else
flag[i]=1;
}
}
for(i=0;i<np;i++)
{
if(flag[i]!=0)
printf("\n\nProcess %d of size
%d is not allocated",i,p[i]);
}
break;
default:
printf(“Invalid Choice…!”);break;
}
}while(ch<=3);
}
}
OUTPUT:
Enter the no of process:3 Enter
the no of blocks:3
Enter the size of each process:
Process 0:100
Process 1:150
Process 2:200
Enter the block sizes:
Block 0:300
Block 1:350
Block 2:200
1.First fit 2.Best fit 3.Worst fit
Enter your choice:1
Alloc[100]
Process 0 of size 100 is allocated in block 0 of size 300 Alloc[150]
Process 1 of size 150 is allocated in block 1 of size 350 Alloc[200]
Process 2 of size 200 is allocated in block 2 of size 200 Enter
your choice:2
Best Fit
After sorting block sizes are: Block
0:200
Block 1:300
Block 2:350
Alloc[100]
Process 0 of size 100 is allocated in block:0 of size:200 Alloc[150]
Process 1 of size 150 is allocated in block:1 of size:300 Alloc[200]
Process 2 of size 200 is allocated in block:2 of size:350 enter
your choice:3
Worst Fit
After sorting block sizes are:
Block 0:350
Block 1:300
Block 2:200
Alloc[100]
Process 0 of size 100 is allocated in block 0 of size 350 Alloc[150]
Process 1 of size 150 is allocated in block 1 of size 300 Alloc[200]
Process 2 of size 200 is allocated in block 2 of size 200 Enter
your choice:6
Invalid Choice…!
RESULT:
Thus a UNIX C program to implement memory management scheme using Best fit worst fit
and first fit were executed successfully.
EX.NO:12A IMPLEMENTATION OF THE FIFO PAGE
AIM:
To write a UNIX C program to implement FIFO page replacement algorithm.
DESCRIPTION :
The FIFO Page Replacement algorithm associates with each page the time when that page
was brought into memory. When a page must be replaced, the oldest page is chosen . There
is not strictly necessary to record the time when a page is brought in. By creating a FIFO
queue to hold all pages in memory and by replacing the page at the head of the queue.
When a page is brought into memory, insert it at the tail of the queue.
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. Format 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>
#include<conio.h> main()
{
int i, j, k, f, pf=0, count=0, rs[25], m[10], n;
clrscr();
printf("\n Enter the length of reference string -- ");
scanf("%d",&n);
printf("\n Enter the reference string -- "); for(i=0;i<n;i++)
scanf("%d",&rs[i]); printf("\n Enter no. of
frames -- "); scanf("%d",&f);
for(i=0;i<f;i++)
m[i]=-1;
printf("\n The Page Replacement Process is -- \n"); for(i=0;i<n;i++)
{
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("\n The number of Page Faults using FIFO are %d",pf); getch();
}
OUTPUT:
Enter the length of reference string – 20
Enter the reference string -- 70120304230321201701
Enter no. of frames -- 3
The Page Replacement Process is –
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 3 1 PF No. 5
2 3 0 PF No. 6
4 3 0 PF No. 7
4 2 0 PF No. 8
4 2 3 PF No. 9
0 2 3 PF No. 10
0 2 3
0 2 3
0 1 3 PF No. 11
0 1 2 PF No. 12
0 1 2
0 1 2
7 1 2 PF No. 13
7 0 2 PF No. 14
7 0 1 PF No. 15
The number of Page Faults using FIFO are 15
RESULT:
Thus a UNIX C program to implement FIFO page replacement is executed successfully.
EX.NO:12B
IMPLEMENTATION OF LRU PAGE REPLACEMENT
ALGORITHM
DATE:
AIM:
To write UNIX C program a program to implement LRU page replacement
algorithm.
DESCRIPTION:
The Least Recently Used replacement policy chooses to replace the page which has not
been referenced for the longest time. This policy assumes the recent past will approximate the
immediate future. The operating system keeps track of when each page was referenced by
recording the time of reference or by maintaining a stack of references.
ALGORITHM:
1. Start the process
2. Declare the size
3. Get the number of pages to be inserted
4. Get the value
5. Declare counter and stack
6. Select the least recently used page by counter value
7. Stack them according the selection.
8. Display the values
9. Stop the process
PROGRAM:
#include<stdio.h>
#include<conio.h> main()
{
int i, j , k, min, rs[25], m[10], count[10], flag[25], n, f, pf=0, next=1; clrscr();
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)
{
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]=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); getch();
}
OUTPUT:
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 --
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 a UNIX C program to implement LRU page replacement is executed successfully.
EX.NO:12C IMPLEMENTATION OF LFU PAGE REPLACEMENT
DATE: ALGORITHM
AIM:
To write a program in C to implement LFU page replacement algorithm.
ALGORITHM
Step1: Start the program
Step2: Declare the required variables and initialize it.
Step3; Get the frame size and reference string from the user
cntr[i]=0; a[i]=-1;
}
Printf(“\nThe Page Replacement Process is – \n“);
for(i=0;i<m;i++)
{
for(j=0;j<f;j++)
if(rs[i]==a[j])
{
}
cntr[j]++;
if(j==f)
break;
{
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(“\tPF No. %d”,pf);
}
printf("\n\n Total number of page faults -- %d",pf); getch();
}
OUTPUT:
Enter number of page references -- 10
Enter the reference string -- 123452525143
Enter the available no. of frames 3
The Page Replacement Process is –
1 -1 -1 PF No. 1
1 2 -1 PF No. 2
1 2 3 PF No. 3
4 2 3 PF No. 4
5 2 3 PF No. 5
5 2 3
5 2 3
5 2 1 PF No. 6
5 2 4 PF No. 7
5 2 3 PF No. 8
Total number of page faults ------------ 8
RESULT:
Thus the C programs to implement LFU page replacement algorithm was executed
successfully.
EX NO: 13 IMPLEMENTATION OF FILE ORGANIZATION TECHNIQUES
DATE:
AIM:
Program to simulate Single level directory file organization technique.
DESCRIPTION:
The directory structure is the organization of files into a hierarchy of folders. In a single-level directory
system, all the files are placed in one directory. There is a root directory which has all files. It has a
simple architecture and there are no sub directories. Advantage of single level directory system is that it
is easy to find a file in the directory.
PROGRAM:
#include<stdio.h>struct
{
char dname[10],fname[10][10];
int fcnt;
}dir;
void main()
{
int i,ch; char
f[30]; clrscr(); dir.fcnt
= 0;
printf("\nEnter name of directory -- ");
scanf("%s", dir.dname);
while(1)
{
printf("\n\n1. Create File\t2. Delete File\t3. Search File \n
4. Display Files\t5. Exit\nEnter 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;
}
}
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);
}
}
getch();}
OUTPUT:
Enter name of directory -- CSE
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit Enter your choice – 1
Description:
In the two-level directory system, each user has own user file directory (UFD). The system maintains a
master block that has one entry for each user. This master block contains the addresses of the directory
of the users. When a user job starts or a user logs in, the system's master file directory (MFD) is
searched. When a user refers to a particular file, only his own UFDis searched.
PROGRAM:
#include<stdio.h>struct
{
char dname[10],fname[10][10];
int fcnt;
}dir[10];
void main()
{
int i,ch,dcnt,k; char
f[30], d[30]; clrscr(); dcnt=0;
while(1)
{
printf("\n\n1. Create Directory\t2. Create File\t3. Delete File");
printf("\n4. Search File\t\t5. Display\t6. Exit\t Enter your choice --");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nEnter name of directory -- ");
scanf("%s", dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf("Directory created"); break;
case 2: printf("\nEnter name of the directory -- ");
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
{
printf("Enter name of the file -- ");
scanf("%s",dir[i].fname[dir[i].fcnt]);
for(i=0;i<dcnt;i++)for(i=0;i<dcnt;i++)
{
if(strcmp(d,dir[i].dname)==0)
{
default:exit(0);
}
}
}
OUTPUT:
RESULT:
AIM:
To implement sequential file allocation technique.
ALGORITHM:
Step 1: Start the program.
scanf("%d",&c);
if(c==1)
goto X;
else
exit();
getch();
}
OUTPUT:
Output: Enter the starting block & length of file 4 10 4->1
5->1
6->1
7->1
8->1
9->1
10->1
11->1
12->1
13->1
The file is allocated to disk
If you want to enter more files? (Y-1/N-0)
RESULT:
Thus the program to implement the Sequential file allocation was executed successfully.
EX.NO:14B LINKED FILE ALLOCATION
DATE:
AIM:
To write a C program to implement File Allocation concept using the technique Linked List
Technique.
ALGORITHM:
Step 1: Start the Program
Step 2: Get the number of files.
Step 3: Allocate the required locations by selecting a location randomly
for(j=st;j<(k+st);j++)
{
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("\n %d->file is already allocated",j); k++;
}
}
printf("\n If u want to enter one more file? (yes-1/no-0)");
scanf("%d",&c);
if(c==1)
goto X;
else
exit();
getch( );
}
OUTPUT:
Enter how many blocks are already allocated 3 Enter the
blocks no’s that are already allocated 4 7 9 Enter the
starting index block & length 3 7
3-> 1
4-> File is already allocated 5->1
6->1
7-> File is already allocated 8->1
9-> File is already allocated 10->1
11->1
12->1
If u want to enter one more file? (yes-1/no-0)
RESULT:
Thus the program to implement the linked file allocation was executed successfully
EX.NO:14C INDEXED FILE ALLOCATION
DATE:
AIM:
To write a C program to implement file Allocation concept using the technique indexed
allocation Technique
ALGORITHM:
Step 1: Start the Program
Step 2: Get the number of files.
Step 3: Get the memory requirement of each file.
Step 4: Allocate the required locations by selecting a location randomly.
}
else
{
printf("Block already allocated\n"); goto x;
}
for(i=0;i<n;i++)
scanf("%d",&inde[i]); for(i=0;i<n;i++)
if(f[inde[i]]==1)
{
printf("Block already allocated"); goto x;
}
for(j=0;j<n;j++)
f[inde[j]]=1; printf("\n allocated");
printf("\n file indexed");
for(k=0;k<n;k++)
printf("\n %d->%d:%d",p,inde[k],f[inde[k]]); printf(" Enter 1 to enter
more files and 0 to exit\t"); s scanf("%d",&c);
if(c==1)
goto x;
else
exit();
getch();
}
OUTPUT:
Enter index block 9
Enter no of files on index 3 1 2 3
Allocated
File indexed 9-> 1:1
9-> 2:1
9->3:1
Enter 1 to enter more files and 0 to exit.
RESULT :
Thus the program to implement the indexed file allocation was executed successfully
EX.NO: 15 IMPLEMENTATION OF DISK
DATE: SCHEDULING ALGORITHMS
AIM:
Write a C program to simulate disk scheduling algorithms
a) FCFS b) SCAN c) C-SCAN
DESCRIPTION
One of the responsibilities of the operating system is to use the hardware efficiently. For the
disk drives, meeting this responsibility entails having fast access time and large disk
bandwidth. Both the access time and the bandwidth can be improved by managing the order
in which disk I/O requests are serviced which is called as disk scheduling. The simplest
form of disk scheduling is, of course, the first-come, first- served (FCFS) algorithm. This
algorithm is intrinsically fair, but it generally does not provide the fastest service. In the
SCAN algorithm, the disk arm starts at one end, and moves towards the other end, servicing
requests as it reaches each cylinder, until it gets to the other end of the disk. At the other end,
the direction of head movement is reversed, and servicing continues. The head continuously
scans back and forth across the disk. C-SCAN is a variant of SCAN designed to provide a
more uniform wait time. Like SCAN, C-SCAN moves the head from one end of the disk to
the other, servicing requests along the way. When the head reaches the other end, however,
it immediately returns to the beginning of the disk without servicing any requests on the
return trip
PROGRAM
FCFS DISK SCHEDULING ALGORITHM
#include<stdio.h> main()
{
int t[20], n, I, j, tohm[20], tot=0; float avhm;
clrscr();
printf(“enter the no.of tracks”);
scanf(“%d”,&n);
printf(“enter the tracks to be traversed”);
for(i=2;i<n+2;i++)
scanf(“%d”,&t*i+); for(i=1;i<n+1;i++)
{
tohm[i]=t[i+1]-t[i]; if(tohm[i]<0)
tohm[i]=tohm[i]*(-1);
}
for(i=1;i<n+1;i++)
tot+=tohm[i]; avhm=(float)tot/n;
printf(“Tracks traversed\tDifference between tracks\n”); for(i=1;i<n+1;i++)
printf(“%d\t\t\t%d\n”,t*i+,tohm*i+);
printf("\nAverage header movements:%f",avhm); getch();
}
OUTPUT:
Enter no.of tracks:9
Enter track position:55 58 60 70 18 90 150 160 184
for(p=k+1;p<n+2;p++,k++)
atr[p]=t[k+1];
for(j=0;j<n+1;j++)
{
if(atr[j]>atr[j+1])
d[j]=atr[j]-atr[j+1];
else
d[j]=atr[j+1]-atr[j];
sum+=d[j];
}
printf("\nAverage header movements:%f",(float)sum/n); getch();
}
OUTPUT:
Enter no.of tracks:9
Enter track position:55 58 60 70 18 90 150 160 184
160 10
1841 24
90 94
70 20
60 10
58 2
55 3
18 37
Average header movements: 27.77
RESULT:
Thus the program to implement disk Scheduling algorithm has been executed and verified
EX.NO: 16 INSTALLATION OF UBUNTU OPERATING SYSTEM USING VMWARE
DATE:
Ubuntu:
Ubuntu is one of the popular Linux distributions developed on the Debian Linux platform. Ubuntu is a full
operating system available in multiple editions: Desktop edition, Servers edition, IoT, and Cloud. These
editions can run on either a computer or virtual machines.
What Is VMWare Workstation?
VMWare Workstation is an application developed by VMWare to create virtual machines, containers, and
Kubernetes clusters on any desktop or server system. VMWare released VMWare Workstation in two
products: VMWare Workstation Pro and VMWare Workstation Player. VMWare Workstation Player is
released on a free license with limited features, whereas VMWare Workstation Pro is an enterprise paid
version that has loaded with a lot of features.
Prerequisites To Install Ubuntu On VMWare Workstation:
To install Ubuntu Linux on VMWare Workstation you just need a physical machine, VMWare Workstation
Pro or Player, and Ubuntu Linux ISO image.