0% found this document useful (0 votes)
12 views9 pages

OSY PR

pr os

Uploaded by

sanskaruravane9
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)
12 views9 pages

OSY PR

pr os

Uploaded by

sanskaruravane9
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/ 9

Course code: 22516

MARATHAWADA MITRAMANDAL’S POLYTECHNIC,


THERGAON, PUNE-33
Academic Year 2024-25
PRACTICAL EXAM QUESTION BANK
Program Name: Computer Engineering Program Code: CO5I
Course: Operating System 22516
Marks: PA 25 marks and ESE 25 marks

1) Execute general purpose commands

Date date

time time ls

cal cal

banner sudo apt install sysvbanner banner "Hello"

TTY tty

script script

man. man date

2) Work with multiple Linux terminals, and basic commands:

who who

who am I whoami

login login

passwd passwd

pwd pwd

3)

a) Use operating services(Edittor,GUI, File Handling)

vi filename.txt
b) Run commands to start, stop, and restart the specified service in Linux

sudo systemctl start apache2

sudo systemctl stop apache2

sudo systemctl restart apache2

sudo systemctl status apache2

sudo systemctl enable apache2

4) Execute process commands ps, wait, exit, sleep, kill

ps aux

sleep 5 & # Run a command in the background

wait # Wait for the background process to complete

exit 0 # Exits with success status

sleep 10 # Wait for 10 seconds before continuing

kill 1234 # Kill process with PID 1234

kill -9 1234 # Forcefully kill process with PID 1234

5) Execute file and directory manipulation commands- ls,rm,mv, cp, join,


spilit, cat(file saving and redirection operator) , head, tail, touch

ls -l

rm file.txt # Removes a file

rm -r dir_name # Removes a directory and its contents

mv oldfile.txt newfile.txt # Renames the file

mv file.txt /path/to/destination/ # Moves the file to another directory

cp file.txt /path/to/destination/ # Copies file to another directory

cp -r folder1 folder2 # Copies folder1 to folder2


6) Execute file and directory manipulation commands-diff, comm., pr, mkdir,
rmdir, cd, pwd, dir, cmp. (Use wild card characters).

diff file1.txt file2.txt

comm file1.txt file2.txt

pr -h "File Content" file.txt

mkdir new_directory

mkdir -p parent_directory/subdirectory # Creates nested directories

rmdir old_directory # Removes an empty directory

7) Execute text processing tr,wc, cut, paste, spell, sort grep, more

echo "hello world" | tr 'a-z' 'A-Z'

echo "hello123" | tr -d '0-9'

wc -l file.txt # Count lines in file.txt

wc -w file.txt # Count words in file.txt

wc -c file.txt # Count characters in file.txt

echo "apple,banana,orange" | cut -d ',' -f 2

echo "abcdef" | cut -c 1-3

8) Use vi editor and perform all editor commands.

vi filename.txt

9) Write and execute Shell Script using following control statement features-
"if" statement

#!/bin/bash

# Prompt the user to enter a number

echo "Enter a number: "


read num

# Check the condition using 'if' statement

if [ $num -gt 10 ]; then

echo "The number is greater than 10."

elif [ $num -lt 10 ]; then

echo "The number is less than 10."

else

echo "The number is equal to 10."

Fi

10) Write and execute Shell Script using following control statement
features- "for" statement

#!/bin/bash

# Using a 'for' loop to print numbers from 1 to 5

for i in {1..5}

do

echo "Number: $i"

done

11) Write Shell Script to find out whether- Given file exists?

#!/bin/bash

# Prompt the user to enter the filename

echo "Enter the file name (with path if necessary):"


read filename

# Check if the file exists

if [ -e "$filename" ]; then

echo "The file '$filename' exists."

else

echo "The file '$filename' does not exist."

fi

12) Write Shell Script to find out whether- File has read, write and execute
permissions?

#!/bin/bash

echo "Enter the file name:"

read filename

if [ -e "$filename" ]; then

[ -r "$filename" ] && echo "Read permission: Yes" || echo "Read


permission: No"

[ -w "$filename" ] && echo "Write permission: Yes" || echo "Write


permission: No"

[ -x "$filename" ] && echo "Execute permission: Yes" || echo "Execute


permission: No"

else

echo "The file '$filename' does not exist."

Fi
13) Write a program to calculate total waiting and turnaround time of n
processes with First Come First Serve CPU scheduling algorithm.

#include <stdio.h>

void calculateTimes(int n, int bt[]) {

int wt[n], tat[n], totalWT = 0, totalTAT = 0;

wt[0] = 0; // Waiting time for the first process is 0

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

wt[i] = bt[i - 1] + wt[i - 1];

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

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

totalWT += wt[i];

totalTAT += tat[i];

printf("Process\tBurst Time\tWaiting Time\tTurnaround Time\n");

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

printf("%d\t%d\t\t%d\t\t%d\n", i + 1, bt[i], wt[i], tat[i]);

printf("\nAverage Waiting Time: %.2f\n", (float)totalWT / n);

printf("Average Turnaround Time: %.2f\n", (float)totalTAT / n);

int main() {

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

scanf("%d", &n);

int bt[n];

printf("Enter burst times for each process:\n");

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

printf("Process %d: ", i + 1);

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

calculateTimes(n, bt);

return 0;

14) Write a 'c' program to implement FIFO page replacement algorithm.

#include <stdio.h>

void fifoPageReplacement(int pages[], int n, int capacity) {

int frame[capacity], front = 0, pageFaults = 0, pageHits = 0;

for (int i = 0; i < capacity; i++) frame[i] = -1;

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

int found = 0;

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

if (frame[j] == pages[i]) { found = 1; pageHits++; break; }


}

if (!found) {

pageFaults++;

if (front < capacity) frame[front++] = pages[i];

else {

for (int j = 0; j < capacity - 1; j++) frame[j] = frame[j + 1];

frame[capacity - 1] = pages[i];

printf("Frame: ");

for (int j = 0; j < capacity; j++) printf("%d ", frame[j]);

printf("\n");

printf("\nPage Faults: %d\nPage Hits: %d\n", pageFaults, pageHits);

int main() {

int n, capacity;

printf("Enter the number of pages: ");

scanf("%d", &n);

int pages[n];

printf("Enter page references: ");

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

printf("Enter number of frames: ");


scanf("%d", &capacity);

fifoPageReplacement(pages, n, capacity);

return 0;

You might also like