23BCP119 Os Lab File
23BCP119 Os Lab File
ENGINEERING
SCHOOL OF TECHNOLOGY
PANDIT DEENDAYAL ENERGY UNIVERSITY
SESSION 2024-25
SUBMITTED BY
SUBMITTED TO
Assistant Professor
****************
Experiment-1
1. Introduction to Linux Commands with all the options available for them like p,f, a,
t,r, S, R, i, g, h, d etc.
b) cd - Change Directory
• Output:
l) sudo - Superuser Do
• Output:
• Output:
o) chmod - Change File Permissions
u) ps - Process Status
x) df - Disk Free
z) clear
aa) ipconfig
cc) cal
• Displays a calendar.
• Options:
o -y: Display the calendar for the whole year.
• Output:
dd) passwd
ff) comm
gg) group
f. Write a menu driven shell script will point the following menu and execute the given
task.
▪ Display calendar of current month
▪ Display today’s date and time
▪ Display username those are currently logged in the system
▪ Display your name at given x,y position.
▪ Display your terminal number.
Code and Output:
Experiment-4
Objective: Introduction to shell scripting with functions and command line arguments
a. Write a shell script and create functions to find the largest of three numbers and also
find the total average.
Code and Output:
b. Write a shell script which print “invalid no. of arguments” if more than 5 command line
arguments otherwise print “valid no. of arguments”.
c. Write a shell script and create functions to find the max. and min. number from the
given data set passed by command line argument.
e. Write a shell script and create functions which will generate first n Fibonacci numbers
like :1,1,2,3,5,13….
i) FCFS
Explanation: First come – First served (FCFS), is the simplest scheduling algorithm.
FIFO simply queues processes according to the order they arrive in the ready queue. In this
algorithm, the process that comes first will be executed first and next process starts only
after the previous gets fully executed.
Code:
#include <stdio.h>
int main() {
int n, i;
printf("Enter number of processes: ");
scanf("%d", &n);
wt[0] = 0;
for(i = 1; i < n; i++)
wt[i] = wt[i-1] + bt[i-1];
printf("\nProcess\tBT\tWT\tTAT\n");
for(i = 0; i < n; i++)
printf("P%d\t%d\t%d\t%d\n", i+1, bt[i], wt[i], tat[i]);
return 0;
}
Output:
ii) RR
Code:
#include <stdio.h>
int main() {
int i, j, n, time, remain, flag = 0, tq;
printf("Enter number of processes: ");
scanf("%d", &n);
remain = n;
int wt = 0, tat = 0;
for(time = 0, i = 0; remain != 0;) {
if(rt[i] > 0 && at[i] <= time) {
if(rt[i] <= tq) {
time += rt[i];
rt[i] = 0;
flag = 1;
} else {
rt[i] -= tq;
time += tq;
}
if(flag) {
remain--;
wt += time - at[i] - bt[i];
tat += time - at[i];
flag = 0;
}
}
i = (i+1)%n;
}
Output:
Experiment-6
i) FIFO
Explanation: This is the simplest page replacement algorithm. In this algorithm, the
operating system keeps track of all pages in the memory in a queue, the oldest page is in
the front of the queue. When a page needs to be replaced page in the front of the queue is
selected for removal.
Code:
#include <stdio.h>
printf("Page\tFrames\t\tPage Fault\n");
for (int i = 0; i < n; i++) {
int found = 0;
for (int j = 0; j < capacity; j++) {
if (input[i] == queue[j]) {
found = 1;
break;
}
}
if (!found) {
queue[index] = input[i];
index = (index + 1) % capacity;
fault++;
}
printf("%d\t", input[i]);
for (int k = 0; k < capacity; k++) {
if (queue[k] != -1)
printf("%d ", queue[k]);
else
printf("- ");
}
printf("\t\t%s\n", found ? "No" : "Yes");
}
int main() {
int input[] = {1, 3, 0, 3, 5, 6};
int n = sizeof(input) / sizeof(input[0]);
int capacity = 3;
fifo(input, n, capacity);
return 0;
}
Output:
ii) LRU
Explanation: In this algorithm, page will be replaced which is least recently used.
Code:
#include <stdio.h>
if (!found) {
// Find the LRU frame (smallest time)
pos = findLRU(time, f);
frames[pos] = pages[i];
time[pos] = i; // Set new access time
faults++;
}
}
printf("Total Page Faults = %d\n", faults);
return 0;
}
Output:
Experiment-7
i) FCFS
Explanation: FCFS is the simplest disk scheduling algorithm. As the name suggests, this
algorithm entertains requests in the order they arrive in the disk queue. The algorithm
looks very fair and there is no starvation (all requests are serviced sequentially) but
generally, it does not provide the fastest service.
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, head, i, total = 0;
printf("Enter number of disk requests: ");
scanf("%d", &n);
int req[n];
printf("Enter request sequence: \n");
for(i = 0; i < n; i++) scanf("%d", &req[i]);
printf("Enter initial head position: ");
scanf("%d", &head);
ii) C-Scan
Code:
#include <stdio.h>
#include <stdlib.h>
int pos;
for (i = 0; i < n; i++) {
if (head < request[i]) {
pos = i;
break;
}
}
int main() {
int request[] = {82, 170, 43, 140, 24, 16, 190};
int n = sizeof(request) / sizeof(request[0]);
int head = 50;
int disk_size = 200;
Output: