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

Operating System Word

Q1. The student wrote a C program to simulate the FCFS CPU scheduling algorithm by taking input of process IDs and burst times, calculating waiting times, and outputting turnaround times. Q2. The student wrote a C program to simulate round robin scheduling by taking input of arrival times and burst times, implementing time quanta, and outputting waiting times and turnaround times. Q3. The program takes a logical address as input, converts it to a physical address based on relocation and limit registers, and outputs the physical address.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Operating System Word

Q1. The student wrote a C program to simulate the FCFS CPU scheduling algorithm by taking input of process IDs and burst times, calculating waiting times, and outputting turnaround times. Q2. The student wrote a C program to simulate round robin scheduling by taking input of arrival times and burst times, implementing time quanta, and outputting waiting times and turnaround times. Q3. The program takes a logical address as input, converts it to a physical address based on relocation and limit registers, and outputs the physical address.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

DSEU DWARKA CAMPUS

(Formerly Integrated Institute of Technology)


Sector 9, Dwarka, NewDelhi-110077

DEPARTMENT OF COMPUTER SCIENCE


AND ENGINEERING

Operating System
Subject code: CS-PC303
Lab File

Submitted To: Dr. Rama Bansal


Professor: Department of Computer Engineering
Submitted By: Yogeshwar Vashist (10621619)
Diploma CE 2nd Year (3rd Semester)
INDEX
1. Write a program in C to simulate FCFS CPU scheduling Algorithm.
2. Write a program in C to simulate Round Robin CPU Scheduling Algorithm.
3. Write a program in C language to convert logical address to physical address
4. Create a file using vi editor having commands to save and close file.
5. Create a file using vi editor having commands to enter into insertion mode
from command line mode.
6. Write Vi commands to copy text.
7. Write Vi commands to paste text.
8. Write Vi commands to delete text.
9. Create a file in vi editor yourname.txt in current folder and assign reading,
writing and execution permission to user, reading permission to group, none to
other.
10. Create a file with your name and write your roll no, batch, name, address,
University in it and recursively search your name using case insensitive
approach.
11. Create a shell script program where u have taken file name from user and
three-digit octal number from user and write a program to change the set of
permission over the given file.
12. Create a program file to multiply two numbers and display the result (take
input from user).
13. Take your name, roll no, address as input from user and create a file using
shell scripting and input your name, roll no, address into it and display the
result. 14. Create a directory in current directory with your name in Linux OS.
15. Create a txt file with your name in that directory and insert your name, roll
number and address in it in Linux OS.
16. Display the content of your file in Linux OS.
17. Rename your file in Linux OS.
Q.1: Write a program in C to simulate FCFS CPU scheduling Algorithm.
Program:
#include
<stdio.h> int
main()
{
int pid[15];
int bt[15];
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);

printf("Enter process id of %d the processes: \n", n);


for (int i = 0; i < n; i++)
scanf("%d", &pid[i]);

printf("Enter burst time of %d the processes: \n", n);


for (int i = 0; i < n; i++)
scanf("%d", &bt[i]);

int i, wt[n];
wt[0] = 0;

// for calculating waiting time of each process


for (i = 1; i < n; i++)
wt[i] = bt[i - 1] + wt[i - 1];

printf("\n\nProcess ID\tBurst time\tWaiting time\tTurn Around time");


float twt = 0.0;
float tat = 0.0;
for (i = 0; i < n; i++)
{
printf("\n%d\t\t%d\t\t%d\t\t", pid[i], bt[i], wt[i]);

// calculating turn around time of each process


printf("%d\t\t", bt[i] + wt[i]);
// for calculating total waiting time $ turnaround time
twt += wt[i], tat += (wt[i] + bt[i]);
}
float att, awt;

// for calculating average waiting time & average turnaround time


awt = twt / n, att = tat / n;
printf("\n\nAvg. WAT Time = %.2f", awt);
printf("\nAvg. TAT Time = %.2f", att);
}

OUTPUT:

Q.2: Write a program in C to simulate Round Robin CPU Scheduling


Algorithm.
Program :
#include <stdio.h>
#include <conio.h>
void main()
{
// initlialize the variable name
int i, NOP, sum = 0, count = 0, y, quant, wt = 0, tat = 0, at[10], bt[10], temp[10];
float avg_wt, avg_tat;
printf(" Total number of process in the system: ");
scanf("%d", &NOP);
y = NOP; // Assign the number of process to variable y

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


{
printf("\n Enter the Arrival and Burst time of the Process[%d]\n", i + 1);
printf(" Arrival time is: "); // Accept arrival time
scanf("%d", &at[i]);
printf(" Burst time is: "); // Accept the Burst time
scanf("%d", &bt[i]);
temp[i] = bt[i]; // store the burst time in temp array
}
// Accept the Time qunat
printf("\nEnter the Time Quantum for the process: ");
scanf("%d", &quant);
// Display the process No, burst time, Turn Around Time and the waiting time
printf("\n Process No \t\t Burst Time \t\t TAT \t\t Waiting Time ");
for (sum = 0, i = 0; y != 0;)
{
if (temp[i] <= quant && temp[i] > 0) // define the conditions
sum = sum + temp[i], temp[i] = 0, count = 1;

else if (temp[i] > 0)


temp[i] = temp[i] - quant, sum = sum + quant;

if (temp[i] == 0 && count == 1)


{
y--; // decrement the process no.
printf("\n [%d] \t\t\t %d\t\t\t %d\t\t\t %d", i + 1, bt[i], sum - at[i], sum - at[i] -
bt[i]);
wt = wt + sum - at[i] - bt[i], tat = tat + sum - at[i];
count = 0;
}
if (i == NOP - 1)
i = 0;
else if (at[i + 1] <= sum)
i++;
else
i = 0;
}
// represents the average waiting time and Turn Around time
avg_wt = wt * 1.0 / NOP, avg_tat = tat * 1.0 / NOP; printf("\n\
n Average Turn Around Time: \t%f", avg_wt); printf("\n
Average Waiting Time: \t%f", avg_tat);
getch();
}

OUTPUT:
Q 3. Write a program in C language to convert logical address to physical
address.
Program :
#include<stdio.h>
int main()
{
int relocation_register=14000;
int limit_register=1000;
int logical_address,physical_address;
printf("Enter logial address : ");
scanf("%d",&logical_address);
if((logical_address<limit_register)&&(logical_address>=0))
{
physical_address=relocation_register+logical_address*1 ;
printf("Allocated Physical Address is : %d\n",physical_address);
}
else{
printf("Fatal Error!\n");
}
return 0;
}
Output:

Q 4.Create a file using vi editor having commands to save and close file.
To save a file, In Command Line mode, type “:w” and Press Enter. The contents of the file
will be saved.
To close a file, In Command Line mode, type “:q” and Press Enter. The file will be closed.
But, this not works when we haven’t saved the file.

When we want to save and close at the same time, we type “:wq” and Press Enter. The
content of file will be saved and file gets closed.
Sometimes, we want to forcefully close the file, so we will type “:q!” to close the file, this
will not save changes.

Q 5. Create a file using vi editor having commands to enter into insertion


mode from command line mode.
The initial position of cursor is shown in the image below:-
Initially, cursor is at “2” in Line 2.

There are 6 ways to enter into insertion mode from Command Mode in Vi Editor:-

1. Press ‘i’
For newly created file, when we press ‘i’, the cursor moves to BOF (Beginning of
File). But, when we have saved changes, the cursor moves before the current location.
2. Press ‘I’
This will place cursor at the Beginning of current line.

3. Press ‘a’
This will place cursor after the current location.
4.Press ‘A’
This will insert text at the end of the current line.

5. Press ‘o’
This will create a new line below the cursor location.

6. Press ‘O’

This will create a new line above the cursor location.


Q 6.Write Vi commands to copy text.

Ans. STEP-1

This is question 1 in

Command line mode we

have to select th text whi

we have to copy STEP-2

Then we have to press

(yy) for copy the text


STEP-3 Then Our Text is copied.
copy the text is where By yy command.

Q 7.Write Vi commands to paste text.

Ans. In this question we are going to paste the text which we copy in

STEP-1 Open that file in which we have to paste the Text

STEP-2 Press (P) to Paste

the text in insertion mode


STEP- 3

STEP-4 Here we paste the text the we copied.


Q 8. Write Vi commands to delete text.
Three types for deleting text.

1. Ans. In this we are


delete the text in VI

editor

2. STEP-1 In this we
are create a file

STEP-2
Now we are deleting the

selected text

STEP-3 Press (d)) To delete


the text

STEP-
Q 9. Create a file in vi editor yourname.txt in current folder and
assign reading, writing and execution permission to user, reading
permission to group, none to other.

Ans. We are using (chmod) cmd to assign


permission. In the following : The Commands we use
in image.

For Users : (chmod


u=rwx Yogeshwar.txt) , For
group: (chmod g=r Yogeshwar.txt), For others
(chmod o-r Yogeshwar.txt)

Q 10.Create a file with your name and write your roll_no, batch,
name, address, University in it and recursively search your name using case
insensitive approach.

Ans: first we have created aniket.txt and input all details ATQ. The content of
(Yogeshwar.txt) Shown below by using( cat ) cmd.
OUTPUT

Now, recursively search ‘Yogeshwar ’ using case insensitive

approach by using cmd: (grep -ir yogeshwar.

Q11.Create a shell script program where u have taken file name from user
and three-digit octal number from user and write a program to change the
set of permission over the given file.
Q12. Create a program file to multiply two numbers and display the result
(take input from user).
Q13. Take your name, roll no, address as input from user and create a file
using shell scripting and input your name, roll no, address into it and
display the result.
Q 14. Create a directory in current directory with your name in Linux OS.

Q 15. Create a txt file with your name in that directory and insert your name,
roll number and address in it in Linux OS.

Q 16. Display the content of your file in Linux OS.


Q 17. Rename your file in Linux OS.

You might also like