0% found this document useful (0 votes)
64 views18 pages

Shubh Kapil: Mid Term Lab

The mid term lab report submitted by Shubh Kapil (registration no. 20BCI0265) covers the subject CSE 2005 - Operating Systems. The lab included three questions - the first involving input validation of strings in shell scripting, the second demonstrating processes and inter-process communication in C++, and the third implementing a process scheduling simulator in C++ to calculate metrics like average waiting time.

Uploaded by

shubh kapil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views18 pages

Shubh Kapil: Mid Term Lab

The mid term lab report submitted by Shubh Kapil (registration no. 20BCI0265) covers the subject CSE 2005 - Operating Systems. The lab included three questions - the first involving input validation of strings in shell scripting, the second demonstrating processes and inter-process communication in C++, and the third implementing a process scheduling simulator in C++ to calculate metrics like average waiting time.

Uploaded by

shubh kapil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

MID TERM LAB

NAME: SHUBH KAPIL

REGISTRATION NO.: 20BCI0265

SUBJECT: CSE 2005 – OPERATING


SYSTEMS

FACULTY: SIVASANKARI S
ANS 1:

CODE:
echo "Enter two strings";
read str1
read str2

if[ -z "$str1"]
then
echo"\$string 1 is NULL"
fi

if[ -z "$str2"]
then
echo"\$string 2 is NULL"
fi

if [[ $str1=~['!@#$%^&*()_+'] ]];
then
echo"\$string 1 has special characters"
fi

if [[ $str2=~['!@#$%^&*()_+'] ]];
then
echo"\$string 2 has special characters"
fi
if[ $str1==$str2]
then
echo "EQUAL"
else
echo "NOT EQUAL"
fi

OUTPUTS:
ANS 2 a:

CODE:

OUTPUT:
CODE:

#include<unistd.h>
#include<iostream>
#include<cstdlib>
using namespace std;

int main()
{
cout<<"OPERATING "<<endl;
cout.flush();
sleep(10);
cout<<"SYSTEM "<<endl;
cout.flush();
sleep(10);
cout<<"CAT 1"<<endl;
return 0;
}
ANS 2 B:

CODE:
OUTPUT:
ANS 3.

CODE:
CODE:

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

struct process {
int pid;
int arrival_time;
int burst_time;
int priority;
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 burst_remaining[100];
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;
cout<<"Enter priority of the process "<<i+1<<": ";
cin>>p[i].priority;
p[i].pid = i+1;
burst_remaining[i] = p[i].burst_time;
cout<<endl;
}

int current_time = 0;
int completed = 0;
int prev = 0;
while(completed != n) {
int idx = -1;
int mx = -1;
for(int i = 0; i < n; i++) {
if(p[i].arrival_time <= current_time && is_completed[i] == 0) {
if(p[i].priority > mx) {
mx = p[i].priority;
idx = i;
}
if(p[i].priority == mx) {
if(p[i].arrival_time < p[idx].arrival_time) {
mx = p[i].priority;
idx = i;
}
}
}
}

if(idx != -1) {
if(burst_remaining[idx] == p[idx].burst_time) {
p[idx].start_time = current_time;
total_idle_time += p[idx].start_time - prev;
}
burst_remaining[idx] -= 1;
current_time++;
prev = current_time;

if(burst_remaining[idx] == 0) {
p[idx].completion_time = current_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;

is_completed[idx] = 1;
completed++;
}
}
else {
current_time++;
}
}

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"<<"PRI\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].priority<<"\t"<<p
[i].start_time<<"\t"<<p[i].completion_time<<"\t"<<p[i].turnaround_time<<"\t"<<p[i].waitin
g_time<<"\t"<<p[i].response_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;

}
OUTPUT:
GANTT CHART:

You might also like