Avichal Temp OS final
Avichal Temp OS final
KANPUR
Semester- IV
Lab File
Operating
System (BCS401)
List of Experiments
Index
Department Vision Statement
To be a recognized Department of Computer Science & Engineering that produces versatile computer
engineers, capable of adapting to the changing needs of computer and related industry.
i. To provide broad based quality education with knowledge and attitude to succeed in Computer
Science & Engineering careers.
ii. To prepare students for emerging trends in computer and related industry.
iii. To develop competence in students by providing them skills and aptitude to foster culture of
continuous and lifelong learning.
iv. To develop practicing engineers who investigate research, design, and find workable solutions to
complex engineering problems with awareness & concern for society as well as environment.
ii. Graduates will possess capability of designing successful innovative solutions to real life problems
that are technically sound, economically viable and socially acceptable.
iii. Graduates will be competent team leaders, effective communicators and capable of working in
multidisciplinary teams following ethical values.
iv. The graduates will be capable of adapting to new technologies/tools and constantly upgrading
their knowledge and skills with an attitude for lifelong learning
Department Program Outcomes (POs)
The students of Computer Science and Engineering Department will be able:
1. Engineering knowledge: Apply the knowledge of mathematics, science, Computer Science &
Engineering fundamentals, and an engineering specialization to the solution of complex
engineering problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and Computer Science & Engineering sciences.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modelling to complex Computer Science &
Engineering activities with an understanding of the limitations.
6. The Engineering and Society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities relevant
to the professional engineering practice in the field of Computer Science and Engineering.
7. Environment and sustainability: Understand the impact of the professional Computer Science
& Engineering solutions in societal and environmental contexts, and demonstrate the knowledge
of, and need for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the Computer Science & Engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
11. Project management and finance: Demonstrate knowledge and understanding of the
Computer Science & Engineering and management principles and apply these to one’s own work,
as a member and leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
Department Program Specific Outcomes (PSOs)
The students will be able to:
2. Understand the processes that support the delivery and management of information systems
within a specific application environment.
Course Outcomes
*Level of Bloom’s Level to be
*Level of Bloom’s Level to be met
Taxonomy met
Taxonomy
L1: Remember 1 L2: Understand 2
L3: Apply 3 L4: Analyze 4
L5: Evaluate 5 L6: Create 6
Implementation of CPU
Experiment 2
Scheduling Algorithms
a) FCFS b) SJF
Implementation of CPU Scheduling
Experiment 3 Algorithms
c) Priority (Non-Pre-emptive)
d) Multi-level Queue (Level-1 Time
Quantum = 2 ms, Level-2 Time
Quantum = 4 ms, Level-3 FCFS)
Experiment 4
Implementation of resource
allocation graph (RAG).
Implementation of Banker’s
Experiment 5
algorithm for Deadlock
Avoidance.
Conversion of resource allocation
Experiment 6 graph (RAG) to wait for graph (WFG)
for each type of method used for
storing graph.
Implementation of contiguous
Experiment 7 allocation techniques:
a) Worst-Fit b) Best- Fit c) First- Fit
Theory:
COMMAND:
1. Date Command:
This command is used to display the current data and time.
Syntax: $date
Output:
2. Calender Command:
This command is used to display the calendar of the year or the particular month of calendar year.
Syntax:
a. $cal<year>
b. $cal<month><year>
Here the first syntax gives the entire calendar for given year & the second Syntax gives the calendar
of reserved month of that year.
Output:
a.
b.
3. Echo Command:
This command is used to print the arguments on the screen.
Output:
Output:
To have the output in different line, the following command can be used.
Output:
4. ’who’ Command:
It is used to display who are the users connected to our computer currently.
Options:
H–Display the output with headers.
Output:
Options:
b–Display the last booting date or time or when the system was lastly rebooted.
Output:
5. ’who am i’ Command:
Display the details of the current working directory.
Syntax: $who am i
Output:
6. ’tty’ Command:
It will display the terminal name.
Syntax: $tty
Output:
7. ’CLEAR’ Command:
It is used to clear the screen.
Syntax: $clear
Output:
8. ’MAN’ Command:
It helps us to know about the particular command and its options & working. It is like
„help‟ command in windows.
Output:
9. MANIPULATION Command:
It is used to manipulate the screen.
Syntax: $tput<argument>
Arguments:
Output:
Output:
Output:
10.LIST Command:
It is used to list all the contents in the current working directory.
If the command does not contain any argument means it is working in the Current directory.
Options:
a– used to list all the files including the hidden files. c– list all the files column wise.
Output:
Options:
c– list all the files column wise.
Output:
Options:
d- list all the directories.
Output:
Options:
m- list the files separated by commas.
Output:
Options:
p- list files include „/‟ to all the directories.
Output:
Options:
r- list the files in reverse alphabetical order.
Output:
Options:
f- list the files based on the list modification date.
Output:
Options:
x-list in column wise sorted order.
Output:
Syntax: $pwd
Output:
2. MKDIR Command:
To create or make a new directory in a current directory.
Output:
3. CD Command:
To change or move the directory to mentioned directory.
Output:
4. RMDIR Command:
To remove a directory in the current directory & not the current directory itself.
Output:
1. CREATE A FILE:
To create a new file in the current directory we use CAT command.
Syntax:
Output:
2. DISPLAY A FILE:
To display the content of file mentioned we use CAT command without „>‟ operator.
Syntax:
$cat <filename.
Options –s = to neglect the warning /error message.
Output:
3. COPYING CONTENTS:
To copy the content of one file with another. If file doesnot exist, a new file is
created and if the file exists with some data then it is overwritten.
Syntax:
Options:
-n content of file with numbers included with blank lines.
Output:
Syntax:
$cat –n <filename>
Output:
4. SORTING A FILE:
Syntax:
Option:
$ sort –r <filename>
Output:
Syntax:
$cp<source filename><destination filename>
Output:
Syntax:
$cp<source filename path ><destination filename path>
Output:
6. MOVE Command:
To completely move the contents from source file to destination file and to remove the source file.
Syntax:
$ mv <source filename><destination filename>
Output:
7. REMOVE Command:
Syntax:
$rm<filename>
Output:
8. WORD Command:
Syntax:
$wc<filename>
Output:
Options:
-c – to display no of characters.
Output:
Options:
Options:
-w – to display the no. of words.
Output:
9. LINE PRINTER:
Syntax:
$lp<filename>
Output:
10. PAGE Command:
This command is used to display the contents of the file page wise & next page can
be viewed by pressing the enter key.
Syntax:
$ more<filename> –displays the content of example.txt page-wise. Press Enter to move to
the next line, Space to move to the next page, and `q` to quit.
Output:
Syntax:
Output:
Syntax: $head<filename>
Output:
TAIL: This command is used to display the last ten lines of file.
Syntax: $tail<filename>
Output:
GREP: This command is used to search and print the specified patterns from the file.
Options: -i: Ignore case distinctions in both the pattern and the input files.
Output:
Output:
Options: -c: Count the number of matching lines and print the count instead of the lines.
Output:
Options: -l: Print only the names of files with matching lines (once per file).
Output:
Options: -n: Prefix each line of output with the line number within its input file.
Output:
Output:
Output:
Output:
Syntax: $sort<filename>
Output:
PIPE: It is a mechanism by which the output of one command can be channeled into the input of another command.
Syntax: $who | wc -1
Output:
TR: The tr filter is used to translate one set of characters from the standard inputs to another.
Output:
Experiment 2
Implementation of CPU Scheduling Algorithms
a) FCFS b) SJF
a.) FCFS
#include <stdio.h>
struct Process {
int id;
int arrival_time;
int burst_time;
int
waiting_time;
int turnaround_time;
};
processes[0].waiting_time =
0; for (int i = 1; i < n; i++) {
processes[i].waiting_time = processes[i-1].waiting_time + processes[i-1].burst_time;
}
int main()
{ int n;
calculateTimes(processes, n);
return 0;
}
OUTPUT:
#include <stdio.h>
struct Process
{ int id;
int arrival_time;
int burst_time;
int
waiting_time;
int turnaround_time;
int completion_time;
};
while (completed != n)
{ int idx = -1;
int min_burst = 99999;
if (idx != -1) {
processes[idx].completion_time = current_time + processes[idx].burst_time;
processes[idx].turnaround_time = processes[idx].completion_time -
processes[idx].arrival_time; processes[idx].waiting_time = processes[idx].turnaround_time -
processes[idx].burst_time;
total_waiting_time += processes[idx].waiting_time;
total_turnaround_time += processes[idx].turnaround_time;
completed++;
current_time = processes[idx].completion_time;
} else {
current_time++;
}
}
int main()
{ int n;
calculateTimes(processes, n);
return 0;
}
OUTPUT:
b) Multi-level Queue (Level-1 Time Quantum = 2 ms, Level-2 Time Quantum = 4 ms, Level-
3 FCFS)
a) Priority (Non-Pre-emptive)
#include <stdio.h>
struct Process
{ int id;
int
arrival_time;
int burst_time;
int priority;
int waiting_time;
int turnaround_time;
int completion_time;
};
while (completed != n)
{ int idx = -1;
int highest_priority = -1;
if (idx != -1) {
processes[idx].completion_time = current_time +
processes[idx].burst_time; processes[idx].turnaround_time =
processes[idx].completion_time -
processes[idx].arrival_time;
processes[idx].waiting_time = processes[idx].turnaround_time - processes[idx].burst_time;
total_waiting_time += processes[idx].waiting_time;
total_turnaround_time +=
processes[idx].turnaround_time;
completed++;
current_time = processes[idx].completion_time;
} else {
current_time++;
}
}
int main()
{ int n;
struct Process
i < n; i++) {
processes[i].id = i + 1;
printf("Enter arrival time, burst time and priority for process %d: ", i + 1);
scanf("%d %d %d", &processes[i].arrival_time, &processes[i].burst_time,
&processes[i].priority);
processes[i].completion_time = 0; // Initially, no process is completed
}
calculateTimes(processes, n);
return 0;
}
OUTPUT:
Process Arrival Time Burst Time Priority Waiting Time Turnaround Time
P1 0 4 2 3 7
P2 1 3 1 6 9
P3 2 1 3 0 1
#include <stdio.h>
#include <stdbool.h>
#define MAX_PROCESSES
100 struct Process {
int id;
int
arrival_time;
int burst_time;
int
remaining_time;
int waiting_time;
int turnaround_time;
int completion_time;
int queue_level;
};
void roundRobin(struct Process processes[], int n, int time_quantum, int start_time, int end_time)
{ int time = start_time;
bool done;
do {
done = true;
for (int i = 0; i < n; i++) {
if (processes[i].remaining_time > 0 && processes[i].queue_level == 1)
{ done = false;
if (processes[i].remaining_time > time_quantum)
{ time += time_quantum;
processes[i].remaining_time -= time_quantum;
} else {
time +=
processes[i].remaining_time;
processes[i].completion_time = time;
processes[i].remaining_time = 0;
processes[i].turnaround_time = processes[i].completion_time - processes[i].arrival_time;
processes[i].waiting_time = processes[i].turnaround_time - processes[i].burst_time;
}
}
}
} while (!done && time <= end_time);
}
void fcfs(struct Process processes[], int n, int start_time)
{ int time = start_time;
roundRobin(processes, n, 2, 0, MAX_PROCESSES);
roundRobin(processes, n, 4, 0, MAX_PROCESSES);
fcfs(processes, n, 0);
calculateTimes(processes,
n); return 0;
}
OUTPUT:
Process Arrival Time Burst Time Queue Level Waiting Time Turnaround Time
P1 0 5 1 2 7
P2 2 3 2 4 7
P3 4 1 3 0 1
#include
<stdio.h> #define
MAX 100
printf("\nRequest Matrix:\n");
for (int i = 0; i < processes; i++) {
for (int j = 0; j < resources; j++)
{
printf("%d ", request[i][j]);
}
printf("\n");
}
}
int main() {
int processes, resources;
int allocation[MAX]
[MAX]; int request[MAX]
[MAX];
Request
Matrix:
010
001
110
Experiment 5
Implementation of Banker’s algorithm for Deadlock Avoidance.
#include <stdio.h>
#include <stdbool.h>
#define MAX_PROCESSES 10
#define MAX_RESOURCES 10
bool finished[MAX_PROCESSES] =
{0}; int work[MAX_RESOURCES];
for (int i = 0; i < resources; i++)
{ work[i] = available[i];
}
while (true) {
bool found = false;
for (int i = 0; i < processes; i++)
{ if (!finished[i]) {
bool canAllocate = true;
for (int j = 0; j < resources; j++)
{ if (need[i][j] > work[j]) {
canAllocate =
false; break;
}
}
if (canAllocate) {
for (int j = 0; j < resources; j++)
{ work[j] += allocation[i][j];
}
finished[i] = true;
found = true;
}
}
}
if (!found) {
for (int i = 0; i < processes; i++)
{ if (!finished[i]) {
return false;
}
}
return true;
}
}
}
int main() {
int processes, resources;
int allocation[MAX_PROCESSES]
[MAX_RESOURCES]; int max[MAX_PROCESSES]
[MAX_RESOURCES];
int available[MAX_RESOURCES];
#include <stdio.h>
#include <stdlib.h>
#define MAX_PROCESSES 10
#define MAX_RESOURCES 10
int main() {
int processes, resources;
printf("Enter the RAG adjacency matrix (%d x %d):\n", processes + resources, processes
+ resources);
for (int i = 0; i < processes + resources; i++) {
for (int j = 0; j < processes + resources; j++)
{
scanf("%d", &ragMatrix[i][j]);
}
}
return 0;
}
OUTPUT:
WFG Adjacency
List: P0: NULL
P1: NULL
P2: P1 -> NULL
Experiment 7
Implementation of contiguous allocation techniques:
a) Worst-Fit b) Best- Fit c) First- Fit
a) Worst-Fit
#include <stdio.h>
int blockSize[m];
printf("Enter sizes of memory blocks:\
n"); for (int i = 0; i < m; i++) {
scanf("%d", &blockSize[i]);
}
int processSize[n];
printf("Enter sizes of processes:\
n"); for (int i = 0; i < n; i++) {
scanf("%d", &processSize[i]);
}
return 0;
}
OUTPUT:
#include <stdio.h>
int blockSize[m];
printf("Enter sizes of memory blocks:\
n"); for (int i = 0; i < m; i++) {
scanf("%d", &blockSize[i]);
}
printf("Enter the number of processes:
"); scanf("%d", &n);
int processSize[n];
printf("Enter sizes of processes:\
n"); for (int i = 0; i < n; i++) {
scanf("%d", &processSize[i]);
}
bestFit(blockSize, m, processSize, n);
return 0;
}
OUTPUT:
#include <stdio.h>
void firstFit(int blockSize[], int m, int processSize[], int n) { int allocation[n];
for (int i = 0; i < n; i++)
{ allocation[i] = -1;
}
int main()
{ int m,
n;
int blockSize[m];
printf("Enter sizes of memory blocks:\
n"); for (int i = 0; i < m; i++) {
scanf("%d", &blockSize[i]);
}
int processSize[n];
printf("Enter sizes of processes:\
n"); for (int i = 0; i < n; i++) {
scanf("%d", &processSize[i]);
}
return 0;
}
OUTPUT: