cs3461-os-lab-manual-master-copy
cs3461-os-lab-manual-master-copy
LIST OF EXPERIMENTS:
1. Installation of windows operating system
2. Illustrate UNIX commands and Shell Programming
3. Process Management using System Calls : Fork, Exit, Getpid, Wait, Close
4. Write C programs to implement the various CPU Scheduling Algorithms
5. Illustrate the inter process communication strategy
6. Implement mutual exclusion by Semaphore
7. Write C programs to avoid Deadlock using Banker's Algorithm
8. Write a C program to Implement Deadlock Detection Algorithm
9. Write C program to implement Threading
10. Implement the paging Technique using C program
11. Write C programs to implement the following Memory Allocation Methods
a. First Fit b. Worst Fit c. Best Fit
12. Write C programs to implement the various Page Replacement Algorithms
13. Write C programs to Implement the various File Organization Techniques
14. Implement the following File Allocation Strategies using C programs
a. Sequential b. Indexed c. Linked
15. Write C programs for the implementation of various disk scheduling algorithms
16. Install any guest operating system like Linux using VMware.
TOTAL: 60 PERIODS
Ex.No:01
Date: INSTALLATION OF WINDOWS OPERATING SYSTEM
Aim:
To INSTALLATION OF WINDOWS OPERATING SYSTEM
Procedure to Install :
The Boot tab may instead say Boot Options or Boot Order, depending on
your computer's manufacturer.
4. Select a device from which to boot. You have a couple of options here:For a USB flash drive, select
the Removable Devices opion.For a disc installation, select the CD-ROM Drive or Optical Drive option.
5. Press the key until your boot option is first. Once either Removable Devices or CD-ROM
Drive is at the top of the list, your computer will select your choice as its default boot option.
On some computers, you'll instead press one of the function keys (e.g., F5 or the arrow
keys to navigate an option up to the top of the menu. The key will be listed on the right
Aim:
To study of Basic UNIX Commands and various UNIX editors such as vi, ed, ex and EMACS.
CONTENT:
a) date
–used to check the date and time
Syn: $date
e) lp
–used to take printouts
Syn:$lp filename
f) man
–used to provide manual help on every UNIX commands.
Syn:$man unix command
$man cat
g) who & whoami
–it displays data about all users who have logged into the system currently. The next command
displays about current user only.
Syn:$who
$whoami
h)uptime
–tells you how long the computer has been running since its last reboot or power-off.
Syn:$uptime i)
uname
–it displays the system information such as hardware platform, system name and processor, OS type.
Syn:$uname–a
j) hostname
–displays and set system host name
Syn:$ hostname
FILE MANIPULATION COMMANDS
a) cat
–this create, view and concatenate files.
Creation:
Syn:$cat>filename
Viewing:
Syn:$cat filename
Add text to an existing file:
Syn:$cat>>filename
Concatenate:
Syn:$catfile1file2>file3
$catfile1file2>>file3 (no over writing of file3)
b) grep
–used to search a particular word or pattern related to that word from the file
. Syn:$grep search word filename
Eg:$grep anu student
c) rm
–deletes a file from the file system
Syn:$rm filename
d) touch
–used to create a blank file.
Syn:$touch file names
e) cp
–copies the files or directories
Syn:$cpsource file destination file
Eg:$cp student stud
f) mv
–to rename the file or directory
syn:$mv old file new file
Eg:$mv–i student student list(-i prompt when overwrite)
g) cut
–it cuts or pickup a given number of character or fields of the file.
Syn:$cut<option><filename>
Eg: $cut –c filename
$cut–c1-10emp
$cut–f 3,6emp
$ cut –f 3-6 e (-c cutting columns , -f cutting fields)
h) head
–displays10 lines from the head(top)of a given file
Syn:$head filename
Eg:$head student
Syn:$head-2student
i) tail
Syn:$tail filename
Eg:$tail student
-To display the bottom two lines;
Syn:$ tail -2 student
j) wc–it counts the number of lines, words, character in a specified file(s)with the options as
–l,-w,-c
RESULT:
Thus the Unix commands was studied successfully
ALGORITHM:
SEPT 1: Start the program.
STEP 2: Read the value of year.
STEP 3: Calculate „b=expr $y%4‟.
STEP 4: If the value of b equals 0 then print the year is a leap year
STEP 5: If the value of r not equal to 0 then print the year is not a leap year.
PROGRAM:
echo "Enter the year"
read y
b=`expr $y % 4`
if [ $b -eq 0 ]; then
echo "$y is a leap year"
else
echo "$y is not a leap year"
fi
OUTPUT :
Enter the year 2024
2024 is a leap year
Enter the year 2022
2022 is not a leap year
RESULT :
Thus the shell programming was developed and output was gained
17
EX.NO :3 PROGRAM FOR SYSTEM CALLS OF UNIXOPERATING
SYSTEM(fork, getpid, exit)
AIM:
To write C programs for system calls of Unix operating system (fork, getpid, exit).
ALGORITHM:
PROGRAM:
include <stdio.h>
#include <stdlib.h> // Added for exit()
#include <unistd.h> // Added for fork() and getpid()
int main()
{
int pid, pid1, pid2;
// Create a new process
pid = fork();
if (pid == -1)
{
// Error in process creation
printf("ERROR IN PROCESS CREATION \n");
exit(1);
}
// If pid is non-zero, it's the parent process
if (pid != 0)
{
pid1 = getpid(); // Get the parent process ID
printf("\nThe parent process ID is %d\n", pid1);
}
else
{
// If pid is 0, it's the child process
pid2 = getpid(); // Get the child process ID
printf("\nThe child process ID is %d\n", pid2);
}
OUTPUT:
RESULT:
Thus program for system calls of Unix operating system was developed and output was obtained
EX.NO :4A Write C Programs To Implement The Various CPU Scheduling
Algorithms ( FIRST COME FIRST SERVE )
AIM:
To write a c program to simulate the CPU scheduling algorithm First Come First Serve (FCFS).
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process name and the bursttime
Step 4: Set the waiting of the first process as ‗0‘and its burst time as its
turnaroundtime Step 5: for each process in the Ready Q calculate
a). Waiting time (n) = waiting time (n-1) + Burst time (n-1)
b). Turnaround time (n)= waiting time(n)+Burst time(n)
Step 6: Calculate
a) Average waiting time = Total waiting Time / Number of process
b) Average Turnaround time = Total Turnaround Time / Number of process
Step 7: Stop the process
PROGRAM:
#include <stdio.h>
int main()
{
int bt[20], wt[20], tat[20], i, n;
float wtavg = 0, tatavg = 0;
printf("\nEnter the number of processes -- ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("\nEnter Burst Time for Process %d -- ", i);
scanf("%d", &bt[i]);
}
wt[0] = 0;
tat[0] = bt[0];
for (i = 1; i < n; i++)
{
wt[i] = wt[i - 1] + bt[i - 1];
tat[i] = tat[i - 1] + bt[i];
wtavg += wt[i];
tatavg += tat[i]; }
printf("\tPROCESS\tBURST TIME\tWAITING TIME\tTURNAROUND TIME\n");
for (i = 0; i < n; i++)
{
printf("\tP%d\t\t%d\t\t%d\t\t%d\n", i, bt[i], wt[i], tat[i]);
}
wtavg /= n;
tatavg /= n;
printf("\nAverage Waiting Time -- %.2f", wtavg);
printf("\nAverage Turnaround Time -- %.2f", tatavg);
return 0;
}
Output :
Enter the number of processes -- 2
RESULT :
Thus Program for simulate the CPU scheduling algorithm First Come First Serve (FCFS).
EX.NO :4B Write C Programs To Implement The Various CPU Scheduling
Algorithms ( SHORTEST JOB FIRST)
AIM:
To write a program to stimulate the CPU scheduling algorithm Shortest job first (Non-Preemption)
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Start the Ready Q according the shortest Burst time by sorting according to lowest to
highest burst time.
Step 5: Set the waiting time of the first process as ‗0‘ and its turnaround time asits burst
time.
Step 6: Sort the processes names based on their Burt time
Step 7: For each process in the ready queue, calculate
PROGRAM:
#include <stdio.h>
int main()
{
int p[20], bt[20], wt[20], tat[20], i, k, n, temp;
float wtavg = 0, tatavg = 0;
printf("\nEnter the number of processes -- ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
p[i] = i; // Process IDs
printf("Enter Burst Time for Process %d -- ", i);
scanf("%d", &bt[i]);
}
for (i = 0; i < n; i++)
{
for (k = i + 1; k < n; k++)
{
if (bt[i] > bt[k])
{
temp = bt[i];
bt[i] = bt[k];
bt[k] = temp;
temp = p[i];
p[i] = p[k];
p[k] = temp;
}
}
}
wt[0] = wtavg = 0;
tat[0] = tatavg = bt[0];
for (i = 1; i < n; i++)
{
wt[i] = wt[i - 1] + bt[i - 1];
tat[i] = tat[i - 1] + bt[i];
wtavg = wtavg + wt[i];
tatavg = tatavg + tat[i];
}
printf("\n\tPROCESS\tBURST TIME\tWAITING TIME\tTURNAROUND TIME\n");
for (i = 0; i < n; i++)
{
printf("\n\tP%d\t\t%d\t\t%d\t\t%d", p[i], bt[i], wt[i], tat[i]);
}
Output :
RESULT :
Thus Program for stimulate the CPU scheduling algorithm Shortest job first (Non-Preemption)
was developed and output was obtained.
Write C Programs To Implement The Various CPU Scheduling
EX.NO :4C Algorithms (ROUND ROBIN)
AIM:
ALGORITHM:
Step 2: Accept the number of processes in the ready Queue and time quantum(or) time slice
Step 3: For each process in the ready Q, assign the process id and accept theCPU burst time
Step 4: Calculate the no. of time slices for each process where No. of timeslice for process (n) =
Step 5: If the burst time is less than the time slice then the no. of time slices =1.
a) Waiting time for process (n) = waiting time of process(n-1)+ burst time ofprocess(n-1
) + the time difference in getting the CPU fromprocess(n-1)
b) Turnaround time for process(n) = waiting time of process(n) + burst time ofprocess(n)+ the
time difference in getting CPU from process(n).
Step 7: Calculate
PROGRAM:
#include <stdio.h>
int main()
{
int i, n, burst_time[10], waiting_time[10], turnaround_time[10], remaining_time[10], time_slice;
float average_waiting_time = 0, average_turnaround_time = 0;
printf("Enter the number of processes: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("Enter Burst Time for process %d: ", i + 1);
scanf("%d", &burst_time[i]);
remaining_time[i] = burst_time[i];
}
printf("Enter the size of time slice: ");
scanf("%d", &time_slice);
int current_time = 0;
while (1)
{
int all_done = 1;
for (i = 0; i < n; i++)
{
if (remaining_time[i] > 0)
{
all_done = 0;
if (remaining_time[i] <= time_slice)
{
current_time += remaining_time[i];
turnaround_time[i] = current_time;
remaining_time[i] = 0;
}
else
{
current_time += time_slice;
remaining_time[i] -= time_slice;
}
}
}
if (all_done == 1) break;
}
for (i = 0; i < n; i++)
{
waiting_time[i] = turnaround_time[i] - burst_time[i];
average_waiting_time += waiting_time[i];
average_turnaround_time += turnaround_time[i];
}
printf("\nThe Average Turnaround time is: %.2f", average_turnaround_time / n);
printf("\nThe Average Waiting time is: %.2f", average_waiting_time / n);
printf("\n\tPROCESS\tBURST TIME\tWAITING TIME\tTURNAROUND TIME\n");
for (i = 0; i < n; i++) {
printf("\t%d\t\t%d\t\t%d\t\t%d\n", i + 1, burst_time[i], waiting_time[i], turnaround_time[i]);
}
return 0;
}
Output :
RESULT :
Thus Program for simulate the CPU scheduling algorithm round-robin was developed and output was
obtained.
25
EX.NO :4D Write C Programs To Implement The Various CPU Scheduling
Algorithms (PRIORITY)
AIM:
ALGORITHM:
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst
time
Step 5: Set the waiting of the first process as ‗0‘ and its burst time as its turnaround time
For each process in the Ready Q calculate Step 8:for each process
PROGRAM:
#include <stdio.h>
int main()
{
int p[20], bt[20], pri[20], wt[20] = {0}, tat[20] = {0}, i, k, n, temp;
float wtavg = 0, tatavg = 0;
printf("Enter the number of processes: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
p[i] = i; // Assign process ID (0 to n-1)
printf("Enter the Burst Time & Priority of Process %d: ", i);
scanf("%d %d", &bt[i], &pri[i]);
}
RESULT :
Thus C Programs to Implement the CPU scheduling priority algorithm was developed and
output was obtained.
EX.NO :5 WRITE C PROGRAMS TO IMPLEMENT IPC USING
SHARED MEMORY
AIM:
the process
data
Step 7: Stop the process.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/ipc.h>
#include
<sys/shm.h>
#include
<sys/types.h>
#define SEGSIZE
char
*argv[]) {int shmid, cntr;
key_t key;
char
*segptr;
char buff[] = "poooda. ";
return 0;
}
RESULT :
AIM:
To write a C program to implement banker‟s algorithm for deadlock avoidance.
ALGORITHM:
availablematrix. Step-4: Compare each and every process using the banker‟s
algorithm.
deadlock process
int max[MAX_PROCESS]
[MAX_RESOURC
E]; int
alloc[MAX_PROCESS][MAX_RESOURC
E]; int
need[MAX_PROCESS][MAX_RESOURC
E];
int
avail[MAX_RESOURCE]
;int n, r;
void
input();
void
show();
void cal();
int main() {
printf("********** Baner's Algo
************\n");input();
show();
cal();
return
0;
}
32
void input()
{int i, j;
printf("Enter the no of Processes\t");
scanf("%d", &n);
printf("Enter the no of resources instances\t");
scanf("%d", &r);
printf("Enter the Max Matrix\n");
for(i = 0; i < n; i++) {
for(j = 0; j < r; j++) {
scanf("%d",
&max[i][j]);
}
}
printf("Enter the Allocation Matrix\n");
for(i = 0; i < n; i++) {
for(j = 0; j < r; j++) {
scanf("%d", &alloc[i]
[j]);
}
}
printf("Enter the available Resources\n");
for(j = 0; j < r; j++) {
scanf("%d", &avail[j]);
}
}
void show()
{int i, j; printf("Process\tAllocation\tMax\
tAvailable\n"); for(i = 0; i < n; i++) {
printf("P%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]);
}}
printf("\n");
}}
void cal() {
int finish[MAX_PROCESS], safe[MAX_PROCESS], work[MAX_RESOURCE], i, j, k,
count = 0;for(i = 0; i < n; i++) {
finish[i] = 0;
}
for(i = 0; i < r; i++)
{work[i] =
avail[i];
}
while(count < n)
33
{int found = 0;
for(i = 0; i < n; i+
+)
{if(finish[i] ==
0) {
int j;
for(j = 0; j < r; j++)
{ if(need[i][j] >
work[j])
{
break;
}
}
if(j == r) {
for(k = 0; k < r; k++)
{ work[k] += alloc[i]
[k];
}
safe[count++] =
i;finish[i] = 1;
found = 1;
}
}
}
if(found == 0)
{break;
}
}
if(count == n) {
printf("\nThe system is in safe state.\n");
printf("Safe Sequence is:");
for(i = 0; i < n; i++)
{ printf("P%d ", safe[i]
+ 1);
}
}
else {
printf("\nSystem is in unsafe state.\n");
}
}
Output :
RESULT :
35
EX NO 8 WRITE A C PROGRAM TO IMPLEMENT
DEADLOCK DETECTION ALGORITHM
AIM:
ALGORITHM:
availablematrix. Step-4: Compare each and every process using the banker‟s
algorithm.
deadlock process
#include<stdio.h>
#include<conio.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()
{printf("********** Deadlock Detection Algorithm ************\n");input();
show();
cal();
getch();
return
0;
}void input()
{int i,j;
printf("Enter the number of processes: ");
scanf("%d",&n);
printf("Enter the number of resource instances: ");
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]);
36
}}
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\tAllocation\tMax\t\tAvailable\n");for(i=0;i<n;i++)
{printf("P%d\t",i+1);for(j=0;j<r;j++)
{printf("%d ",alloc[i][j]);
}printf("\t\t"); for(j=0;j<r;j++)
{printf("%d ",max[i][j]);
}printf("\t\t");if(i==0)
{for(j=0;j<r;j++)
{printf("%d ",avail[j]);
}}printf("\n");
}}void cal()
{int finish[100],temp,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 matrixfor(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; break;
}}}}}
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 processes are: ");for(i=0;i<j;i++)
{printf("P%d ",dead[i]+1);
}}else{printf("\nNo Deadlock Occurs");
}}
RESULT :
Thus Write A C Program To Implement Deadlock DetectionAlgorithm Wqs Developed And
Output Was Obtained.
37
EX NO 9 WRITE A C PROGRAM C PROGRAM TO
IMPLEMENT THREADING
AIM :TO Write C program to implement Threading.
ALGORITHM :
STEP 1 : START.
STEP 5 : STOP.
SOURCE CODE :
#include <stdio.h>
#include <string.h>
#include
<pthread.h>
void* foo(void* arg)
{int val = *(int*)arg;
printf("Value received as argument in starting routine: %i\n",
val);int* ret = malloc(sizeof(int));
*ret = val * val;
pthread_exit(ret)
;}int main(void)
{pthread_t id;int j = 2;
pthread_create(&id, NULL, foo,
&j);int* ptr;
pthread_join(id, (void**)&ptr);
printf("Value received by parent from child: %i\n",
*ptr);free(ptr);
return 0;
}Output :Value received as argument in starting routine: 2Value received by parent from child:
4
RESULT : THUS program to implement Threading was Developed And Output Was
Gained……..
38
EX NO 10 WRITE A C PROGRAM TO IMPLEMENT THE PAGING
TECHNIQUE USING C PROGRAM
AIM:
ALGORITHM:
Step 2: Declare page number, page table, frame number and process size.Step 3:
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)
{pthread_mutex_lock(&lock);unsigned long i = 0;
counter += 1;
printf("\nJob %d started\n", counter);
for(i=0; i<(0xFFFFFFFF); i++);
printf("\nJob %d finished\n", counter);
pthread_mutex_unlock(&lock);
return NULL;
}int main(void)
{int i = 0;int err;
if (pthread_mutex_init(&lock, NULL) !=
0) {printf("\nmutex init failed\n");
return 1;}
while(i < 2) {err = pthread_create(&(tid[i]), NULL, &doSomeThing,
NULL);if (err != 0) {printf("\ncan't create thread :[%s]", strerror(err));
} ;}
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
pthread_mutex_destroy(&lock);
return 0;
39
}
Output :
Job 1 started
Job 1 finished
Job 2 started
Job 2 finished
RESULT :
40
EX NO 11 WRITE A C PROGRAM TO IMPLEMENT MEMORY
ALLOCATION METHODS
WORST FIT
1. Define the maximum number of blocks and files that the program can handle using#define.
2. Declare and initialize the necessary variables: b[max] for block sizes, f[max] for file sizes,
frag[max] for fragmentation, bf[max] for block flags, and ff[max] for file flags.
3. Get the number of blocks and files from the user.
4. Ask the user to enter the size of each block.
5. Ask the user to enter the size of each file.
6. For each file, find the first block that is large enough to hold it.
7. If a block is found, set the flag for that block to 1 to indicate it is in use.
8. Calculate the fragmentation for that file and store it in frag[].
9. Repeat steps 6 to 8 for all files.
10. Display the results (file number, file size, block number, block size,
and fragmentation) using printf().
11. End the program with getch().
PROGRAM
first-FIT
#include<stdio.h>
#define max 25
void main()
{int frag[max], b[max], f[max], i, j, nb, nf, temp;static int bf[max], ff[max];
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");
or(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)
41
{ff[i] = j;break;
}}}
frag[i] = temp;
bf[ff[i]] = 1;
}printf("\nFile_no:\tFile_size:\tBlock_no:\tBlock_size:\tFragment"); for(i=1; i<=nf; i++) printf("\n%d\t\t%d\
t\t%d\t\t%d\t\t%d", i, f[i], ff[i], b[ff[i]], frag[i]);
}
Output :
Memory Management Scheme - First Fit
Enter the number of blocks:4
Enter the number of files:3
BEST FIT
ALGORITHM :
BEST-FIT
#include<stdio.h>
#include<conio.h>
#define MAX_BLOCKS
25
void main()
{
int frag[MAX_BLOCKS], blocks[MAX_BLOCKS], files[MAX_BLOCKS], i, j, num_blocks,
num_files,temp, best_block;
42
int block_status[MAX_BLOCKS] = {0}; // Initialize all blocks
to free int file_block[MAX_BLOCKS] = {0}; // Initialize all files
to unallocated
clrscr();
printf("\nEnter the number of blocks: ");
scanf("%d", &num_blocks);
printf("Enter the number of files: ");
scanf("%d", &num_files); printf("\
nEnter the size of the blocks:\n");
Block 1: 100
Block 2: 200
Block 3: 150
Block 4: 300
43
Enter the size of the files:
File 1: 125
File 2: 75
File 3: 250
File 4: 100
File 5: 175
1 125 2 200 75
2 75 1 100 25
3 250 4 300 50
4 100 3 150 50
RESULT :
44
WORST FIT
ALGORITHM :
PROGRAM
#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]);bf[i] = 0;
}
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++)
{highest = 0;
for(j = 1; j <= nb; j++)
{if(bf[j] != 1) //if bf[j] is not allocated
{temp = b[j] - f[i];if(temp >= 0)
45
{if(highest < temp)
{ff[i] = j;
highest = temp;
}}}}
frag[i] =
highest;bf[ff[i]]
= 1;
}printf("\nFile_no:\tFile_size:\tBlock_no:\tBlock_size:\tFragment"); 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();
}
OUTPUT :
Memory Management Scheme - Worst FitEnter the
number of blocks:4
Enter the number of files:5
Block 1:200
Block 2:400
Block 3:600
Block 4:300
1:200
File 2:400
File 3:500
File 4:300
File 5:150
File_no: File_size: Block_no: Block_size: Fragment
1 200 1 200 0
2 400 3 600 200
3 500 3 600 100
4 300 2 400 100
5 150 3 600 450
ALGORITHM:
A) FIRST IN FIRST
OUT SOURCE CODE :
#include<stdio.h>
#include<conio.h>
int fr[3];
void display()
{int i; printf("\
n");
for(i=0;i<3;i++) {
printf("%d\t",fr[i]);
}}
void main() {
int i,j,page[12]={2,3,2,1,5,2,4,5,3,2,5,2};
int
flag1=0,flag2=0,pf=0,frsize=3,top=0;
clrscr();
for(i=0;i<3;i++)
{fr[i] = -1;
}for(j=0;j<12;j++) {flag1=0; flag2=0;
for(i=0;i<frsize;i++)
47
{ f(fr[i]==page[j])
{flag1=1;
flag2=1; break;
}}
if(flag1==0) {
for(i=0;i<frsize;i++) {
if(fr[i]==-1) {
fr[i]=page[j]
;flag2=1;
break;
}}}
if(flag2==0) {
fr[top]=page[j];
top++;
pf++;
if(top>=frsize)
{top=0;
}}
display();
}printf("Number of page faults: %d",pf+frsize);getch();
}
OUTPUT:
2 -1 -1
2 3 -1
2 3 -1
231
531
521
524
524
324
324
354
352
48
B) LEAST RECENTLY USED
AIM: To implement LRU page replacement technique.
ALGORITHM:
9. Stop the
process SOURCE
CODE :
#include <stdio.h>
#include
<conio.h>
int fr[3];
void display();void main()
{int p[12] = {2, 3, 2, 1, 5, 2, 4, 5, 3, 2, 5, 2};
int i, j, fs[3];
int index, k, l, flag1 = 0, flag2 = 0, pf = 0,
{fr[i] = -1;
}
for (j = 0; j < 12; j++)
{flag1 = 0, flag2 = 0;
for (i = 0; i < 3; i++)
{if (fr[i] == p[j])
{flag1 = 1;
flag2 =
1;break;
}}
if (flag1 == 0)
{for (i = 0; i < 3; i++)
{if (fr[i] == -1)
{fr[i] = p[j];flag2 = 1; break;
}}}
49
if (flag2 == 0)
{for (i = 0; i < 3; i++)fs[i] = 0;
for (k = j - 1, l = 1; l <= frsize - 1; l++, k--)
{for (i = 0; i < 3; i++)
{if (fr[i] == p[k])fs[i] = 1;
}}
for (i = 0; i < 3; i++)
{if (fs[i] == 0)index = i;
}fr[index] = p[j];pf++;
}display();
}printf("\n no of page faults :%d", pf + frsize);getch();
}
void display()
{
int i;
printf("\n");
for (i = 0; i < 3; i+
+)printf();
OUTPUT:
2 -1 -1
2 3 -1
2 3 -1
231
251
251
254
254
354
352
352
352
No of page faults: 7
50
C) OPTIMAL
AIM: To implement optimal page replacement technique.
ALGORTHIM:
1. Start Program
6. If No Frames Is Free Repalce The Page With The Page That Is Leastly Used7.Print
Page Number Of Page Faults
8.Stop process.
SOURCE
CODE:
51
1;break;
}}
if (flag1 == 0)
{for (i = 0; i < m; i++)
{if (fr[i] == -1)
{fr[i] = page[j];flag2 = 1; break;
}}}
if (flag2 == 0)
{for (i = 0; i < m; i++)lg[i] = 0;
for (i = 0; i < m; i++)
{for (k = j + 1; k < n; k++)
{if (fr[i] == page[k])
{lg[i] = k - j;break;
}}}
found = 0;
for (i = 0; i < m; i++)
{if (lg[i] == 0)
{index = i; found = 1;break;
}}
if (found == 0)
{max = lg[0];index = 0;
for (i = 0; i < m; i++)
{if (max < lg[i])
{max = lg[i];index = i;
}}}
fr[index] =
page[j];pf++;
}display();}
printf("Number of page faults : %d\n", pf);
pr = (float)pf / n * 100;
printf("Page fault rate = %f \n", pr);
getch();
}void display()
{int i;
for (i = 0; i < m; i+
+) printf("%d\t",
fr[i]);
printf("\n");
}
OUTPUT:
52
Enter length of the reference string: 12
frames: 3
1 -1 -1
1 2 -1
123
124
124
124
125
125
125
325
425
425
RESULT :
53
EX NO 13 WRITE C PROGRAMS TO IMPLEMENT THE VARIOUS
FILE ORGANIZATIONTECHNIQUES
AIM :
SOURCE CODE :
#include <stdio.h>
#include<string.h>
struct directory
{char dname[10]; char fname[10][10];int fcnt;
};
void main()
{int i, ch; char f[30];
struct directory dir;
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 \n4. Display Files\t5. Exit\nEnter yourchoice
-- ");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]);dir.fcnt--;
break;
}}if (i == dir.fcnt)
printf("File %s not found",
e)
;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");
54
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
Files are -- A B C
SOURCE CODE :
#include <stdio.h>
#include<string.h>
struct directory
char name[10];
charfiles[10][10];
int file_count;
} dirs[10];
int dir_count = 0;
void create_directory() {
if (dir_count >= 10) {
printf("\nMaximum directory limit reached.");
return;
}
printf("\nEnter name of directory: ");
scanf("%s", dirs[dir_count].name);
dirs[dir_count].file_count = 0;
dir_count++;
printf("\nDirectory created successfully.");
}
void create_file() {
char dir_name[10], file_name[10]; printf("\
nEnter name of the directory: "); scanf("%s",
dir_name);
int dir_index = -1;
for (int i = 0; i < dir_count; i++) {
if (strcmp(dir_name, dirs[i].name) == 0)
{dir_index = i;
break;
}}
if (dir_index == -1) {
printf("\nDirectory %s not found.", dir_name);
return;
}printf("\nEnter name of the file: ");scanf("%s", file_name);
if (dirs[dir_index].file_count >= 10) {
printf("\nMaximum file limit reached for directory %s.", dir_name);
return;
}
strcpy(dirs[dir_index].files[dirs[dir_index].file_count], file_name);
dirs[dir_index].file_count++;
printf("\nFile created successfully.");
}
void delete_file() {
char dir_name[10], file_name[10]; printf("\
nEnter name of the directory: "); scanf("%s",
dir_name);
int dir_index = -1;
for (int i = 0; i < dir_count; i++) {
if (strcmp(dir_name, dirs[i].name) == 0)
{ dir_index =
56
i;break;
}}if (dir_index == -1) {
printf("\nDirectory %s not found.", dir_name);
return;
}printf("\nEnter name of the file: ");scanf("%s", file_name);
int file_index = -1;
for (int i = 0; i < dirs[dir_index].file_count; i++) {
if (strcmp(file_name, dirs[dir_index].files[i]) == 0)
{file_index = i;
break;
}}
if (file_index == -1) {
printf("\nFile %s not found in directory %s.", file_name, dir_name);
return;
}printf("\nFile %s deleted successfully from directory %s.", file_name,
dir_name); dirs[dir_index].file_count--;
strcpy(dirs[dir_index].files[file_index], dirs[dir_index].files[dirs[dir_index].file_count]);
}void search_file() {
char dir_name[10], file_name[10]; printf("\
nEnter name of the directory: "); scanf("%s",
dir_name);
int dir_index = -1;
for (int i = 0; i < dir_count; i++) {
if (strcmp(dir_name, dirs[i].name) == 0)
{dir_index = i;
break;
}}
if (dir_index == -1) {
printf("\nDirectory %s not found.", dir_name);
return;
}printf("\nEnter name of the file”);
OUTPUT
1. Create Directory 2. Create File 3. Delete File
your choice -- 1
created
57
1. Create Directory 2. Create File 3. Delete File
your choice -- 2
RESULT :
Thus, Implementation Of various File OrganizationTechniques was Successfully
executed and Verified
58
EX NO 14 WRITE C PROGRAMS TO IMPLEMENTFILE ALLOCATION
STRATEGIES USING CPROGRAMS
a. Sequential b. Indexed c. Linked
Step 3: Get the number of processes and values of block size for each process.
Step 4: First fit algorithm searches the entire entire memory block until a
holewhich is big enough is encountered. It allocates that memory block for
therequesting process.
Step 5: Best-fit algorithm searches the memory blocks for the smallest
holewhichcanbe allocated to requesting process and allocates if.
Step 6: Worst fit algorithm searches the memory blocks for the largest hole and
Step 7: Analyses all the three memory management techniques and display the
Program:
#include<stdio.h>
#include<conio.h>
int main()
{
int n, i, j, b[20], sb[20], t[20], x,
c[20][20];clrscr();
printf("Enter number of files: ");
scanf("%d", &n);
for(i=0; i<n; i++)
{
printf("Enter number of blocks occupied by file %d: ",
i+1);scanf("%d", &b[i]);
printf("Enter the starting block of file %d: ",
i+1);scanf("%d", &sb[i]);
t[i] = sb[i];
59
for(j=0; j<b[i]; j++)
c[i][j] = sb[i++];
}
printf("\nFilename\tStart block\tLength\n");
for(i=0; i<n; i++)
printf("%d\t\t%d\t\t%d\n", i+1, t[i], b[i]);
printf("\nEnter file name: ");
scanf("%d", &x); printf("\
nFile name: %d", x);
printf("\nLength: %d", b[x-
1]);printf("\nBlocks occupied:
"); for(i=0; i<b[x-1]; i++)
printf("%d ", c[x-
1][i]);getch();
return 0;
}
OUTPUT:
1 5 3
2 1 2
3 8 5
File name: 2
Length: 2
Blocks occupied: 1 2
60
INDEXED FILE ALLOCATION
AIM: Write a C Program to implement Indexed File Allocation method.Algorithm:
Step 1: Start.
Step 7: Check there is any cosumer.If yes check whether the buffer is emptyStep 8: If no
Step 10: Repeat checking for the producer and consumer till requiredStep 11:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n, m[20], i, j, sb[20], s[20], b[20][20],
x;clrscr();
printf("Enter no. of
files:");scanf("%d", &n);
61
are:");for(j = 0; j < m[i]; j++)
printf("%3d", b[i][j]);
getch();
}
OUTPUT:
Enter no. of files:2
Enter starting block and size of file1:3
5Enter blocks occupied by file1:5
Enter blocks of file1:3 4 5 6 7
Enter starting block and size of file2:9
6Enter blocks occupied by file2:6
Enter blocks of file2:9 10 11 12 13 14
ALGORITHM:
Step 2: When the page is required replace the page at the head of the queueStep 3: Now
Program:
#include<stdio.h>
#include<conio.h>
struct file{char fname[10];
int start,size,block[10];
}f[10];
main()
62
{
int i,j,n;
clrscr();
scanf("%d",&n); for(i=0;i<n;i+
+)
{
printf("Enter file name:"); scanf("%s",&f[i].fname); printf("Enter starting block:");
scanf("%d",&f[i].start);
f[i].block[0]=f[i].start; printf("Enter
no.of
blocks:");scanf("%d",&f[i].size);
for(j=1;j<=f[i].size;j++)
{scanf("%d",&f[i].block[j]);
}}printf("File\tstart\tsize\tblock\n");for(i=0;i<n;i++)
{printf("%s\t%d\t%d\t",f[i].fname,f[i].start,f[i].size);for(j=1;j<=f[i].size-1;j++)
printf("%d--->",f[i].block[j]);
printf("%d",f[i].block[j]);printf("\n");
}getch();
63
`OUTPUT
no.of blocks: 4
no.of blocks: 3
file1 10 4 10--->11--->12--->13
file2 20 3 20--->21--->22
file3 30 5 30--->31--->32--->33--->34
RESULT :
#include<stdio.h>
#include<conio.h>
int main()
{
int t[20], n, i, j, tohm[20], tot=0;
float avhm;
clrscr();
printf("Enter the number of tracks: ");
scanf("%d",&n);
printf("Enter the tracks to be traversed: ");
for(i=0;i<n;i++)
scanf("%d",&t[i])
;for(i=0;i<n-1;i++)
{tohm[i]=t[i+1]-t[i];if(tohm[i]<0)
tohm[i]=tohm[i]*(-1);
}for(i=0;i<n-1;i++)tot+=tohm[i];
avhm=(float)tot/n;
printf("Tracks traversed\tDifference between tracks\n");
for(i=0;i<n-1;i++)
printf("%d\t\t\t%d\n",t[i],tohm[i]); printf("\
nAverage header movements: %f",avhm); getch();
return 0;
}
Output :
Enter the number of tracks: 5
Enter the tracks to be traversed: 53 98 183 37
122 Tracks traversed Difference between
tracks
53 45
98 85
183 146
37 85
Average header movements: 72.200005
65
15 B) SCAN DISK SCHEDULING ALGORITHM
#include <stdio.h>
#include<conio.h>
main() {
int t[20], d[20], h, i, j, n, temp, k, atr[20], tot, p, sum=0;
clrscr();
printf("Enter the no. of tracks to be traversed: ");
scanf("%d",&n);
printf("Enter the position of head: ");
scanf("%d",&h);
t[0]=0;
t[1]=h;
printf("Enter the tracks: ");
for(i=2;i<n+2;i++)
scanf("%d",&t[i]);
// Sorting the tracks in ascending order
for(i=0;i<n+2;i++) {
for(j=0;j<(n+2)-i-1;j++) {
if(t[j]>t[j+1]) {
temp=t[j];
t[j]=t[j+1];
t[j+1]=temp;
}}}
66
Output :
67
Output :
RESULT :
Thus Write C programs for the implementation of various disk
scheduling algorithms.
68
EX NO 16 INSTALL ANY GUEST OPERATING SYSTEM USING
VMWARE
AIM: To install Kali Linux on Windows using a virtual machine software
called Vware.
PROCEDURE :
1 Download and install a virtual machine software such as VMware on your Windows machine.
2Download the Kali Linux ISO files from the official Kali Linux website.
69
3Open the virtual machine software and click on "New" to create a new virtual machine.
4 Follow the instructions to set up the virtual machine, such as specifying the amount of RAM and
hard disk space to allocate.
5When prompted, select the Kali Linux ISO file as the installation media.
70
6Complete the Kali Linux installation process within the virtual machine, following the prompts.
71
72
73
7 Once the installation is complete, start the Kali Linux virtual machine from the virtualization
software.
74
8 You should now have Kali Linux running as a virtual machine on your Windows computer.
RESULT :
Thus Installation Of Any Guest Operating System Using Vmware Was
Successfully Verified
75