You are on page 1of 71

Annexure 1

Real Time Operating System


ECL 362

Lab Practical Report

Faculty name: Student name: Parth Bathla


Roll No.: 18ECU016
Semester: 6th SEM
Group: ECE VLSI

Department of Electronics and Communication Engineering

The NorthCap University, Gurugram- 122001, India

Session 2020-21

INDEX
ii

Real Time Operating System (ECL 362)


2020-21

S.No Experiment Page Date of Date of Marks Signature


Number Experiment Submission
1 Explain the structure basic commands 4- 7 29/01/2021 03/02/2021
Linux Operating System

2 ALL commands of linux 4-7 03/02/2021 10/02/2021

3 Write a shell program to find factorial 8-10 10/02/2021 24/02/2021


of a number.

4 Write a shell program to find gross 11-13 24/02/2021 24/02/2021


salary of an employee.

5 Write a shell program to display the 14-15 24/02/2021 10/02/2021


menu and execute instructions
accordingly.

(i)List of file (ii)Process Status (iii)


Date (iv) users in program (v)
Quit

6 Write a shell program to find 16-20 24/02/2021 10/02/2021


Fibonacci series.

7 Write a shell program to find largest 21-23 10/02/2021 03/03/2021


of three numbers.

8 Write a shell program to find average 24-26 10/02/2021 03/03/2021


of N numbers

9 Write a C program to simulate the 27-32 03/03/2021 10/03/2021


FCFS non-preemptive CPU
scheduling algorithms to find
turnaround time and waiting time.

10 Write a C program to simulate the 33-38 14/04/2021 14/04/2021


SJF non-preemptive CPU
scheduling algorithms to find
turnaround time and waiting time.

11 Write a C program to simulate the 39-46 21/04/2021 21/04/2021


SJRF preemptive CPU scheduling
algorithms to find turnaround time
and waiting time.
iii

Real Time Operating System (ECL 362)


2020-21

12 Write a C program to simulate the 47-55 31/03/2021 07/04/2021


Round Robin preemptive CPU
scheduling algorithms to find
turnaround time and waiting time.

13 Write a C program to simulate the 56-60 07/04/2021 21/04/2021


Priority non- preemptive CPU
scheduling algorithms to find
turnaround time and waiting time.

14 Write a C program to simulate the 61-65 10/03/2021 17/03/2021


Priority preemptive CPU
scheduling algorithms to find
turnaround time and waiting time.

15. Write a program to simulate 66-71 05/05/2021 05/05/2021


Bankers algorithm for the purpose
of deadlock avoidance

16. Write a C program to simulate


page replacement algorithms

a) FIFO b) LRU c) LFU

17. Write a C program to simulate


page replacement algorithms

a) Optimal
iv

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 1 and 2


Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Sem (ECE)
Link to Code:
Date: 29/01/2021 – 03/02/2021

Faculty Signature:

Marks:

Objective: Explain the structure basic commands of Linux Operating System

Outcome: The students will understand the basic Linux command

Problem Statement: Run basic Linux commands on Cygwin


Background Study:
• LINUX is an operating system that is a clone of UNIX.
• LINUX is free and open source.
• LINUX commands are case sensitive.
Question Bank:

(7 MCQ Questions related to topic with ans )


1.Maximum how long can a Linux filename be?

128 bytes

255 bytes

32 bytes

64 bytes

2.Which command(s) is/are used to get help about a command in Linux?

info

man
v

Real Time Operating System (ECL 362)


2020-21

None of these

Both a and b

3.Which of the following OS is not based on Linux?

Ubuntu

Redhat

CentOs

BSD

4.Which command is used to get the kernel version in Linux?

uname -r

kernel

uname -n

uname –s

5.Which command is used to list all the files in your current directory(including hidden)?

ls -l

ls -t

ls -a

ls –i

6.Which command is/are used to remove directory in Linux?

rmdir

rm -r
vi

Real Time Operating System (ECL 362)


2020-21

only b

Both a and b

7.Which of the following command is used to create file in Linux?

touch

cat

echo

All of the above

Student Work Area

Code & Sample Outputs

Commands:
vii

Real Time Operating System (ECL 362)


2020-21
viii

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 3
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Sem ECE
Link to Code:
Date: 10/02/2021

Faculty Signature:

Marks:

Objective: Write a shell program to find factorial of a number

Outcome: Factorial of a number

Problem Statement: To find factorial of a number


Background Study: Factorial of numbers
Question Bank:

(7 MCQ Questions related to topic with ans )

1.
(A) 0
(B) 1
(C) 10
(D) undefined

2.
(A)
(B)
(C)
(D)

3.
(A) 70
(B) 120
(C) 720
(D) 5040

4.
(A) 90
(B) 105
ix

Real Time Operating System (ECL 362)


2020-21

(C) 120
(D) 135

5.
(A) 24
(B) 26
(C) 28
(D) 30

ANSWERS: FACTORIAL QUIZ


1. B
2. A
3. D
4. C
5. D

Student Work Area

Code & Sample OutputScreenshots:


x

Real Time Operating System (ECL 362)


2020-21
xi

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 4
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Sem ECE
Link to Code:
Date: 24/02/2021

Faculty Signature:

Marks:

Objective: Write a shell program to find gross salary of an employee.

Outcome: Gross salary of an employee

Problem Statement: To find gross salary of an employee.


Background Study: total salary of employe
Question Bank:

1. If a file with execute permissions set, but with unknown file format is executed
a) The file is passed to /bin/sh
b) The system returns an error
c) The current shell will try to execute it
d) None of the mentioned

Answer: c

2. Which of the following is true?


a) Shell is a process and can be started by superuser only
b) Shell is a built-in Kernel functionality
c) Shell is a wrapper for all the commands and utilities
d) None of the mentioned

Answer: c

3. Which is true with regards to the shell prompt


a) It can be accidentally erased with backspace
b) The prompt cannot be modified
c) The prompt can be customized (modified)
d) None of the mentioned
xii

Real Time Operating System (ECL 362)


2020-21

Answer: c

4. What is a shell in UNIX?


a) a program through which users can issue commands to UNIX
b) a window management system
c) the login screen
d) the thing that rides on the back of a turtle in UNIX

Answer: a

5. Which of the following represents an absolute path?


a) ../home/file.txt
b) bin/cat
c) cs2204/
d) /usr/bin/cat

Answer: d

6. The user bhojas logged in and performed the following sequence of command. What will be the output of
the last command?
$ cd project/module1
$ pwd
a) /home/bhojas/project/module1
b) /home/project/module1
c) /usr/bhojas/project/module1
d) project/module1

Answer: a

7. BASH shell stands for?


a) Bourne-again Shell
b) Basic Access Shell
c) Basic to Advanced Shell
d) Big & Advanced Shell

Answer: a
xiii

Real Time Operating System (ECL 362)


2020-21

Student Work Area

Code & Sample Outputs

Screenshots
xiv

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 5
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Sem ECE
Link to Code:
Date: 24/02/2021

Faculty Signature:

Marks:

Objective: Write a shell program to display the menu and execute instructions accordingly.

(i)List of file (ii)Process Status (iii) Date (iv) users in program (v) Quit

Outcome: Display the menu of list of file, process status, users in program and quit

Problem Statement: To display the menu and execute instructions accordingly


Background Study:

Student Work Area

Code & Sample Outputs

Screenshots
xv

Real Time Operating System (ECL 362)


2020-21
xvi

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 6
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Sem ECE
Link to Code:
Date: 24/02/2021

Faculty Signature:

Marks:

Objective: Write a shell program to find Fibonacci series

Outcome: Fibonacci Series

Problem Statement: To find Fibonacci Series


Background Study: Study about the working of Fibonacci series
Question Bank:

(7 MCQ Questions related to topic with ans )

1. Suppose the first fibonnaci number is 0 and the second is 1. What is the sixth fibonnaci number?
a) 5
b) 6
c) 7
d) 8

Answer: a
Explanation: The sixth fibonnaci number is 5.

2. Which of the following is not a fibonnaci number?


a) 8
b) 21
c) 55
d) 14

Answer: d
Explanation: 14 is not a fibonnaci number.

3. Which of the following option is wrong?


a) Fibonacci number can be calculated by using Dynamic programming
b) Fibonacci number can be calculated by using Recursion method
xvii

Real Time Operating System (ECL 362)


2020-21

c) Fibonacci number can be calculated by using Iteration method


d) No method is defined to calculate Fibonacci number

Answer: d
Explanation: Fibonacci number can be calculated by using Dynamic Programming, Recursion method,
Iteration Method.

4. Consider the following iterative implementation to find the nth fibonacci number?

int main()
{
int n = 10,i;
if(n == 1)
printf("0");
else if(n == 2)
printf("1");
else
{
int a = 0, b = 1, c;
for(i = 3; i <= n; i++)
{
c = a + b;
________;
________;
}
printf("%d",c);
}
return 0;
}

Which of the following lines should be added to complete the above code?
a)

c = b
b = a

b)

a = b
b = c

c)

b = c
a = b

d)

a = b
b = a
xviii

Real Time Operating System (ECL 362)


2020-21

Answer: b
Explanation: The lines “a = b” and “b = c” should be added to complete the above code.

5. Which of the following recurrence relations can be used to find the nth fibonacci number?
a) F(n) = F(n) + F(n – 1)
b) F(n) = F(n) + F(n + 1)
c) F(n) = F(n – 1)
d) F(n) = F(n – 1) + F(n – 2)

Answer: d
Explanation: The relation F(n) = F(n – 1) + F(n – 2) can be used to find the nth fibonacci number.

6. Consider the following recursive implementation to find the nth fibonacci number:

int fibo(int n)
{
if(n == 1)
return 0;
else if(n == 2)
return 1;
return ________;
}
int main()
{
int n = 5;
int ans = fibo(n);
printf("%d",ans);
return 0;
}

Which of the following lines should be inserted to complete the above code?
a) fibo(n – 1)
b) fibo(n – 1) + fibo(n – 2)
c) fibo(n) + fibo(n – 1)
d) fibo(n – 2) + fibo(n – 1)

Answer: b
Explanation: The line fibo(n – 1) + fibo(n – 2) should be inserted to complete the above code.

7. Consider the following recursive implementation to find the nth fibonnaci number:

int fibo(int n)
{
if(n == 1)
return 0;
else if(n == 2)
return 1;
return fibo(n - 1) + fibo(n - 2);
}
int main()
{
xix

Real Time Operating System (ECL 362)


2020-21

int n = 5;
int ans = fibo(n);
printf("%d",ans);
return 0;
}

Which of the following is the base case?


a) if(n == 1)
b) else if(n == 2)
c) return fibo(n – 1) + fibo(n – 2)
d) both if(n == 1) and else if(n == 2)

Answer: d
Explanation: Both if(n == 1) and else if(n == 2) are the base cases.

Student Work Area

Code & Sample Outputs

Screenshots
xx

Real Time Operating System (ECL 362)


2020-21
xxi

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 7
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Sem ECE
Link to Code:
Date: 10/02/2021

Faculty Signature:

Marks:

Objective: Write a shell program to find largest of three numbers.

Outcome: Largest of three numbers

Problem Statement: To find largest of three numbers


Background Study: Out of the given numbers which is the greatest.
Question Bank:

(7 MCQ Questions related to topic with ans )

1) #include<userdefined.h>

Which of the following is the correct syntax to add the header file in the C++ program?

1. #include<userdefined>
2. #include "userdefined.h"
3. <include> "userdefined.h"
4. Both A and B

Answer: D
Explanation: To include the herder files in the C++ program user can use any of the following given syntax.

2) Which of the following is the correct syntax to print the message in C++ language?

1. cout <<"Hello world!";


2. Cout << Hello world! ;
3. Out <<"Hello world!;
4. None of the above

Answer: A
xxii

Real Time Operating System (ECL 362)


2020-21

3) Which of the following is the correct identifier?

1. $var_name
2. VAR_123
3. varname@
4. None of the above

Answer: B

4) Which of the following is the address operator?

1. @
2. #
3. &
4. %

Answer: C

5) Which of the following features must be supported by any programming language to become a
pure object-oriented programming language?

1. Encapsulation
2. Inheritance
3. Polymorphism
4. All of the above

Answer: D

6) The programming language that has the ability to create new data types is called___.

1. Overloaded
2. Encapsulated
3. Reprehensible
4. Extensible

Answer: D

7) Which of the following is the original creator of the C++ language?

1. Dennis Ritchie
2. Ken Thompson
3. Bjarne Stroustrup
4. Brian Kernighan

Answer: C
xxiii

Real Time Operating System (ECL 362)


2020-21

Student Work Area

Code & Sample Outputs

Screenshots
xxiv

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 8
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Sem ECE
Link to Code:
Date: 10/02/2021

Faculty Signature:

Marks:

Objective: Write a shell program to find average of N numbers.

Outcome:

Problem Statement: Average of numbers


Background Study: To find average of N numbers
Question Bank:

(7 MCQ Questions related to topic with ans )

Q1. OS stands for

a) Operating solve
b) Open Source
c) Open System
d) Operating system

Answer : d

Q2. World Wide Web is being standard by

a) Worldwide corporation
b) W3C
c) World Wide Web Standard
d) World Wide Consortium

Answer : b

Q3. A co-processor
xxv

Real Time Operating System (ECL 362)


2020-21

a) Is relatively easy to support in software


b) Causes all processor to function equally
c) Works with any application
d) Is quite common in modern computer

Answer : a

Q4. A Microsoft Windows is a(n)

a) Operating system
b) Graphic program
c) Word Processing
d) Database program

Answer : a

Q5. Which of the following is program group?

a) Accessories
b) Paint
c) Word
d) All of above

Answer : a

Q6. Which is not application software?

a) Windows NT
b) Page Maker
c) WinWord XP
d) Photoshop

Answer : a

Q7.The …… program compresses large files into a smaller file

a) WinZip
b) WinShrink
c) WinStyle
d) None of above

Answer : a
xxvi

Real Time Operating System (ECL 362)


2020-21

Student Work Area

Code & Sample Outputs

Screenshots
xxvii

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 9
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Sem ECE
Link to Code:
Date: 03/03/2021

Faculty Signature:

Marks:

Objective: Write a C program to simulate the FCFS non-preemptive CPU scheduling


algorithms to find turnaround time and waiting time.

Outcome: FCFS non-preemptive CPU scheduling algorithms to find turnaround time and
waiting time
Problem Statement: To simulate the FCFS non-preemptive CPU scheduling algorithms to find
turnaround time and waiting time
Background Study:
Question Bank:

(7 MCQ Questions related to topic with ans )

1. Round robin scheduling falls under the category of ____________


a) Non-preemptive scheduling
b) Preemptive scheduling
c) All of the mentioned
d) None of the mentioned

Answer: b

2. With round robin scheduling algorithm in a time shared system ____________


a) using very large time slices converts it into First come First served scheduling algorithm
b) using very small time slices converts it into First come First served scheduling algorithm
c) using extremely small time slices increases performance
d) using very small time slices converts it into Shortest Job First algorithm

Answer: a
Explanation: All the processes will be able to get completed.

3. The portion of the process scheduler in an operating system that dispatches processes is concerned
with ____________
a) assigning ready processes to CPU
xxviii

Real Time Operating System (ECL 362)


2020-21

b) assigning ready processes to waiting queue


c) assigning running processes to blocked queue
d) all of the mentioned

Answer: a

4. Complex scheduling algorithms ____________


a) are very appropriate for very large computers
b) use minimal resources
c) use many resources
d) all of the mentioned

Answer: a
Explanation: Large computers are overloaded with a greater number of processes.

5. What is FIFO algorithm?


a) first executes the job that came in last in the queue
b) first executes the job that came in first in the queue
c) first executes the job that needs minimal processor
d) first executes the job that has maximum processor needs

Answer: b

6. The strategy of making processes that are logically runnable to be temporarily suspended is called
____________
a) Non preemptive scheduling
b) Preemptive scheduling
c) Shortest job first
d) First come First served

Answer: b

7. What is Scheduling?
a) allowing a job to use the processor
b) making proper use of processor
c) all of the mentioned
d) none of the mentioned

Answer: a
xxix

Real Time Operating System (ECL 362)


2020-21

Student Work Area

Code & Sample Outputs

#include<iostream>

#define MAX_PROCESS 10

using namespace std;

class process

public:

int process_num;

int burst_time;

int arrival_time;

int response_time;

int waiting_time;

int turnaround_time;

void input_process(int);

int get_at()

return arrival_time;

};

void process::input_process(int count)

process_num=count+1;

cout<<"\nENTER BURST TIME FOR PROCESS "<<count+1<<" : ";

cin>>burst_time;

cout<<"ENTER ARRIVAL TIME FOR PROCESS "<<count+1<<" : ";


xxx

Real Time Operating System (ECL 362)


2020-21

cin>>arrival_time;

void calc_wait_tat(process*,int);

void average(process*,int);

void display(process*,int);

int main()

process p[MAX_PROCESS],temp;

int num,i,j;

cout<<"ENTER NUMBER OF PROCESSES : ";

cin>>num;

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

p[i].input_process(i);

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

for(j=i+1;j<num;++j)

if(p[i].get_at()>p[j].get_at())

temp=p[i];

p[i]=p[j];

p[j]=temp;

calc_wait_tat(p,num);

display(p,num);
xxxi

Real Time Operating System (ECL 362)


2020-21

return 0;

void calc_wait_tat(process *p,int n)

int i;

p[0].response_time=0;

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

p[i].response_time=p[i-1].burst_time+p[i-1].response_time;

if(p[i].response_time<p[i].arrival_time)

p[i].response_time=p[i].arrival_time;

p[0].waiting_time=0;

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

p[i].waiting_time=p[i].response_time-p[i].arrival_time;

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

p[i].turnaround_time=p[i].waiting_time+p[i].burst_time;

void average(process *p,int n)

float avg_wt=0,avg_tat=0;

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

avg_wt+=(float)p[i].waiting_time;

avg_tat+=(float)p[i].turnaround_time;

avg_wt/=n;
xxxii

Real Time Operating System (ECL 362)


2020-21

avg_tat/=n;

cout<<"\n\nAVERAGE WAITING TIME : "<<avg_wt;

cout<<"\nAVERAGE TURN AROUND TIME : "<<avg_tat;

void display(process *p,int n)

cout<<"Processes "<<" Burst time "<<" Waiting time "<<" Turn around time\n";

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

cout<<"\n "<<p[i].process_num<<"\t\t"<<p[i].burst_time<<"\t "<<p[i].waiting_time<<"\t\t


"<<p[i].turnaround_time;

average(p,n);

}
xxxiii

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 10
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Semester ECE
Date: 03/03/2021
Faculty Signature:

Marks:

Objective: Write a C program to simulate the SJF non-preemptive CPU scheduling algorithms to
find turnaround time and waiting time

Outcome: SJF non-preemptive CPU scheduling algorithms to find turnaround time and waiting time
Problem Statement: To simulate SJF non-preemptive CPU scheduling algorithms to find
turnaround time and waiting time
Background Study: SJF non primitive
Question Bank:

(7 MCQ Questions related to topic with ans )

1. Which is the most optimal scheduling algorithm?


a) FCFS – First come First served
b) SJF – Shortest Job First
c) RR – Round Robin
d) None of the mentioned

Answer: b

2. The real difficulty with SJF in short term scheduling is ____________


a) it is too good an algorithm
b) knowing the length of the next CPU request
c) it is too complex to understand
d) none of the mentioned

Answer: b

3. The FCFS algorithm is particularly troublesome for ____________


a) time sharing systems
b) multiprogramming systems
c) multiprocessor systems
d) operating systems
xxxiv

Real Time Operating System (ECL 362)


2020-21

Answer: b
Explanation: In a time sharing system, each user needs to get a share of the CPU at regular intervals.

4. Consider the following set of processes, the length of the CPU burst time given in milliseconds.

Process Burst time


P1 6
P2 8
P3 7
P4 3

Assuming the above process being scheduled with the SJF scheduling algorithm.
a) The waiting time for process P1 is 3ms
b) The waiting time for process P1 is 0ms
c) The waiting time for process P1 is 16ms
d) The waiting time for process P1 is 9ms

Answer: a

5. Preemptive Shortest Job First scheduling is sometimes called ____________


a) Fast SJF scheduling
b) EDF scheduling – Earliest Deadline First
c) HRRN scheduling – Highest Response Ratio Next
d) SRTN scheduling – Shortest Remaining Time Next

Answer: d

6. An SJF algorithm is simply a priority algorithm where the priority is ____________


a) the predicted next CPU burst
b) the inverse of the predicted next CPU burst
c) the current CPU burst
d) anything the user wants

Answer: a
Explanation: The larger the CPU burst, the lower the priority.

7. Choose one of the disadvantages of the priority scheduling algorithm?


a) it schedules in a very complex manner
b) its scheduling takes up a lot of time
c) it can lead to some low priority process waiting indefinitely for the CPU
d) none of the mentioned

Answer: c
xxxv

Real Time Operating System (ECL 362)


2020-21

Student Work Area

Code & Sample Outputs

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string.h>
using namespace std;

struct process {
int pid;
int arrival_time;
int burst_time;
int start_time;
int completion_time;
int turnaround_time;
int waiting_time;
int response_time;
};

int main() {

int n;
struct process p[100];
float avg_turnaround_time;
float avg_waiting_time;
float avg_response_time;
float cpu_utilisation;
int total_turnaround_time = 0;
int total_waiting_time = 0;
int total_response_time = 0;
int total_idle_time = 0;
float throughput;
int is_completed[100];
memset(is_completed,0,sizeof(is_completed));

cout << setprecision(2) << fixed;

cout<<"Enter the number of processes: ";


cin>>n;

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


cout<<"Enter arrival time of process "<<i+1<<": ";
cin>>p[i].arrival_time;
cout<<"Enter burst time of process "<<i+1<<": ";
cin>>p[i].burst_time;
xxxvi

Real Time Operating System (ECL 362)


2020-21

p[i].pid = i+1;
cout<<endl;
}

int current_time = 0;
int completed = 0;
int prev = 0;

while(completed != n) {
int idx = -1;
int mn = 10000000;
for(int i = 0; i < n; i++) {
if(p[i].arrival_time <= current_time && is_completed[i] == 0) {
if(p[i].burst_time < mn) {
mn = p[i].burst_time;
idx = i;
}
if(p[i].burst_time == mn) {
if(p[i].arrival_time < p[idx].arrival_time) {
mn = p[i].burst_time;
idx = i;
}
}
}
}
if(idx != -1) {
p[idx].start_time = current_time;
p[idx].completion_time = p[idx].start_time + p[idx].burst_time;
p[idx].turnaround_time = p[idx].completion_time - p[idx].arrival_time;
p[idx].waiting_time = p[idx].turnaround_time - p[idx].burst_time;
p[idx].response_time = p[idx].start_time - p[idx].arrival_time;

total_turnaround_time += p[idx].turnaround_time;
total_waiting_time += p[idx].waiting_time;
total_response_time += p[idx].response_time;
total_idle_time += p[idx].start_time - prev;

is_completed[idx] = 1;
completed++;
current_time = p[idx].completion_time;
prev = current_time;
}
else {
current_time++;
}

}
xxxvii

Real Time Operating System (ECL 362)


2020-21

int min_arrival_time = 10000000;


int max_completion_time = -1;
for(int i = 0; i < n; i++) {
min_arrival_time = min(min_arrival_time,p[i].arrival_time);
max_completion_time = max(max_completion_time,p[i].completion_time);
}

avg_turnaround_time = (float) total_turnaround_time / n;


avg_waiting_time = (float) total_waiting_time / n;
avg_response_time = (float) total_response_time / n;
cpu_utilisation = ((max_completion_time - total_idle_time) / (float) max_completion_time
)*100;
throughput = float(n) / (max_completion_time - min_arrival_time);

cout<<endl<<endl;

cout<<"#P\t"<<"AT\t"<<"BT\t"<<"ST\t"<<"CT\t"<<"TAT\t"<<"WT\t"<<"RT\t"<<"\n"<<endl;

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

cout<<p[i].pid<<"\t"<<p[i].arrival_time<<"\t"<<p[i].burst_time<<"\t"<<p[i].start_time<<"\t"<<
p[i].completion_time<<"\t"<<p[i].turnaround_time<<"\t"<<p[i].waiting_time<<"\t"<<p[i].respo
nse_time<<"\t"<<"\n"<<endl;
}
cout<<"Average Turnaround Time = "<<avg_turnaround_time<<endl;
cout<<"Average Waiting Time = "<<avg_waiting_time<<endl;
cout<<"Average Response Time = "<<avg_response_time<<endl;
cout<<"CPU Utilization = "<<cpu_utilisation<<"%"<<endl;
cout<<"Throughput = "<<throughput<<" process/unit time"<<endl;
}
xxxviii

Real Time Operating System (ECL 362)


2020-21
xxxix

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 11
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Semester ECE
Date: 03/03/2021
Faculty Signature:

Marks:

Objective: Write a C++ program to simulate the SJRF preemptive CPU scheduling algorithms to
find turnaround time

Outcome: SRJF preemptive CPU scheduling algorithms to find turnaround time and waiting time
Problem Statement: To simulate SRJF preemptive CPU scheduling algorithms to find turnaround
time and waiting time
Background Study:
Question Bank:

(7 MCQ Questions related to topic with ans )

Question 1 : Which of the following scheduling algorithms gives minimum average waiting time ?
1. FCFS
2. SJF
3. Round – robin
4. Priority
Answer : Option 2 - SJF

Question 2 : Which of the following statements are true ? (GATE 2010)


i) Shortest remaining time first scheduling may cause starvation
ii) Preemptive scheduling may cause starvation
iii) Round robin is better than FCFS in terms of response time
1. i only
2. i and iii only
3. ii and iii only
4. i, ii and iii
Answer : Option 4 - i, ii and iii

Question 3 : One of the disadvantages of the priority scheduling algorithm is that :


1. it schedules in a very complex manner
2. its scheduling takes up a lot of time
3. it can lead to some low priority process waiting indefinitely for the CPU
4. none of the mentioned
Answer : Option 3 - it can lead to some low priority process waiting indefinitely for the CPU
xl

Real Time Operating System (ECL 362)


2020-21

Question 4 : An SJF algorithm is simply a priority algorithm where the priority is :


1. the predicted next CPU burst
2. the inverse of the predicted next CPU burst
3. the current CPU burst
4. anything the user wants
Answer : Option 1 - the predicted next CPU burst

Question 5 : Preemptive Shortest Job First scheduling is sometimes called :


1. Fast SJF scheduling
2. EDF scheduling – Earliest Deadline First
3. HRRN scheduling – Highest Response Ratio Next
4. SRTN scheduling – Shortest Remaining Time Next
Answer : Option 4 - SRTN scheduling – Shortest Remaining Time Next

Question 6: The FCFS algorithm is particularly troublesome for ____________


1. time sharing systems
2. multiprogramming systems
3. multiprocessor systems
4. operating systems
Answer : Option 2 - multiprogramming systems

Question 7 : The real difficulty with SJF in short term scheduling is :


1. it is too good an algorithm
2. knowing the length of the next CPU request
3. it is too complex to understand
4. none of the mentioned
Answer : Option 2 - knowing the length of the next CPU request

Student Work Area

Code & Sample Outputs

#include <bits/stdc++.h>

using namespace std;

struct Process {

int pid; // Process ID


xli

Real Time Operating System (ECL 362)


2020-21

int bt; // Burst Time

int art; // Arrival Time

};

// Function to find the waiting time for all

// processes

void findWaitingTime(Process proc[], int n,

int wt[])

int rt[n];

// Copy the burst time into rt[]

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

rt[i] = proc[i].bt;

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

int shortest = 0, finish_time;

bool check = false;

// Process until all processes gets

// completed

while (complete != n) {

// Find process with minimum

// remaining time among the


xlii

Real Time Operating System (ECL 362)


2020-21

// processes that arrives till the

// current time`

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

if ((proc[j].art <= t) &&

(rt[j] < minm) && rt[j] > 0) {

minm = rt[j];

shortest = j;

check = true;

if (check == false) {

t++;

continue;

// Reduce remaining time by one

rt[shortest]--;

// Update minimum

minm = rt[shortest];

if (minm == 0)

minm = INT_MAX;

// If a process gets completely


xliii

Real Time Operating System (ECL 362)


2020-21

// executed

if (rt[shortest] == 0) {

// Increment complete

complete++;

check = false;

// Find finish time of current

// process

finish_time = t + 1;

// Calculate waiting time

wt[shortest] = finish_time -

proc[shortest].bt -

proc[shortest].art;

if (wt[shortest] < 0)

wt[shortest] = 0;

// Increment time

t++;

// Function to calculate turn around time


xliv

Real Time Operating System (ECL 362)


2020-21

void findTurnAroundTime(Process proc[], int n,

int wt[], int tat[])

// calculating turnaround time by adding

// bt[i] + wt[i]

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

tat[i] = proc[i].bt + wt[i];

// Function to calculate average time

void findavgTime(Process proc[], int n)

int wt[n], tat[n], total_wt = 0,

total_tat = 0;

// Function to find waiting time of all

// processes

findWaitingTime(proc, n, wt);

// Function to find turn around time for

// all processes

findTurnAroundTime(proc, n, wt, tat);

// Display processes along with all

// details
xlv

Real Time Operating System (ECL 362)


2020-21

cout << "Processes "

<< " Burst time "

<< " Waiting time "

<< " Turn around time\n";

// Calculate total waiting time and

// total turnaround time

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

total_wt = total_wt + wt[i];

total_tat = total_tat + tat[i];

cout << " " << proc[i].pid << "\t\t"

<< proc[i].bt << "\t\t " << wt[i]

<< "\t\t " << tat[i] << endl;

cout << "\nAverage waiting time = "

<< (float)total_wt / (float)n;

cout << "\nAverage turn around time = "

<< (float)total_tat / (float)n;

// Driver code

int main()

Process proc[] = { { 1, 6, 1 }, { 2, 8, 1 },
xlvi

Real Time Operating System (ECL 362)


2020-21

{ 3, 7, 2 }, { 4, 3, 3 } };

int n = sizeof(proc) / sizeof(proc[0]);

findavgTime(proc, n);

return 0;

}
xlvii

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 12
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Semester ECE
Date: 31/03/2021
Faculty Signature:

Marks:

Objective: Write a C++ program to simulate the Round Robin CPU scheduling algorithms to
find turnaround time and waiting time.

Outcome: Round Robin CPU scheduling algorithms to find turnaround time and waiting time

Problem Statement: To simulate the Round Robin CPU scheduling algorithms to find
turnaround time and waiting time
Background Study: Round robin function
Question Bank:

(7 MCQ Questions related to topic with ans )

1. Round robin scheduling falls under the category of ____________


a) Non-preemptive scheduling
b) Preemptive scheduling
c) All of the mentioned
d) None of the mentioned

Answer: b

2. With round robin scheduling algorithm in a time shared system ____________


a) using very large time slices converts it into First come First served scheduling algorithm
b) using very small time slices converts it into First come First served scheduling algorithm
c) using extremely small time slices increases performance
d) using very small time slices converts it into Shortest Job First algorithm

Answer: a
Explanation: All the processes will be able to get completed.

3. The portion of the process scheduler in an operating system that dispatches processes is concerned
with ____________
a) assigning ready processes to CPU
b) assigning ready processes to waiting queue
c) assigning running processes to blocked queue
xlviii

Real Time Operating System (ECL 362)


2020-21

d) all of the mentioned


Answer: a

4. Complex scheduling algorithms ____________


a) are very appropriate for very large computers
b) use minimal resources
c) use many resources
d) all of the mentioned

Answer: a
Explanation: Large computers are overloaded with a greater number of processes.

5. The strategy of making processes that are logically runnable to be temporarily suspended is called
____________
a) Non preemptive scheduling
b) Preemptive scheduling
c) Shortest job first
d) First come First served
Answer: b

6. What is Scheduling?
a) allowing a job to use the processor
b) making proper use of processor
c) all of the mentioned
d) none of the mentioned

Answer: a

7. There are 10 different processes running on a workstation. Idle processes are waiting for an input
event in the input queue. Busy processes are scheduled with the Round-Robin time sharing method.
Which out of the following quantum times is the best value for small response times, if the processes
have a short runtime, e.g. less than 10ms?
a) tQ = 15ms
b) tQ = 40ms
c) tQ = 45ms
d) tQ = 50ms
View Answer

Answer: a

Student Work Area

Code & Sample Outputs


xlix

Real Time Operating System (ECL 362)


2020-21

#include<iostream>

#include<cstdlib>

#include<queue>

#include<cstdio>

using namespace std;

/* C++ Program to Round Robin*/

typedef struct process

int id,at,bt,st,ft,pr;

float wt,tat;

}process;

process p[10],p1[10],temp;

queue<int> q1;

int accept(int ch);

void turnwait(int n);

void display(int n);

void ganttrr(int n);

int main()

int i,n,ts,ch,j,x;

p[0].tat=0;

p[0].wt=0;

n=accept(ch);

ganttrr(n);
l

Real Time Operating System (ECL 362)


2020-21

turnwait(n);

display(n);

return 0;

int accept(int ch)

int i,n;

printf("Enter the Total Number of Process: ");

scanf("%d",&n);

if(n==0)

printf("Invalid");

exit(1);

cout<<endl;

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

printf("Enter an Arrival Time of the Process P%d: ",i);

scanf("%d",&p[i].at);

p[i].id=i;

cout<<endl;

for(i=1;i<=n;i++)
li

Real Time Operating System (ECL 362)


2020-21

printf("Enter a Burst Time of the Process P%d: ",i);

scanf("%d",&p[i].bt);

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

p1[i]=p[i];

return n;

void ganttrr(int n)

int i, ts, m, nextval, nextarr;

nextval=p1[1].at;

i=1;

cout<<"\nEnter the Time Quantum: ";

cin>>ts;

for(i=1;i<=n && p1[i].at<=nextval;i++)

q1.push(p1[i].id);

while(!q1.empty())

m=q1.front();

q1.pop();
lii

Real Time Operating System (ECL 362)


2020-21

if(p1[m].bt>=ts)

nextval=nextval+ts;

else

nextval=nextval+p1[m].bt;

if(p1[m].bt>=ts)

p1[m].bt=p1[m].bt-ts;

else

p1[m].bt=0;

while(i<=n&&p1[i].at<=nextval)

q1.push(p1[i].id);

i++;

if(p1[m].bt>0)

q1.push(m);
liii

Real Time Operating System (ECL 362)


2020-21

if(p1[m].bt<=0)

p[m].ft=nextval;

void turnwait(int n)

int i;

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

p[i].tat=p[i].ft-p[i].at;

p[i].wt=p[i].tat-p[i].bt;

p[0].tat=p[0].tat+p[i].tat;

p[0].wt=p[0].wt+p[i].wt;

p[0].tat=p[0].tat/n;

p[0].wt=p[0].wt/n;

void display(int n)

int i;

/*

Here
liv

Real Time Operating System (ECL 362)


2020-21

at = Arrival time,

bt = Burst time,

time_quantum= Quantum time

tat = Turn around time,

wt = Waiting time

*/

cout<<"\n=====================================================\n";

cout<<"\n\nHere AT = Arrival Time\nBT = Burst Time\nTAT = Turn Around Time\nWT =


Waiting Time\n";

cout<<"\n===================TABLE==============================\n";

printf("\nProcess\tAT\tBT\tFT\tTAT\t\tWT");

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

printf("\nP%d\t%d\t%d\t%d\t%f\t%f",p[i].id,p[i].at,p[i].bt,p[i].ft,p[i].tat,p[i].wt);

cout<<"\n=====================================================\n";

printf("\nAverage Turn Around Time: %f",p[0].tat);

printf("\nAverage Waiting Time: %f\n",p[0].wt);

}
lv

Real Time Operating System (ECL 362)


2020-21
lvi

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 13
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Semester ECE
Date: 07/04/2021
Faculty Signature:

Marks:

Objective: Write a C++ program to simulate the Priority non- preemptive CPU scheduling
algorithms to find turnaround time and waiting time.

Outcome: Priority non--preemptive CPU scheduling algorithms to find turnaround and waiting time.
Problem Statement: To simulate Priority non--preemptive CPU scheduling algorithms to find
turnaround and waiting time.
Background Study:
Question Bank:

(7 MCQ Questions related to topic with ans )


1. The algorithms are ________.
A. non-preemptive
B. preemptive
C. Both A and B
D. None of the above
Ans : C
Explanation: The algorithms are either non-preemptive or preemptive.

2. Which of the following algorithms work based on priority?


A. non-preemptive
B. preemptive
C. Both A and B
D. None of the above
View Answer
Ans : B
Explanation: The preemptive scheduling is based on priority where a scheduler may preempt a low
priority running process anytime when a high priority process enters into a ready state.

3. Which of the following is non-preemptive algorithm?


A. Priority Based Scheduling
B. Shortest Remaining Time
C. FCFS
D. shortest job first
Ans : A
lvii

Real Time Operating System (ECL 362)


2020-21

Explanation: Priority scheduling is a non-preemptive algorithm and one of the most common
scheduling algorithms in batch systems.

4. Which of the following is preemptive algorithm?


A. Round Robin Scheduling
B. Shortest Remaining Time
C. Multiple-Level Queues Scheduling
D. Both A and B
Ans : D
Explanation: Both A and B is preemptive algorithm

5. __________ is used to save states of preempted processes.


A. Context switching
B. Quantam
C. Process Period
D. Batch Jobs
Ans : A
Explanation: In RR, Context switching is used to save states of preempted processes.

6. Scheduling algorith In multilevel feedback


A. processes are not classified into groups
B. a process can move to a different classified ready queue…
C. classification of the ready queue is permanent
D. none of the mentioned
Answer: B

7. At the ready queue when a process arrives In priority scheduling algorithm, the priority of this
process is compared with the priority of?
A. currently running process
B. parent process
C. all process
D. init process
Answer: A

Student Work Area

Code & Sample Outputs

#include<iostream>
lviii

Real Time Operating System (ECL 362)


2020-21

using namespace std;

int main()

int a[10],b[10],x[10],pr[10]={0};

int waiting[10],turnaround[10],completion[10];

int i,j,smallest,count=0,time,n;

double avg=0,tt=0,end;

cout<<"\nEnter the number of Processes: ";

cin>>n;

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

cout<<"\nEnter arrival time of process: ";

cin>>a[i];

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

cout<<"\nEnter burst time of process: ";

cin>>b[i];

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

cout<<"\nEnter priority of process: ";

cin>>pr[i];

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

Real Time Operating System (ECL 362)


2020-21

x[i]=b[i];

pr[9]=-1;

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

smallest=9;

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

if(a[i]<=time && pr[i]>pr[smallest] && b[i]>0 )

smallest=i;

time+=b[smallest]-1;

b[smallest]=-1;

count++;

end=time+1;

completion[smallest] = end;

waiting[smallest] = end - a[smallest] - x[smallest];

turnaround[smallest] = end - a[smallest];

cout<<"Process"<<"\t"<< "burst-time"<<"\t"<<"arrival-time" <<"\t"<<"waiting-time"


<<"\t"<<"turnaround-time"<< "\t"<<"completion-time"<<"\t"<<"Priority"<<endl;

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

cout<<"p"<<i+1<<"\t\t"<<x[i]<<"\t\t"<<a[i]<<"\t\t"<<waiting[i]<<"\t\t"<<turnaround[i]<<"\t\t"
<<completion[i]<<"\t\t"<<pr[i]<<endl;
lx

Real Time Operating System (ECL 362)


2020-21

avg = avg + waiting[i];

tt = tt + turnaround[i];

cout<<"\n\nAverage waiting time ="<<avg/n;

cout<<" Average Turnaround time ="<<tt/n<<endl;

}
lxi

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 14
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Semester ECE
Date: 10/04/2021
Faculty Signature:

Marks:

Objective: Write a C++ program to simulate the Priority preemptive CPU scheduling algorithms to
find turnaround time and waiting time

Outcome: Priority preemptive CPU scheduling algorithms to find turnaround time and waiting time.
Problem Statement: To simulate the Priority preemptive CPU scheduling algorithms to find
turnaround time and waiting time
Background Study: Priority scheduling
Question Bank:

(7 MCQ Questions related to topic with ans )


1. In Priority Based Scheduling, if Processes have same priority then which Scheduling algorithm is
used?
A. SJN
B. FCFS
C. SRT
D. Round Robin

Ans : B
Explanation: Processes with same priority are executed on first come first served basis.

2. At the ready queue when a process arrives In priority scheduling algorithm, the priority of this
process is compared with the priority of?
A. currently running process
B. parent process
C. all process
D. init process

Answer: A

3. scheduling algorithms that work on complex :


A. uses few resources
B. uses most resources
C. are suitable for large computers
D. all of the mentioned
lxii

Real Time Operating System (ECL 362)


2020-21

Answer:C
4. scheduling algorithm which allocates the CPU first to the process which requests the CPU first?
A. FCFS scheduling
B. priority scheduling
C. shortest job scheduling
D. none of the mentioned

Answer: A

5. In an operating system, the portion of the process scheduler that forward processes is concerned
with :
A. running processes are assigning to blocked queue
B. ready processes are assigning to CPU
C. ready processes are assigning to the waiting queue
D. all of the mentioned

Answer: B

6. From the time of submission of a process to the time of completion, The interval is termed as
A. waiting time
B. turnaround time
C. response time
D. throughput

Answer: B

7. From the time of submission of a process to the time of completion, The interval is termed as
A. waiting time
B. turnaround time
C. response time
D. throughput
Answer: B

Student Work Area

Code & Sample Outputs

#include<iostream>

using namespace std;


lxiii

Real Time Operating System (ECL 362)


2020-21

int main()

int a[10],b[10],x[10];

int waiting[10],turnaround[10],completion[10],p[10];

int i,j,smallest,count=0,time,n;

double avg=0,tt=0,end;

cout<<"\nEnter the number of Processes: ";

cin>>n;

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

cout<<"\nEnter arrival time of process: ";

cin>>a[i];

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

cout<<"\nEnter burst time of process: ";

cin>>b[i];

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

cout<<"\nEnter priority of process: ";

cin>>p[i];

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

x[i]=b[i];
lxiv

Real Time Operating System (ECL 362)


2020-21

p[9]=-1;

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

smallest=9;

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

if(a[i]<=time && p[i]>p[smallest] && b[i]>0 )

smallest=i;

b[smallest]--;

if(b[smallest]==0)

count++;

end=time+1;

completion[smallest] = end;

waiting[smallest] = end - a[smallest] - x[smallest];

turnaround[smallest] = end - a[smallest];

cout<<"Process"<<"\t"<< "burst-time"<<"\t"<<"arrival-time" <<"\t"<<"waiting-time"


<<"\t"<<"turnaround-time"<< "\t"<<"completion-time"<<"\t"<<"Priority"<<endl;

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

cout<<"p"<<i+1<<"\t\t"<<x[i]<<"\t\t"<<a[i]<<"\t\t"<<waiting[i]<<"\t\t"<<turnaround[i]<<"\t\t"
<<completion[i]<<"\t\t"<<p[i]<<endl;
lxv

Real Time Operating System (ECL 362)


2020-21

avg = avg + waiting[i];

tt = tt + turnaround[i];

cout<<"\n\nAverage waiting time ="<<avg/n;

cout<<" Average Turnaround time ="<<tt/n<<endl;

}
lxvi

Real Time Operating System (ECL 362)


2020-21

EXPERIMENT NO. 15
Student Name and Roll Number: Parth Bathla (18ecu016)
Semester /Section: 6th Semester ECE
Date: 05/05/2021
Faculty Signature:

Marks:

Objective: Write a C++ program to simulate Bankers algorithm for the purpose of deadlock
avoidance.

Outcome: Simulate Bankers algorithm for the purpose of deadlock avoidance.

Problem Statement: To simulate Bankers algorithm for the purpose of deadlock avoidance.
Background Study: Bankers problem using deadlock situation
Question Bank:

(7 MCQ Questions related to topic with ans )

1. Each request requires that the system consider the _____________ to decide whether the current
request can be satisfied or must wait to avoid a future possible deadlock.
a) resources currently available
b) processes that have previously been in the system
c) resources currently allocated to each process
d) future requests and releases of each process

Answer: a

2. Given a priori information about the ________ number of resources of each type that maybe
requested for each process, it is possible to construct an algorithm that ensures that the system will
never enter a deadlock state.
a) minimum
b) average
c) maximum
d) approximate

Answer: c

3. A deadlock avoidance algorithm dynamically examines the __________ to ensure that a circular
wait condition can never exist.
a) resource allocation state
b) system storage state
lxvii

Real Time Operating System (ECL 362)


2020-21

c) operating system
d) resources

Answer: a
Explanation: Resource allocation states are used to maintain the availability of the already and
current available resources.

4. A state is safe, if ____________


a) the system does not crash due to deadlock occurrence
b) the system can allocate resources to each process in some order and still avoid a deadlock
c) the state keeps the system protected and safe
d) all of the mentioned

Answer: b.

5. A system is in a safe state only if there exists a ____________


a) safe allocation
b) safe resource
c) safe sequence
d) all of the mentioned

Answer: c

6. All unsafe states are ____________


a) deadlocks
b) not deadlocks
c) fatal
d) none of the mentioned

Answer: b

7. If no cycle exists in the resource allocation graph ____________


a) then the system will not be in a safe state
b) then the system will be in a safe state
c) all of the mentioned
d) none of the mentioned

Answer: b
lxviii

Real Time Operating System (ECL 362)


2020-21

Student Work Area

Code & Sample Outputs

#include<stdio.h>

#include<conio.h>

int main() {

int
k=0,output[10],d=0,t=0,ins[5],i,avail[5],allocated[10][5],need[10][5],MAX[10][5],pno,P[10],j,rz
, count=0;

printf("\n Enter the number of resources : ");

scanf("%d", &rz);

printf("\n enter the max instances of each resources\n");

for (i=0;i<rz;i++) {

avail[i]=0;

printf("%c= ",(i+97));

scanf("%d",&ins[i]);

printf("\n Enter the number of processes : ");

scanf("%d", &pno);

printf("\n Enter the allocation matrix \n ");

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

printf(" %c",(i+97));

printf("\n");

for (i=0;i <pno;i++) {

P[i]=i;

printf("P[%d] ",P[i]);

for (j=0;j<rz;j++) {
lxix

Real Time Operating System (ECL 362)


2020-21

scanf("%d",&allocated[i][j]);

avail[j]+=allocated[i][j];

printf("\nEnter the MAX matrix \n ");

for (i=0;i<rz;i++) {

printf(" %c",(i+97));

avail[i]=ins[i]-avail[i];

printf("\n");

for (i=0;i <pno;i++) {

printf("P[%d] ",i);

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

scanf("%d", &MAX[i][j]);

printf("\n");

A: d=-1;

for (i=0;i <pno;i++) {

count=0;

t=P[i];

for (j=0;j<rz;j++) {

need[t][j] = MAX[t][j]-allocated[t][j];

if(need[t][j]<=avail[j])

count++;

}
lxx

Real Time Operating System (ECL 362)


2020-21

if(count==rz) {

output[k++]=P[i];

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

avail[j]+=allocated[t][j];

} else

P[++d]=P[i];

if(d!=-1) {

pno=d+1;

goto A;

printf("\t <");

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

printf(" P[%d] ",output[i]);

printf(">");

getch();

}
lxxi

Real Time Operating System (ECL 362)


2020-21

You might also like