You are on page 1of 70

INDEX

Sr. Name of Experiments Remarks


No.
1. To study and use different linux commands.
2. Write a shell script to accept and add 2 numbers.
3. Write a shell script to accept radius of a circle and show its area.
4. Write a shell script to:
i) Accept 2 numbers and find the greater of the 2
ii) Accept 3 numbers and find the smallest of the 3
5. Write a shell script to:
i) Swap 2 numbers with help of 3rd variable
ii) Swap 2 numbers without help of 3rd variable
6. Write a shell script to accept marks and print the grade.
7. Write a shell script to accept a number and print its factorial.
8. Write a shell script to print the Fibonacci series.
9. Write a shell script to implement a simple calculator.
10. Write a shell script that accepts a file name, star ng and ending line
numbers as arguments and displays all the lines of the file between
the given line numbers.
11. Write a shell script that deletes all lines containing a specified word.
12. Write a shell script that displays a list of all files in the current direc-
tory.
13. Implement FCFS CPU scheduling using any language of choice.
14. Implement SJF CPU scheduling using any language of choice
15. Implement SRTN CPU scheduling using any language of choice
16. Implement Round Robin CPU scheduling using any language of choice
17. Implement Priority Scheduling CPU scheduling using any language of
choice.
18. Implement Preemp ve Priority Scheduling CPU scheduling using any
language of choice.
19. Implement Banker’s Algorithm using any language of choice.
20. Implement FIFO Page Replacement Algorithm using any language of
choice.
21. Implement LRU Page Replacement Algorithm using any language of
choice.
22. Implement Op mal Page Replacement Algorithm using any language
of choice.
23. Implement FCFS Disk Scheduling Algorithm using any language of
choice.
24. Implement SSTF Disk Scheduling Algorithm using any language of
choice.

Saahil Lashkari 4CSE3+MBA A023116121002


25. Implement SCAN Disk Scheduling Algorithm using any language of
choice.
26. Implement LOOK Disk Scheduling Algorithm using any language of
choice.
27. OPEN ENDED:
a) Memory Consump on and Ac vity Monitor: Develop an
applica on which is able to iden fy the tasks and ac vi es
consuming memory resources
b) WAP to generate maximum number of child process in your
system and explain with the help of program what are Zombie
processes.

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 1
OBJECTIVE – To study and use different linux commands.
SOFTWARE USED – Kali Linux OS
PERFORMANCE –
1) man: It is used to display the user manual of any command that we can run on the
terminal.

2) pwd: It stands for Print Working Directory. It prints the path of the working directory,
starting from the root.

3) cd: It is known as change directory command. It is used to change current working


directory.

4) ls: It lists directory contents of files and directories. It has many options such as:
a) -l: to display long list
b) -t: to sort by modification time
c) -s: to sort by size
d) -h: to list files in human readable format
e) -r: to reverse the order

Saahil Lashkari 4CSE3+MBA A023116121002


5) mkdir: It allows the user to create directories.

6) rmdir: It is used remove empty directories from the filesystem.

7) vi: It is the default editor that comes with the UNIX operating system is called vi (visual
editor). Using vi editor, we can edit an existing file or create a new file from scratch. we can
also use this editor to just read a text file.

Saahil Lashkari 4CSE3+MBA A023116121002


Once the file open, you can use different commands to edit, save and quit the file.
a) Esc + i + ⏎ : Inserts text before current cursor location.

b) Esc + : + w + ⏎ : Saves the file.

c) Esc + : + q + ⏎ : Quits the file.

8) cat: It reads data from the file and gives their content as output. It dumps an entire file to
standard output. It is good for displaying short, simple files.

Saahil Lashkari 4CSE3+MBA A023116121002


9) less: It is used to read the contents of a text file one page(one screen) at a time. It has
faster access because if file is large it doesn’t access the complete file, but accesses it page
by page. It displays a file, allowing forward/backward movement within it
a) ⏎ scrolls forward one line, space one page
b) y scrolls back one line, b one page
c) use “/string” to search for a string
d) Press q to quit

10) head: It prints the top N number of data of the given input. By default, it prints the first
10 lines of the specified files. If more than one file name is provided then data from each file
is preceded by its file name.

11) tail: It prints the last N number of data of the given input. By default, it prints the last 10
lines of the specified files. If more than one file name is provided then data from each file is
preceded by its file name.

Saahil Lashkari 4CSE3+MBA A023116121002


12) cp: It stands for copy. This command is used to copy files or group of files or directory. It
creates an exact image of a file on a disk with different file name. cp command require at
least two filenames in its arguments.

13) mv: It stands for move. mv is used to move one or more files or directories from one
place to another in a file system like UNIX. It has two distinct functions:
a) It renames a file or folder.
b) It moves a group of files to a different directory.

Saahil Lashkari 4CSE3+MBA A023116121002


14) rm: It stands for remove. rm command is used to remove objects such as files,
directories, symbolic links and so on from the file system like UNIX.

15) wc: wc stands for word count. As the name implies, it is mainly used for counting
purpose.
a) It is used to find out number of lines, word count, byte and characters count in the
files
specified in the file arguments.
b) By default it displays four-columnar output.
c) First column shows number of lines present in a file specified, second column
shows
number of words present in the file, third column shows number of characters
present in
file and fourth column itself is the file name which are given as argument.

16) ps: it allows viewing information related with the processes on a system. It stands for
“Process Status”.

17) top: it is used to show the Linux processes.


(omit)

Saahil Lashkari 4CSE3+MBA A023116121002


18) pipes (|): It is a way to connect the output of 1 program to the input of another program
without any temporary file.

Saahil Lashkari 4CSE3+MBA A023116121002


19) grep: The grep filter searches a file for a particular pattern of characters, and displays all
lines that contain that pattern.

20) finger: Finger command is a user information lookup command which gives details of all
the users logged in.

Saahil Lashkari 4CSE3+MBA A023116121002


21) history: history command is used to view the previously executed command.

22) uname: it displays the information about the system.

23) whoami: it displays the username of the current user when this command is invoked.

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 2
OBJECTIVE – Write a shell script to accept and add 2 numbers.
SOFTWARE USED – Kali Linux OS
PERFORMANCE –

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 3
OBJECTIVE – Write a shell script to accept radius of a circle and show its area.
SOFTWARE USED – Kali Linux OS
PERFORMANCE –

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 4
OBJECTIVE – Write a shell script to:
i) Accept 2 numbers and find the greater of the 2
ii) Accept 3 numbers and find the smallest of the 3
SOFTWARE USED – Kali Linux OS
PERFORMANCE –
i)

ii)

Saahil Lashkari 4CSE3+MBA A023116121002


Saahil Lashkari 4CSE3+MBA A023116121002
EXPERIMENT NO – 5
OBJECTIVE – Write a shell script to:
i) Swap 2 numbers with help of 3rd variable
ii) Swap 2 numbers without help of 3rd variable
SOFTWARE USED – Kali Linux OS
PERFORMANCE –
i)

ii)

Saahil Lashkari 4CSE3+MBA A023116121002


Saahil Lashkari 4CSE3+MBA A023116121002
EXPERIMENT NO – 6
OBJECTIVE – Write a shell script to accept marks and print the grade.
SOFTWARE USED – Kali Linux OS
PERFORMANCE –

Saahil Lashkari 4CSE3+MBA A023116121002


Saahil Lashkari 4CSE3+MBA A023116121002
EXPERIMENT NO – 7
OBJECTIVE – Write a shell script to accept a number and print its factorial.
SOFTWARE USED – Kali Linux OS
PERFORMANCE –

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 8
OBJECTIVE – Write a shell script to print the Fibonacci series.
SOFTWARE USED – Kali Linux OS
PERFORMANCE –

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 9
OBJECTIVE – Write a shell script to implement a simple calculator.
SOFTWARE USED – Kali Linux OS

PERFORMANCE –

Saahil Lashkari 4CSE3+MBA A023116121002


Saahil Lashkari 4CSE3+MBA A023116121002
EXPERIMENT NO – 10
OBJECTIVE – Write a shell script that accepts a file name, star ng and ending line numbers
as arguments and displays all the lines of the file between the given line numbers.
SOFTWARE USED – Kali Linux OS
PERFORMANCE –

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 11
OBJECTIVE – Write a shell script that deletes all lines containing a specified word.
SOFTWARE USED – Kali Linux OS
PERFORMANCE –

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 12
OBJECTIVE – Write a shell script that displays a list of all files in the current directory.
SOFTWARE USED – Kali Linux OS
PERFORMANCE –

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 13
OBJECTIVE – Implement FCFS CPU scheduling using any language of choice
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
Simplest CPU scheduling algorithm that schedules according to arrival mes of processes.
First come first serve scheduling algorithm states that the process that requests the CPU
first is allocated the CPU first. It is implemented by using the FIFO queue. When a process
enters the ready queue, its PCB is linked to the tail of the queue. When the CPU is free, it is
allocated to the process at the head of the queue. The running process is then removed
from the queue. FCFS is a non-preemp ve scheduling algorithm.
PERFORMANCE –

#include <iostream>
using namespace std;

class process
{
public:
int id;
int arrival;
int burst;
int finish;
int tat;
int wait;

process()
{
arrival = 0;
burst = 0;
id = 0;
}

process(int a, int b, int i)


{
arrival = a;
burst = b;
id = i + 1;
}

void sort(process *p, int n)


{
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{

Saahil Lashkari 4CSE3+MBA A023116121002


if (p[j].arrival > p[j + 1].arrival)
{
int temp;

// sorting burst times


temp = p[j].burst;
p[j].burst = p[j + 1].burst;
p[j + 1].burst = temp;

// sorting arrival times


temp = p[j].arrival;
p[j].arrival = p[j + 1].arrival;
p[j + 1].arrival = temp;

// sorting IDs
temp = p[j].id;
p[j].id = p[j + 1].id;
p[j + 1].id = temp;
}
}
}
}

void calc(process *p, int n)


{
int sum = 0;
sum = sum + p[0].arrival;
for (int i = 0; i < n; i++)
{
sum = sum + p[i].burst;
p[i].finish = sum;
p[i].tat = p[i].finish - p[i].arrival;
p[i].wait = p[i].tat - p[i].burst;
}
}

void display(process *p, int n)


{
cout << "Process\tArrival\tBurst\tFinish\tTurn Around\tWaiting\n";
for (int i = 0; i < n; i++)
{
cout << " P[" << p[i].id << "]\t " << p[i].arrival << "\t" <<
p[i].burst << "\t" << p[i].finish << "\t" << p[i].tat << "\t\t " << p[i].wait
<< "\n";
}
}
};

Saahil Lashkari 4CSE3+MBA A023116121002


int main()
{
int n = 0;
cout << "Enter no of processes: ";
cin >> n;
process *p = new process[n];

int i;
for (i = 0; i < n; i++)
{
int a, b;
cout << "Enter arrival time for process P" << i + 1 << ":";
cin >> a;
cout << "Enter burst time for process P" << i + 1 << ":";
cin >> b;
p[i] = process(a, b, i);
cout << "\n";
}

process f;
f.sort(p, n);
f.calc(p, n);
f.display(p, n);

return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 14
OBJECTIVE – Implement SJF CPU scheduling using any language of choice
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
The shortest job first (SJF) or shortest job next, is a scheduling policy that selects the wai ng
process with the smallest execu on me to execute next. Shortest Job first has the ad-
vantage of having a minimum average wai ng me among all scheduling algorithms. It is a
Greedy Algorithm. It may cause starva on if shorter processes keep coming. This problem
can be solved using the concept of ageing. It is prac cally infeasible as Opera ng System
may not know burst mes and therefore may not sort them. While it is not possible to pre-
dict execu on me, several methods can be used to es mate the execu on me for a job,
such as a weighted average of previous execu on mes. SJF can be used in specialized envi-
ronments where accurate es mates of running me are available.
PERFORMANCE –

#include <iostream>
using namespace std;

class process
{
public:
int id;
int arrival;
int burst;
int finish;
int tat;
int wait;

process()
{
arrival = 0;
burst = 0;
id = 0;
}

process(int a, int b, int i)


{
arrival = a;
burst = b;
id = i + 1;
}

void sort(process *p, int n)


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

Saahil Lashkari 4CSE3+MBA A023116121002


{
for (int j = i + 1; j < n - 1; j++)
{
if (p[i].burst > p[j].burst)
{
int temp;

// sorting burst times


temp = p[j].burst;
p[j].burst = p[j + 1].burst;
p[j + 1].burst = temp;

// sorting arrival times


temp = p[j].arrival;
p[j].arrival = p[j + 1].arrival;
p[j + 1].arrival = temp;

// sorting IDs
temp = p[j].id;
p[j].id = p[j + 1].id;
p[j + 1].id = temp;
}
}
}
}

void calc(process *p, int n)


{
int sum = 0;
sum = sum + p[0].arrival;
for (int i = 0; i < n; i++)
{
sum = sum + p[i].burst;
p[i].finish = sum;
p[i].tat = p[i].finish - p[i].arrival;
p[i].wait = p[i].tat - p[i].burst;
}
}

void display(process *p, int n)


{
cout << "Process\tArrival\tBurst\tFinish\tTurn Around\tWaiting\n";
for (int i = 0; i < n; i++)
{
cout << " P[" << p[i].id << "]\t " << p[i].arrival << "\t" <<
p[i].burst << "\t" << p[i].finish << "\t" << p[i].tat << "\t\t " << p[i].wait
<< "\n";
}

Saahil Lashkari 4CSE3+MBA A023116121002


}
};

int main()
{
int n = 0;
cout << "Enter no of processes: ";
cin >> n;
process *p = new process[n];

int i;
for (i = 0; i < n; i++)
{
int a, b;
cout << "Enter arrival time for process P" << i + 1 << ":";
cin >> a;
cout << "Enter burst time for process P" << i + 1 << ":";
cin >> b;
p[i] = process(a, b, i);
cout << "\n";
}

process f;
f.sort(p, n);
f.calc(p, n);
f.display(p, n);

return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 15
OBJECTIVE – Implement SRTN CPU scheduling using any language of choice
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
The shortest remaining me next (SRTN), is the pre-emp ve version of SJF scheduling and
shares all of its remaining characteris cs.
PERFORMANCE –
#include <bits/stdc++.h>
using namespace std;

class process
{
public:
int id;
int burst;
int arrival;

process()
{
arrival = 0;
burst = 0;
id = 0;
}

process(int a, int b, int i)


{
arrival = a;
burst = b;
id = i + 1;
}
};

void findWaitingTime(process p[], int n,


int wait[])
{
int remain[n];

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


remain[i] = p[i].burst;

int complete = 0, t = 0, minimum = INT_MAX;


int shortest = 0, finish;
bool check = false;

Saahil Lashkari 4CSE3+MBA A023116121002


while (complete != n)
{
for (int j = 0; j < n; j++)
{
if ((p[j].arrival <= t) &&
(remain[j] < minimum) && remain[j] > 0)
{
minimum = remain[j];
shortest = j;
check = true;
}
}

if (check == false)
{
t++;
continue;
}

remain[shortest]--;

minimum = remain[shortest];
if (minimum == 0)
minimum = INT_MAX;

if (remain[shortest] == 0)
{
complete++;
check = false;

finish = t + 1;

wait[shortest] = finish -
p[shortest].burst -
p[shortest].arrival;

if (wait[shortest] < 0)
wait[shortest] = 0;
}
t++;
}
}

void findTurnAroundTime(process p[], int n,


int wait[], int tat[])
{
for (int i = 0; i < n; i++)
tat[i] = p[i].burst + wait[i];

Saahil Lashkari 4CSE3+MBA A023116121002


}

void findavgTime(process p[], int n)


{
int wait[n], tat[n], total_wait = 0,
total_tat = 0;

findWaitingTime(p, n, wait);

findTurnAroundTime(p, n, wait, tat);

cout << "Process\tArrival\tBurst\tFinish\tTurn Around\tWaiting\n";

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


{
total_wait = total_wait + wait[i];
total_tat = total_tat + tat[i];
cout << "P" << p[i].id
<< "\t" << p[i].arrival << "\t" << p[i].burst << "\t" << tat[i] +
p[i].arrival
<< "\t " << tat[i]
<< "\t\t " << wait[i] << endl;
}

int main()
{
int n = 0;
cout << "Enter no of processes: ";
cin >> n;
process *p = new process[n];

int i;
for (i = 0; i < n; i++)
{
int a, b;
cout << "Enter arrival time for process P" << i + 1 << ":";
cin >> a;
cout << "Enter burst time for process P" << i + 1 << ":";
cin >> b;
p[i] = process(a, b, i);
cout << "\n";
}

findavgTime(p, n);
return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


Saahil Lashkari 4CSE3+MBA A023116121002
EXPERIMENT NO – 16
OBJECTIVE – Implement Round Robin CPU scheduling using any language of choice.
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
Round Robin is a CPU scheduling algorithm where each process is assigned a fixed me slot
in a cyclic way. It is basically the preemp ve version of First come First Serve CPU Scheduling
algorithm. Round Robin CPU Algorithm generally focuses on Time Sharing technique. The
period of me for which a process or job is allowed to run in a pre-emp ve method is called
me quantum. Each process or job present in the ready queue is assigned the CPU for that
me quantum, if the execu on of the process is completed during that me then the pro-
cess will end else the process will go back to the wai ng table and wait for its next turn to
complete the execu on.
PERFORMANCE –
#include <iostream>
using namespace std;

int main()
{
int i, n, finish = 0, count = 0, a, quantum, wait = 0, tat = 0, arri-
val[10], burst[10], temp[10];
cout << "Total number of process in the system: ";
cin >> n;
a = n;
for (int i = 0; i < n; i++)
{
int a, b;
cout << "Enter arrival time for process P" << i + 1 << ":";
cin >> arrival[i];
cout << "Enter burst time for process P" << i + 1 << ":";
cin >> burst[i];
temp[i] = burst[i];
cout << "\n";
}

cout << "Enter the Time Quantum for the process: ";
cin >> quantum;
cout << "Process\tArrival\tBurst\tFinish\tTurn Around\tWaiting\n";
for (finish = 0, i = 0; a != 0;)
{
if (temp[i] <= quantum && temp[i] > 0)
{
finish = finish + temp[i];
temp[i] = 0;
count = 1;

Saahil Lashkari 4CSE3+MBA A023116121002


}
else if (temp[i] > 0)
{
temp[i] = temp[i] - quantum;
finish = finish + quantum;
}
if (temp[i] == 0 && count == 1)
{
a--;
cout << "P" << i + 1 << "\t " << arrival[i] << "\t " << burst[i]
<< "\t" << finish << "\t " << finish - arrival[i] << "\t\t" << finish - arri-
val[i] - burst[i] << "\n";
wait = wait + finish - arrival[i] - burst[i];
tat = tat + finish - arrival[i];
count = 0;
}
if (i == n - 1)
{
i = 0;
}
else if (arrival[i + 1] <= finish)
{
i++;
}
else
{
i = 0;
}
}
return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 17
OBJECTIVE – Implement Priority Scheduling CPU scheduling using any language of choice.
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
Priority scheduling is a non-preemp ve algorithm and one of the most common scheduling
algorithms in batch systems. Each process is assigned first arrival me (less arrival me pro-
cess first) if two processes have same arrival me, then compare to priori es (highest pro-
cess first). Also, if two processes have same priority then compare to process number (less
process number first). This process is repeated while all process get executed.
PERFORMANCE –
#include <bits/stdc++.h>
using namespace std;

#define totalprocess 4

class process
{
public:
int arrival, burst, priority, id;
};

process p[50];

bool comp(process a, process b)


{
if (a.arrival == b.arrival)
{
return a.priority < b.priority;
}
else
{
return a.arrival < b.arrival;
}
}

void get_wt_time(int wait[])


{
int service[50];

service[0] = p[0].arrival;
wait[0] = 0;

for (int i = 1; i < totalprocess; i++)


{
service[i] = p[i - 1].burst + service[i - 1];

Saahil Lashkari 4CSE3+MBA A023116121002


wait[i] = service[i] - p[i].arrival;
if (wait[i] < 0)
{
wait[i] = 0;
}
}
}

void get_tat_time(int tat[], int wait[])


{
for (int i = 0; i < totalprocess; i++)
{
tat[i] = p[i].burst + wait[i];
}
}

void findgc()
{
int wait[50], tat[50];
get_wt_time(wait);
get_tat_time(tat, wait);

int start[50], finish[50];

start[0] = p[0].arrival;
finish[0] = start[0] + tat[0];

for (int i = 1; i < totalprocess; i++)


{
start[i] = finish[i - 1];
finish[i] = start[i] + tat[i] - wait[i];
}

cout << "Process\tArrival\tBurst\tPriority Finish\tTurn Around\tWait" <<


endl;
for (int i = 0; i < totalprocess; i++)
{
cout << " P[" << p[i].id << "]\t" << p[i].arrival << "\t" <<
p[i].burst << "\t" << p[i].priority << "\t" << finish[i] << "\t" << tat[i] <<
"\t\t" << wait[i] << endl;
}
}

int main()
{
for (int i = 0; i < totalprocess; i++)
{
cout << "Enter arrival time for process P" << i + 1 << ":";

Saahil Lashkari 4CSE3+MBA A023116121002


cin >> p[i].arrival;
cout << "Enter burst time for process P" << i + 1 << ":";
cin >> p[i].burst;
cout << "Enter priority for process P" << i + 1 << ":";
cin >> p[i].priority;
p[i].id = i + 1;
cout << "\n";
}

sort(p, p + totalprocess, comp);

findgc();
return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 18
OBJECTIVE – Implement Preemp ve Priority Scheduling CPU scheduling using any language
of choice.
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
Preemp ve Priority CPU Scheduling Algorithm is a pre-emp ve method of CPU scheduling
algorithm that works based on the priority of a process. In this algorithm, the scheduler
schedules the tasks to work as per the priority, which means that a higher priority process
should be executed first. In case of any conflict, i.e., when there is more than one process
with equal priori es, then the pre-emp ve priority CPU scheduling algorithm works on the
basis of FCFS (First Come First Serve) algorithm.
PERFORMANCE –
#include <iostream>
using namespace std;
int main()
{
int n = 0;
cout << "Enter no of processes: ";
cin >> n;
int arrival[n], burst[n], priority[n];

int i;
for (i = 0; i < n; i++)
{
int a, b;
cout << "Enter arrival time for process P" << i + 1 << ":";
cin >> arrival[i];
cout << "Enter burst time for process P" << i + 1 << ":";
cin >> burst[i];
cout << "Enter priority for process P" << i + 1 << ":";
cin >> priority[i];
cout << "\n";
}
int x[n];

int wait[n], tat[n], finish[n];


i = 0;
int j, smallest, count = 0, time; // count -> number of processes com-
pleted
double end;

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


x[i] = burst[i];

Saahil Lashkari 4CSE3+MBA A023116121002


priority[n] = 10000;

for (time = 0; count != n; time++)


{
smallest = n;
for (i = 0; i < n; i++)
{
if (arrival[i] <= time && priority[i] < priority[smallest] &&
burst[i] > 0)
smallest = i;
}
burst[smallest]--;
if (burst[smallest] == 0)
{
count++;
end = time + 1;
finish[smallest] = end;
wait[smallest] = end - arrival[smallest] - x[smallest];
tat[smallest] = end - arrival[smallest];
}
}
cout << "Process\tArrival\tBurst\tPriority Finish\tTurn Around\tWait" <<
endl;

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


{
cout << "P[" << i + 1 << "]\t" << arrival[i] << "\t" << burst[i] <<
"\t" << priority[i] << "\t" << finish[i] << "\t" << tat[i] << "\t\t" <<
wait[i] << endl;
}
}

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 19
OBJECTIVE – Implement Banker’s Algorithm using any language of choice.
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
The banker’s algorithm is a resource alloca on and deadlock avoidance algorithm that tests
for safety by simula ng the alloca on for the predetermined maximum possible amounts of
all resources, then makes an “s-state” check to test for possible ac vi es, before deciding
whether alloca on should be allowed to con nue.
PERFORMANCE –
#include <iostream>
#define MAX 20
using namespace std;

class bankers
{
private:
int allocated[MAX][MAX], a[MAX][MAX], b[MAX][MAX], available[MAX];
int n, resources, k, result[MAX], id, work[MAX], finish[MAX];

public:
bankers()
{
k = 0;
for (int i = 0; i < MAX; i++)
{
for (int j = 0; j < MAX; j++)
{
allocated[i][j] = 0;
a[i][j] = 0;
b[i][j] = 0;
}
available[i] = 0;
result[i] = 0;
finish[i] = 0;
}
}

void input()
{
int i, j;
cout << "Enter the number of processes:";
cin >> n;
cout << "Enter the number of resources:";
cin >> resources;
cout << "Enter the allocated resources for each process: " << endl;

Saahil Lashkari 4CSE3+MBA A023116121002


for (i = 0; i < n; i++)
{
cout << "\nProcess " << i << ":\n";
for (j = 0; j < resources; j++)
{
cout << "Resource " << j << ":";
cin >> allocated[i][j];
}
}
cout << "\nEnter the maximum resources that are needed for each pro-
cess: ";
for (i = 0; i < n; i++)
{
cout << "\nProcess " << i << ":\n";
for (j = 0; j < resources; j++)
{
cout << "Resource " << j << ":";
cin >> a[i][j];
b[i][j] = a[i][j] - allocated[i][j];
}
}
cout << "\nEnter the currently available resources in the system: ";
for (j = 0; j < resources; j++)
{
cout << "Resource " << j << ":";
cin >> available[j];
work[j] = -1;
}
for (i = 0; i < n; i++)
finish[i] = 0;
}

void method()
{
int i = 0, j, flag;
while (1)
{
if (finish[i] == 0)
{
id = search(i);
if (id != -1)
{
result[k++] = i;
finish[i] = 1;
for (j = 0; j < resources; j++)
{
available[j] = available[j] + allocated[i][j];
}

Saahil Lashkari 4CSE3+MBA A023116121002


}
}
i++;
if (i == n)
{
flag = 0;
for (j = 0; j < resources; j++)
if (available[j] != work[j])

flag = 1;
for (j = 0; j < resources; j++)
work[j] = available[j];

if (flag == 0)
break;
else
i = 0;
}
}
}

int search(int i)
{
int j;
for (j = 0; j < resources; j++)
if (b[i][j] > available[j])
return -1;
return 0;
}

void display()
{
int i, j;
cout << endl
<< "OUTPUT:";
cout << endl
<< "========";
cout << endl
<< "PROCESS\t ALLOCATED\t MAXIMUM\t NEED";
for (i = 0; i < n; i++)
{
cout << "\nP" << i + 1 << "\t ";
for (j = 0; j < resources; j++)
{
cout << allocated[i][j] << " ";
}
cout << "\t ";
for (j = 0; j < resources; j++)

Saahil Lashkari 4CSE3+MBA A023116121002


{
cout << a[i][j] << " ";
}
cout << "\t ";
for (j = 0; j < resources; j++)
{
cout << b[i][j] << " ";
}
}
cout << "\nThe sequence of the safe processes are: \b";
for (i = 0; i < k; i++)
{
int temp = result[i];
cout << "P" << temp << " ";
}
cout << "\nThe sequence of unsafe processes are: \b";
int flg = 0;
for (i = 0; i < n; i++)
{
if (finish[i] == 0)
{
flg = 1;
}
cout << "P" << i << " ";
}
if (flg == 1)
cout << endl
<< "The system is not in safe state and deadlock may occur";
else
cout << endl
<< "The system is in safe state and deadlock will not occur";
}
};

int main()
{
bankers b;
b.input();
b.method();
b.display();
}

Saahil Lashkari 4CSE3+MBA A023116121002


Saahil Lashkari 4CSE3+MBA A023116121002
EXPERIMENT NO – 20
OBJECTIVE – Implement FIFO Page Replacement Algorithm using any language of choice.
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
First In First Out (FIFO): This is the simplest page replacement algorithm. In this algorithm,
the opera ng 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. Belady’s anomaly proves that it is possible to have more page faults
when increasing the number of page frames while using the First in First Out (FIFO) page re-
placement algorithm.
PERFORMANCE –
#include <iostream>
using namespace std;

int main()
{
int str[] = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 0, 3, 2, 1, 2, 0, 1, 7,
0, 1};
int faults = 0;
int frames = 3;
int i, j, s, pages;

pages = sizeof(str) / sizeof(str[0]);

printf("Incoming Frame 1 Frame 2 Frame 3");


int temp[frames];
for (i = 0; i < frames; i++)
{
temp[i] = -1;
}

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


{
s = 0;

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


{
if (str[i] == temp[j])
{
s++;
faults--;
}
}
faults++;

Saahil Lashkari 4CSE3+MBA A023116121002


if ((faults <= frames) && (s == 0))
{
temp[i] = str[i];
}
else if (s == 0)
{
temp[(faults - 1) % frames] = str[i];
}

cout << "\n";


cout << str[i] << " ";
for (j = 0; j < frames; j++)
{
if (temp[j] != -1)
cout << temp[j] << " ";
else
cout << "- ";
}
}

cout << "\nTotal Page Faults: " << faults;


cout << "\nTotal Hits : " << pages - faults;
return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 21
OBJECTIVE – Implement LRU Page Replacement Algorithm using any language of choice.
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
In Least Recently Used (LRU) algorithm is a Greedy algorithm where the page to be replaced
is least recently used. The idea is based on locality of reference, the least recently used page
is not likely.
PERFORMANCE –
#include <iostream>
using namespace std;

int main()
{
int q[20], p[50], c = 0, c1, d, f, i, j, k = 0, n, r, t, b[20], c2[20];
cout << "Enter no of pages:";
cin >> n;
cout << "Enter the reference string:";
for (i = 0; i < n; i++)
cin >> p[i];
cout << "Enter no of frames:";
cin >> f;
q[k] = p[k];
cout << "\n\t" << q[k] << "\n";
c++;
k++;
for (i = 1; i < n; i++)
{
c1 = 0;
for (j = 0; j < f; j++)
{
if (p[i] != q[j])
c1++;
}
if (c1 == f)
{
c++;
if (k < f)
{
q[k] = p[i];
k++;
for (j = 0; j < k; j++)
cout << "\t" << q[j];
cout << "\n";
}
else

Saahil Lashkari 4CSE3+MBA A023116121002


{
for (r = 0; r < f; r++)
{
c2[r] = 0;
for (j = i - 1; j >= 0; j--)
{
if (q[r] != p[j])
c2[r]++;
else
break;
}
}
for (r = 0; r < f; r++)
b[r] = c2[r];
for (r = 0; r < f; r++)
{
for (j = r; j < f; j++)
{
if (b[r] < b[j])
{
t = b[r];
b[r] = b[j];
b[j] = t;
}
}
}
for (r = 0; r < f; r++)
{
if (c2[r] == b[0])
q[r] = p[i];
cout << "\t" << q[r];
}
cout << "\n";
}
}
}
cout << "\nThe no of page faults is " << c;
return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


Saahil Lashkari 4CSE3+MBA A023116121002
EXPERIMENT NO – 22
OBJECTIVE – Implement Op mal Page Replacement Algorithm using any language of choice.
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
In op mal page replacement algorithm, if referred page is already present, increment hit
count. If not present, find if a page that is never referenced in future. If such a page exists,
replace this page with new page. If no such page exists, find a page that is referenced far-
thest in future. Replace this page with new page.
PERFORMANCE –
#include <iostream>
using namespace std;

int main()
{
int no_of_frames, no_of_pages, frames[10], pages[30], temp[10], flag1,
flag2, flag3, i, j, k, pos, max, faults = 0;

cout << "Enter number of frames: ";


cin >> no_of_frames;

cout << "Enter number of pages: ";


cin >> no_of_pages;

cout << "Enter page reference string: ";

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


{
cin >> pages[i];
}

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


{
frames[i] = -1;
}

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


{
flag1 = flag2 = 0;

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


{
if (frames[j] == pages[i])
{
flag1 = flag2 = 1;
break;

Saahil Lashkari 4CSE3+MBA A023116121002


}
}

if (flag1 == 0)
{
for (j = 0; j < no_of_frames; ++j)
{
if (frames[j] == -1)
{
faults++;
frames[j] = pages[i];
flag2 = 1;
break;
}
}
}

if (flag2 == 0)
{
flag3 = 0;

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


{
temp[j] = -1;

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


{
if (frames[j] == pages[k])
{
temp[j] = k;
break;
}
}
}

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


{
if (temp[j] == -1)
{
pos = j;
flag3 = 1;
break;
}
}

if (flag3 == 0)
{
max = temp[0];

Saahil Lashkari 4CSE3+MBA A023116121002


pos = 0;

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


{
if (temp[j] > max)
{
max = temp[j];
pos = j;
}
}
}

frames[pos] = pages[i];
faults++;
}

cout << endl;

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


{
cout << frames[j] << "\t";
}
}

cout << endl


<< endl
<< "Total Page Faults = " << faults;

return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 23
OBJECTIVE – Implement FCFS Disk Scheduling Algorithm using any language of choice.
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
FCFS is the simplest disk scheduling algorithm. As the name suggests, this algorithm enter-
tains requests in the order they arrive in the disk queue. The algorithm looks very fair and
there is no starva on (all requests are serviced sequen ally) but generally, it does not pro-
vide the fastest service.
PERFORMANCE –
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int queue[20], n, head, i, j, k, max, diff;
float avg;
int total_head_movement = 0;
cout << "Enter the max range of disk: ";
cin >> max;
cout << "Enter the size of queue request: ";
cin >> n;
cout << "Enter the queue of disk positions to be read: ";
for (i = 1; i <= n; i++)
{
cin >> queue[i];
}
cout << "Enter the initial head position: ";
cin >> head;
queue[0] = head;
for (j = 0; j <= n - 1; j++)
{
diff = abs(queue[j + 1] - queue[j]);
total_head_movement += diff;
if (queue[j] < queue[j + 1])
{
cout << queue[j] << " -> ";
}
else
{
cout << queue[j] << " <- ";
}
}
cout << queue[n] << endl;
cout << "Total head movement is: " << total_head_movement << endl;
return 0;

Saahil Lashkari 4CSE3+MBA A023116121002


}

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 24
OBJECTIVE – Implement SSTF Disk Scheduling Algorithm using any language of choice.
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
Shortest Seek Time First (SSTF) – tracks which are closer to current disk head posi on should
be serviced first in order to minimise the seek opera ons.
Advantages –
1) Be er performance than FCFS scheduling algorithm.
2) It provides be er throughput.
3) This algorithm is used in Batch Processing system where throughput is more im-
portant.
4) It has less average response and wai ng me.
Disadvantages –
1) Starva on is possible for some requests as it favours easy to reach request and ig-
nores the far away processes.
2) There is lack of predictability because of high variance of response me.
3) Switching direc on slows things down.
PERFORMANCE –
#include <iostream>
#include <climits>
using namespace std;

const int N = 100005;

int n;
int head;
int complete[N];
int str[N];

void sstf()
{
int movement = 0;
for (int i = 0; i < n; i++)
{
int index = 0;
int shortest = INT_MAX;
for (int k = 0; k < n; k++)
{
if (abs(head - str[k]) < shortest && !complete[k])
{
index = k;
shortest = abs(head - str[k]);

Saahil Lashkari 4CSE3+MBA A023116121002


}
}
complete[index] = true;
movement += shortest;
head = str[index];
}
cout << "Total Head Movement is: " << movement << endl;
return;
}

int main()
{
cout << "Queue Size: ";
cin >> n;
cout << "Enter the queue of disk positions to be read: ";
for (int i = 0; i < n; i++)
cin >> str[i];
cout << "Initial Head Position: ";
cin >> head;
sstf();
return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 25
OBJECTIVE – Implement SCAN Disk Scheduling Algorithm using any language of choice.
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
In SCAN disk scheduling algorithm, head starts from one end of the disk and moves towards
the other end, servicing requests in between one by one and reach the other end. Then the
direc on of the head is reversed and the process con nues as head con nuously scan back
and forth to access the disk. So, this algorithm works as an elevator and hence also known
as the elevator algorithm. As a result, the requests at the midrange are serviced more and
those arriving behind the disk arm will have to wait.
PERFORMANCE –
#include <bits/stdc++.h>
using namespace std;
int main()
{
int i, j, k, n, m, sum = 0, x, y, h;
cout << "Enter the size of disk\n";
cin >> m;
cout << "Enter number of requests\n";
cin >> n;
cout << "Enter the requests\n";
vector<int> a(n), b;
for (i = 0; i < n; i++)
{
cin >> a[i];
}
for (i = 0; i < n; i++)
{
if (a[i] > m)
{
cout << "Error, Unknown position " << a[i] << "\n";
return 0;
}
}
cout << "Enter the head position\n";
cin >> h;
int temp = h;
a.push_back(h);
a.push_back(m);
a.push_back(0);
sort(a.begin(), a.end());
for (i = 0; i < a.size(); i++)
{
if (h == a[i])

Saahil Lashkari 4CSE3+MBA A023116121002


break;
}
k = i;
if (k < n / 2)
{
for (i = k; i < a.size(); i++)
{
b.push_back(a[i]);
}
for (i = k - 1; i >= 0; i--)
{
b.push_back(a[i]);
}
}
else
{
for (i = k; i >= 0; i--)
{
b.push_back(a[i]);
}
for (i = k + 1; i < a.size(); i++)
{
b.push_back(a[i]);
}
}
temp = b[0];
cout << temp;
for (i = 1; i < b.size(); i++)
{
cout << " -> " << b[i];
sum += abs(b[i] - temp);
temp = b[i];
}
cout << '\n';
cout << "Total head movements = " << sum << '\n';
cout << "Average head movement = " << (float)sum / n << '\n';
return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


EXPERIMENT NO – 26
OBJECTIVE – Implement LOOK Disk Scheduling Algorithm using any language of choice.
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
The LOOK disk scheduling algorithm is a varia on of the SCAN algorithm for disk scheduling.
It is used to reduce the amount of me it takes to access data on a hard disk drive by mini-
mizing the seek me between read/write opera ons. The LOOK algorithm operates by scan-
ning the disk in a specific direc on, but instead of going all the way to the end of the disk
before reversing direc on like the SCAN algorithm, it reverses direc on as soon as it reaches
the last request in the current direc on.
PERFORMANCE –
#include <bits/stdc++.h>
using namespace std;
int main()
{
int i, j, k, n, m, sum = 0, x, y, h;
cout << "Enter the size of disk\n";
cin >> m;
cout << "Enter number of requests\n";
cin >> n;
cout << "Enter the requests\n";
vector<int> a(n), l;
for (i = 0; i < n; i++)
{
cin >> a[i];
}
for (i = 0; i < n; i++)
{
if (a[i] > m)
{
cout << "Error, Unknown position\n";
return 0;
}
}
cout << "Enter the head position\n";
cin >> h;
a.push_back(h);
sort(a.begin(), a.end());
for (i = 0; i < a.size(); i++)
{
if (h == a[i])
break;
}
k = i;

Saahil Lashkari 4CSE3+MBA A023116121002


if (k < n / 2)
{
for (i = k; i < a.size(); i++)
{
l.push_back(a[i]);
}
for (i = k - 1; i >= 0; i--)
{
l.push_back(a[i]);
}
}
else
{
for (i = k; i >= 0; i--)
{
l.push_back(a[i]);
}
for (i = k + 1; i < a.size(); i++)
{
l.push_back(a[i]);
}
}
int temp = l[0];
cout << temp;
for (i = 1; i < l.size(); i++)
{
cout << " -> " << l[i] << ' ';
sum += abs(l[i] - temp);
temp = a[i];
}
cout << '\n';
cout << "Total head movements = " << sum << '\n';
return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


Open Ended Experiment
OBJECTIVE – a) Memory Consump on and Ac vity Monitor: Develop an applica on which is
able to iden fy the tasks and ac vi es consuming memory resources
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
Memory usage is an important factor to consider when developing so ware, as excessive
memory usage can lead to poor performance and even crashes. By retrieving memory usage
informa on, developers can monitor their program's memory usage and op mize their code
to reduce memory consump on. This program uses the Windows API to retrieve memory
usage informa on for the processes in a C++ program.
The windows.h header file provides access to the Windows API func ons, while the psapi.h
header file declares the PROCESS_MEMORY_COUNTERS_EX structure and related func ons
for working with process memory usage informa on.
Here, the GetProcessMemoryInfo func on is used to retrieve the memory usage infor-
ma on. This func on takes as input a handle to a process, a pointer to a PRO-
CESS_MEMORY_COUNTERS struct, and the size of the struct. The func on then fills in the
struct with informa on about the memory usage.
The PROCESS_MEMORY_COUNTERS_EX struct used in this code is a more advanced version
of the PROCESS_MEMORY_COUNTERS struct, which provides addi onal informa on about
memory usage, such as the peak working set size and the number of page faults.
The GetProcessMemoryInfo func on is then called with three parameters: GetCurrentPro-
cess() which retrieves a handle to the current process.
(PROCESS_MEMORY_COUNTERS *)&pmc - this is the memory loca on where the func on
will write the process memory informa on.
The ‘&’ operator is used to get the address of the pmc variable, and the (PRO-
CESS_MEMORY_COUNTERS *) cast tells the compiler to treat the address as a pointer to the
PROCESS_MEMORY_COUNTERS struct.The sizeof(pmc) specifies the size of the memory
block pointed to by pmc. If GetProcessMemoryInfo is successful, the program prints the
name of the current process executable file (pmc.thisFile) and the amount of private
memory used by the process (pmc.PrivateUsage) to the console using cout.
Once the memory usage informa on is retrieved, the program prints the name of the cur-
rent process executable file and the amount of private memory used by the process to the
console
PERFORMANCE –
#include <iostream>
#include <windows.h>
#include <psapi.h>

using namespace std;

Saahil Lashkari 4CSE3+MBA A023116121002


int main()
{
PROCESS_MEMORY_COUNTERS_EX pmc;

if (GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS
*)&pmc, sizeof(pmc)))
{
cout << "File name: " << pmc.thisFile << endl;
cout << "Size used: " << pmc.PrivateUsage << endl;
}
else
{
cout << "Failed to retrieve memory usage. Error code: " << GetLastEr-
ror() << endl;
}

return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


Saahil Lashkari 4CSE3+MBA A023116121002
OBJECTIVE – b) WAP to generate maximum number of child process in your system and ex-
plain with the help of program what are Zombie processes.
SOFTWARE USED – VS Code, g++ (MinGW.org GCC-6.3.0-1) 6.3.0
THEORY –
This code creates an infinite loop that repeatedly forks new child processes until the program
is terminated. The parent process uses a break statement to exit the loop after the first child
process is created.
The iostream library is included to use the standard input/output stream objects like cout and
endl.
The unistd.h library is included to use the fork() system call which creates a new process by
duplicating the calling process.
The using namespace std; line is a shorthand notation which indicates that the standard
namespace is to be used. This allows the programmer to use objects and functions defined in
the std namespace without needing to prefix them with ‘std::’.
The main() function is the entry point of the program and returns an integer value to the oper-
ating system.
An integer variable ‘i’ is initialized with the value 0. An infinite loop is created using the
while (true) statement. Inside the loop, the fork() system call is used to create a new process.
If fork() returns 0, it means that the current process is the child process. In this case, the child
increments the value of i by one and prints a message to the console indicating that it has
been created. If fork() returns a value greater than 0, it means that the current process is the
parent process. In this case, the parent uses a break statement to exit the loop after the first
child process is created. Finally, the main() function returns 0 to indicate successful program
execution.
The process that initiates the fork() call is called the parent process, and the new process that
is created is called the child process. The child process is an exact copy of the parent process,
with its own unique process ID (PID), memory space, and other system resources.
After creating a child process, the parent process can continue running in parallel with the
child process, or it can wait for the child process to complete its execution using the wait()
system call. When a parent process waits for a child process, it can collect the exit status of
the child process and reclaim its system resources.
A zombie process is a type of process that has completed its execution, but its exit status has
not been collected by its parent process. Zombie processes can occur when a parent process
fails to call the wait() system call after its child process has completed execution. The zombie
process continues to exist in the process table and consumes system resources, but it cannot
be killed or terminated until its parent process collects its exit status.
To avoid zombie processes, it is essential for the parent process to call the wait() system call
after creating a child process. This ensures that the parent process collects the exit status of its
child process and reclaims its system resources. Additionally, the parent process can use the
signal() system call to handle the SIGCHLD signal, which is sent to the parent process when

Saahil Lashkari 4CSE3+MBA A023116121002


a child process terminates. By handling this signal, the parent process can ensure that it col-
lects the exit status of its child processes promptly and avoids creating zombie processes.
PERFORMANCE –
#include <stdio.h>
#include <stdlib.h>
#include <sys types.h="">
#include <unistd.h>
int k = 5; // global variable

int main()
{

int i = 0;
int status;

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


{
if (fork() == 0)
{
printf("child %d %d\n", i, ++k);
sleep(5);
printf("done %d\n", i);
exit(0);
}
}

return 0;
}

Saahil Lashkari 4CSE3+MBA A023116121002


Saahil Lashkari 4CSE3+MBA A023116121002

You might also like