0% found this document useful (0 votes)
9 views

O.S Lab Programming

Doc's

Uploaded by

aadarshgupta388
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

O.S Lab Programming

Doc's

Uploaded by

aadarshgupta388
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Implementation of FCFS Scheduling algorithm

#include<iostream>
using namespace std;

struct process
{
int process_id;
int arrival_time;
int brust_time;
int completion_time;
int turnAround_time;
int waiting_time;

};

void findCompletionTime(process arr[],int n)


{
arr[0].completion_time= arr[0].brust_time;
for(int i=1;i<n;i++)
{
arr[i].completion_time = arr[i-1].completion_time + arr[i].brust_time;
}
}

void findTurnAroundTime(process arr[],int n)


{
for(int i=0;i<n;i++)
{
arr[i].turnAround_time = arr[i].completion_time - arr[i].arrival_time;
}
}

void findWaitingTime(process arr[],int n)


{
arr[0].waiting_time=0;
for(int i=1;i<n;i++)
{
arr[i].waiting_time = arr[i].turnAround_time - arr[i].brust_time;
}
}
void findFCFS(process arr[], int n)
{
findCompletionTime(arr,n);
findTurnAroundTime(arr,n);
findWaitingTime(arr,n);

void printFCFS(process arr[], int n)


{
cout<<"The First Come First Server Algorithms :"<<endl;
cout<<"Process No.\t"<<"Arrival Time\t"<<"Brust Time\t"<<"Completions Time\t"
<<"TurnAround Time\t\t"<<"Waiting Time"<<endl;

for(int i=0;i<n;i++)
{
cout<<arr[i].process_id<<"\t\t\t"<<arr[i].arrival_time<<"\t\t"<<arr[i].brust_time<<"\t\t"

<<arr[i].completion_time<<"\t\t"<<arr[i].turnAround_time<<"\t\t\t"<<arr[i].waiting_time<<endl;

}
}

int main()
{
int n=5;
process arr[n]={{1,4,3},{2,5,1},{3,9,6},{4,7,5},{5,8,3}};
findFCFS(arr,n);
printFCFS(arr,n);

cout<<"Solved by : Mr. Sahil Kumar / PtuCoder !"<<endl;


return 0;
}
OUTPUT ➖
The First Come First Server Algorithms :

Process No. Arrival Time Burst Time Completions Time TurnAround Time Waiting Time

1 4 3 3 -1 0
2 5 1 4 -1 -2
3 9 6 10 1 -5
4 7 5 15 8 3
5 8 3 18 10 7

Solved by : Mr. Sahil Kumar / PtuCoder !


Implementation of SJF Scheduling algorithm

#include<iostream>
using namespace std;

struct process
{
int process_no;
int arrival_time;
int burst_time;
int completion_time;
int turnAround_time;
int waiting_time;

};

void findSJF(process arr[], int n)


{
int remaining_time[n];
for(int i=0;i<n;i++)
{
remaining_time[i]=arr[i].burst_time;

}
int currentTime=0;
int complete=0;
int shortest =0;
int minBurst=9999;

while(complete<n)
{
minBurst=9999;
for(int i=0;i<n;i++)
{
if(arr[i].arrival_time<=currentTime && remaining_time[i]<minBurst &&
remaining_time[i]>0)
{
minBurst=remaining_time[i];
shortest=i;
}
}
remaining_time[shortest]--;
if(remaining_time[shortest]==0)
{
complete++;
arr[shortest].completion_time = currentTime+1;

arr[shortest].turnAround_time = arr[shortest].completion_time -
arr[shortest].arrival_time;

arr[shortest].waiting_time=arr[shortest].turnAround_time - arr[shortest].burst_time;
}
currentTime++;

}
}

void printSJF(process arr[], int n)


{
cout<<"Process\t Arrival\t Burst\t Completion\t TurnAround\t Waiting"<<endl;

for(int i=0;i<n;i++)
{
cout<<arr[i].process_no<<"\t\t"<<arr[i].arrival_time<<"\t"<<arr[i].burst_time<<"\t"

<<arr[i].completion_time<<"\t\t"<<arr[i].turnAround_time<<"\t\t"<<arr[i].waiting_time<<endl;

}
cout<<endl;
cout<<"Solved by : PtuCoder or Sahil Rauniyar !"<<endl;

int main()
{
int n=5;
process arr[n];
cout<<"ENter the process details (process id \t arrival time \t burst time :)"<<endl;
for(int i=0;i<n;i++)
{
cout<<"ENter the process :"<<endl;
cin>>arr[i].process_no>>arr[i].arrival_time>>arr[i].burst_time;
}
findSJF(arr,n);
printSJF(arr,n);
return 0;

OUTPUT ➖
ENter the process details (process id arrival time burst time :)

ENter the process :


1
5
3
ENter the process :
2
7
4
ENter the process :
3
8
4
ENter the process :
4
9
6
ENter the process :
5
4
1

Process Arrival Burst Completion TurnAround Waiting

1 5 3 3 -2 -5
2 7 4 11 4 0
3 8 4 15 7 3
4 9 6 21 12 6
5 4 1 5 1 0

Solved by : PtuCoder or Sahil Rauniyar !


Implementation of Round-Robin Scheduling algorithm

#include <iostream>
using namespace std;

struct process
{
int process_no;
int arrival_time;
int burst_time;
int completion_time;
int turnAround_time;
int waiting_time;
};

void findCurrentCompletionRemainingTime(process arr[], int n, int qt)


{
int remainingTime[n];
int i;
for (i = 0; i < n; i++)
{
remainingTime[i] = arr[i].burst_time;
}

int currentTime = 0;
bool allDone = false;
while (!allDone)
{
allDone = true;
for (int i = 0; i < n; i++)
{
if (remainingTime[i] > 0)
{
allDone = false;
if (remainingTime[i] > qt)
{
currentTime = currentTime + qt;
remainingTime[i] = remainingTime[i] - qt;
}
else
{
currentTime = currentTime + remainingTime[i];
arr[i].completion_time = currentTime;
remainingTime[i] = 0;
}
}
}
}
}

void findTurnAroundTime(process arr[], int n)


{
int i;
for (i = 0; i < n; i++)
{
arr[i].turnAround_time = arr[i].completion_time - arr[i].arrival_time;
}
}

void findWaitingTime(process arr[], int n)


{
int i;
for (i = 0; i < n; i++)
{
arr[i].waiting_time = arr[i].turnAround_time - arr[i].burst_time;
}
}

void printRoundRobinScheduling(process arr[], int n)


{
cout << "ProcessNo\t ArrivalTime\t BurstTime\t CompletionTime\t TurnAroundTime\t
WaitingTime " << endl;
int i;
for (i = 0; i < n; i++)
{
cout << arr[i].process_no << "\t\t" << arr[i].arrival_time << "\t\t" << arr[i].burst_time <<
"\t\t"
<< arr[i].completion_time << "\t\t" << arr[i].turnAround_time << "\t\t" <<
arr[i].waiting_time << endl;
}
}
int main()
{
int n, qt;
cout << "Enter the size of process :";
cin >> n;
cout << "Enter the time quantum :";
cin >> qt;

process arr[n];
cout << "ENter the process details :" << endl;
for (int i = 0; i < n; i++)
{
cout << "Process " << i + 1 << ":\n";
arr[i].process_no = i + 1;
cout << "Arrival Time :";
cin >> arr[i].arrival_time;
cout << "Burst Time :";
cin >> arr[i].burst_time;
}

findCurrentCompletionRemainingTime(arr, n, qt);

findTurnAroundTime(arr, n);

findWaitingTime(arr, n);

cout << "Round Robin Scheduling Results :" << endl;

printRoundRobinScheduling(arr, n);

cout << "Solved by : Mr. Sahil Kumar / PtuCoder !" << endl;

return 0;
}
OUTPUT ➖
Enter the size of process :4
Enter the time quantum :2

ENter the process details :

Process 1:
Arrival Time :4
Burst Time :6

Process 2:
Arrival Time :2
Burst Time :5

Process 3:
Arrival Time :8
Burst Time :5

Process 4:
Arrival Time :7
Burst Time :9

Round Robin Scheduling Results :

ProcessNo ArrivalTime BurstTime CompletionTime TurnAroundTime WaitingTime


1 4 6 18 14 8
2 2 5 19 17 12
3 8 5 20 12 7
4 7 9 25 18 9

Solved by : Mr. Sahil Kumar / PtuCoder !


Introductions of Operating System ➖
An operating system (OS) is software that acts as an intermediary between computer
hardware and user applications. It manages computer hardware resources and provides
services to software applications.

Here's a basic introduction to operating systems: ➖


Kernel: ➖ At the heart of every operating system is the kernel. It's the core component
responsible for managing hardware resources such as the CPU, memory, and peripheral
devices. The kernel also provides essential services like process management, memory
management, device management, and file system access.

User Interface: ➖ Operating systems provide user interfaces through which users
interact with the computer. This interface can be command-line based (text-based) or
graphical, where users interact with icons, windows, and menus.

Process Management: ➖ The OS is responsible for managing processes, which are


instances of executing programs. It allocates CPU time to processes, schedules them for
execution, and provides mechanisms for inter-process communication and synchronization.

Memory Management: ➖ Operating systems manage the computer's memory, ensuring


that each process has adequate memory to execute and preventing processes from
interfering with each other's memory space.

File System: ➖ The OS provides a file system that organizes and stores data on storage
devices such as hard drives and SSDs. It manages files, directories, and file access
permissions.

Device Management: ➖ Operating systems control peripheral devices such as printers,


keyboards, mice, and network adapters. They provide device drivers that act as
intermediaries between the OS and hardware, enabling communication and control.

Security: ➖ Operating systems implement security mechanisms to protect data and


resources from unauthorised access and malicious software. This includes user
authentication, access control, encryption, and malware detection.

Networking: ➖ Modern operating systems include networking capabilities, allowing


computers to communicate with each other over local networks or the internet. They provide
networking protocols, services, and utilities for data transfer and communication.
Examples of popular operating systems include: ➖
● Windows: ➖ Developed by Microsoft, Windows is one of the most widely used
operating systems for personal computers.

● macOS: ➖Developed by Apple Inc., macOS is the operating system used on


Macintosh computers.

● Linux: ➖ Linux is a Unix-like open-source operating system kernel developed by


Linus Torvalds and used in a variety of distributions (distros) such as Ubuntu, Fedora,
and Debian.

● Unix: ➖ Unix is a family of multitasking, multi user computer operating systems that
derive from the original AT&T Unix, developed in the 1970s.

These are just some of the key aspects and examples of operating systems. They play a
crucial role in enabling users to interact with computers and utilise their capabilities
effectively.
INDEX
Sr. Date: Title : Page Teacher’s
No. No. Sign/Remarks.

01. Installation of windows OS.

02. Installation of Linux OS.

03. Dual boot installation of Operating


systems.

04. Implementation of FCFS Scheduling


algorithm .

05. Implementation of SJF Scheduling


algorithm .

06. Implementation of Round-Robin


Scheduling algorithm .

07. Vi Editor & its commands .

08. Shell Commands .

09. Shell Scripting- Using variables .

10. Shell Scripting- Input & Output.

11. Shell Scripting- Data types.

12. Shell Scripting- Use of arithmetic


operators

13. Shell Scripting- if control statement


programs

14. Shell Scripting- while control statement .

15. Shell Scripting- for control statement.

You might also like