0% found this document useful (0 votes)
8 views36 pages

Os Practicals All

Uploaded by

Kartik Mishra
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)
8 views36 pages

Os Practicals All

Uploaded by

Kartik Mishra
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/ 36

Operating System (2030106404) 4th Sem

Practical – 1
Aim:- Install and Test different types of Operating system.
For downloading Ubuntu we need ISO file of Ubuntu .we can get ISO file

on official website of Ubuntu and also you can choose which version you

want to download.

After downloading ISO file of Ubuntu we have two ways to install .

● We can install Ubuntu in dual boot using boot able pendrive.

● We can install Ubuntu virtualy using any virtual machine.

o In both ways we have to follow following steps:

Utsav Lankapati(2327010601077) Page | 1


Operating System (2030106404) 4th Sem

Step 1: Choose your language.

Step 2: you can change Accessibility or skip it.

Utsav Lankapati(2327010601077) Page | 2


Operating System (2030106404) 4th Sem

Step 3: Select your keybord layout.

Step 4: To improve installion you can connect to internet or you can install without
internet.

Utsav Lankapati(2327010601077) Page | 3


Programming with Java(2030106405) 4th Sem

Step 5: choose install Ubuntu, it will install Ubuntu permenetly.

Step 6: choose Interactive installation.

Step 7: You can choose that you need extra tools or not.

Utsav Lankapati(2327010601077) 4
Programming with Java(2030106405) 4th Sem

Step 8: Select following option.

Step 9: choose Erase disk option.

Utsav Lankapati(2327010601077) 5
Programming with Java(2030106405) 4th Sem
Step 10: Create you account by which you will use Ubuntu.

Step 11: Select your Timezone.

Utsav Lankapati(2327010601077) 6
Programming with Java(2030106405) 4th Sem
Step 12: Click on install button.

Final Step: Restart your system.

And now Ubuntu has been Succesfully Install.

Utsav Lankapati(2327010601077) 7
Programming with Java(2030106405) 4th Sem
Practical – 2
Aim:- Study Various Process Scheduling algorithms.

● There are four types of Scheduling Algorithms.

o FCFS : First come, Frist Served

o SJF : Shortest Job First

o SRTN : Shortest Remaining Time Next

o RR : Round Robin Scheduling

● Explain FCFS Algorithm in detail with example.

❖ Selection criteria: The process that request first is served first. It means

that processes Are service in the exact order as they come.

❖ Decision Mode: Non-pre-emptive: Once a process is selected, it runs until

it blocks for An I/O or some event, or it terminates.

❖ Implementation: This strategy can be implemented by using sorted FIFO

queue. FIFO means First In First Out. When first process enters the

system, it starts its execution. All other processes are appended in a

queue. When CPU becomes free, a process from the first position in a

queue is selected to run.

Example: Consider the following set of four processes. Their arrival time and time

required To complete the execution are given in following table. Consider all

time values in milliseconds

Process Arrival Time Time required


for
completion(∆T
)

Utsav Lankapati(2327010601077) 8
Programming with Java(2030106405) 4th Sem
P0 0 10
P1 1 6
P2 3 2
P3 5 4

❖ Gantt Chart:

Initially only process P0 is present and it allowed to run. But, when P0

completes, all other processes are present .So, next process (P1) from ready

queue is selected and allowed to run till its completes. This is repeated till all

processes complete their execution.

❖ Statistics:

Process Arrival Completio Finish Turnaround Waiting


Time(T0) n Time(T1) Time Time
Time(∆T) (TAT=T1-T0) (TAT-(∆T)
P1 0 10 10 10 0
P2 1 6 16 15 9
P3 3 2 18 15 13
P3 5 4 22 17 13

Average Turn-around Time: (10+15+15+17)/4 = 57/4 =14.25 ms

Average Waiting Time : (0+19+13+13)/4 = 35/4 = 8.75 ms

❖ Advantages:

Simple, Fair, No starvation.

Easy to understand, Easy to implement

Utsav Lankapati(2327010601077) 9
Programming with Java(2030106405) 4th Sem

❖ disadvantages:

Not efficient. Average waiting time is too

high. Convoy effect is possible.

CPU utilization may be too low.

● Explain SJF Algorithm in detail with example.

❖ Selection criteria: The process, that requires shortest time to

complete execution, is served first.

❖ Decision Mode: Non-preemptive: Once a process is selected, it runs until it

blocks for an I/O or some event, or it terminates.

❖ Implementation: This strategy can be implemented by using sorted FIFO

queue. All processes in a queue are sorted in ascending order based in

their required CPU bursts. When CPU becomes free, a process from the

first position in a queue is selected to run.

Example: Consider the following set of four processes. Their arrival time and

time required to complete the execution are given in following table. Consider

all time values in milliseconds.

Process Arrival Time Time required


for
completion(∆T
)
P0 0 10
P1 1 6
P2 3 2
P3 5 4

Utsav Lankapati(2327010601077) 10
Programming with Java(2030106405) 4th Sem

❖ Gantt Chart:

Initially only process P0 is present and it allowed to run. But, when P0 completes, all
other processes are present. So, process with shortest CPU burst (P2) is selected and
allowed to run till it completes. Whenever more than one process in available, such type
of decision is taken. Taken procedure is repeated till the processes complete their
execution.

❖ Statistics:
Process Arrival Completio Finish Turnaroun Waiting
Time(T0) n Time Time(T1) d Time Time
(TAT=T1-T0) (TAT-∆T)
(∆T)
P0 0 10 10 10 0
P1 1 6 22 21 15
P2 3 2 12 9 7
P3 5 4 16 11 7

Average Turn-around Time: (10+21+9+11)/4 = 51/4 =12.75

ms Average Waiting Time : (0+15+7+7)/4 = 29/4 = 7.25 ms

❖ Advantages:

Less waiting time

Good response for short processes.

❖ Disadvantages:

it is difficult to estimate time required to complete execution.

Starvation is possible for long process. Long process may wait

forever.

Utsav Lankapati(2327010601077) 11
Programming with Java(2030106405) 4th Sem

● Explain SRTN Algorithm in detail with example.

❖ Selection criteria: The process, whose remaining run time is shortest, is

served first. This is a preemptive of SJF scheduling.

❖ Decision Mode: Preemptive: When a new process arrives, its time is

compared to the current process remaining time. If the new job needs

less time to finish than the current process, the current process is

suspended and the new job started.

❖ Implementation: This strategy can also be implemented by using sorted

FIFO queue. All processes in a queue are sorted in ascending order based

on their remaining run time. When CPU becomes free, a process from the

first position in a queue is selected to run.

Example: Consider the following set of four processes. Their arrival time and time

required to complete the execution are given in following table. Consider all

time values in milliseconds.

Process Arrival Time(T0) Time required


for
completion(∆
T)
P0 0 10
P1 1 6
P2 3 2
P3 5 4

❖ Gantt Chart:

Utsav Lankapati(2327010601077) 12
Programming with Java(2030106405) 4th Sem

Initially only process P0 is present and it is allowed to run. But, when P1 comes, it has
shortest remaining run time. So, P0 is preempted and P1 is allowed to run, Whenever
new process comes or current process blocks, such type of decision is taken. This
procedure is repeated till all processes complete their execution.

Statistics:

Process Arrival Completio Finish Turnaround Waiting


Time(T0) n Time Time(T1) Time(TAT=T1- Time
(∆T) T0) (TAT-
∆T)
P0 0 10 22 22 12
P1 1 6 9 8 2
P2 3 2 5 2 0
P3 5 4 13 8 4

Utsav Lankapati(2327010601077) 13
Operating System (2030106404) 4th Sem

Average turn-around Time: (22+8+2+8)/4 = 40/4 = 10.0 ms

Average Waiting Time : (12+2+0+4)/4 = 18/4 = 4.5 ms

❖ Advantages:

Less waiting time.

Quite good response for short processes.

❖ Disadvantages:

Again it is difficult to estimate remaining time necessary to complete execution.

Starvation is possible for long process. Long process may wait forever.

Context switch overhead is there.

● Explain Round Robin Algorithm in detail with example.

❖ Selection criteria: The process that requests first is served first. It means

that processes Are served in the exact order as they come. The selection

criteria are same as that of FCFS scheduling.

❖ Decision mode: Pre-emptive: each selected process is assigned a time

interval. Called time quantum or time slice. Process is allowed to run

only of this time interval.

o Here, one of two things is possible: first process needs CPU burst less than

time quantum in this case, process will voluntarily release CPU and it will

be moved to the end of the queue. Second, process needs CPU burst

longer than time quantum. In this case, process will be running at the end

of time quantum. Now, it will be pre-empted and move to the end of the

queue.

o Here, length of time quantum is critical to determine.

Utsav Lankapati(2327010601077) 14
Operating System (2030106404) 4th Sem

❖ Implementation: This strategy can be implemented by using circular FIFO

queue. When new process comes, or process releases CPU, or process is pre-

empted, it is moved to the end of the queue. When CPU becomes free, a

process from the first position in a queue is selected to run.

Example: Consider the following set of four processes. Their arrival time and time

required to complex the execution are give in following table. All time values

are in milliseconds.

Consider that time quantum is of 4 ms, and context switch overhead is of 1 ms.

Utsav Lankapati(2327010601077) 15
Operating System (2030106404) 4th Sem

Process Arrival time(T0) Time required


for
complex(∆T)
P1 0 10
P2 1 6
P3 3 2
P4 5 4

❖ Gantt Chart:

At 4 ms, process P0 completes its time quantum. So it is pre-empted and another


process p1 is allowed to run. At 12 ms, process p2 voluntarily releases CPU, and
another process p0 is selected to run. 1 ms is wasted on each context switch as
overhead. This procedure is repeated till all processes complete their execution.

❖ Statistics:

Process Arrival Completio Finish time Turnaround Waiting


time n time (T1) time time
(T0) (∆T) (TAT=T1-T0) (TAT-
∆T)
P1 0 10 28 28 18
P2 1 6 25 24 18
P3 3 2 12 9 7
P4 5 4 22 17 13

Average turnaround time: (28+24+9+17)/4 = 78/4 = 19.5

ms Average waiting time: (18+18+7+13)/4 = 56/4 = 14.0

ms

Utsav Lankapati(2327010601077) 16
Operating System (2030106404) 4th Sem

❖ Advantages:

One of the oldest, simplest, fairest and most widely used algorithms.

❖ Disadvantages:

Context switch overhead is there.

Determination of time quantum is too critical. If it is too short, it causes frequent

context switches and lowers CPU efficiency. If it is too long, it causes poor response

for short interactive processes.

Utsav Lankapati(2327010601077) 17
Operating System (2030106404) 4th Sem

Practical – 3
Aim:- Test and run UNIX commands.

1. pwd : (print working directory)

2. cd : (change directory)

3. mkdir : (make directory)

4. rmdir : (remove directory)

5. cal : (calendar)

6. date : (show date)

7. echo : (print)

8. passwd : (change password)

9. who : (display user)

10. tty : (display user associated with terminal)

11. man : (print entries)

12. ps : (process ststus)

13. time : (show time)

14. kill : (kill process)

Utsav Lankapati(2327010601077) 18
Operating System (2030106404) 4th Sem

Output:-

Utsav Lankapati(2327010601077) 19
Operating System (2030106404) 4th Sem

Practical-4
Aim: - Write a shell script program to read and display content of
file.
Code:-

echo “Enter your File name”

read file

cat $file

output:-

Utsav Lankapati(2327010601077) 20
Operating System (2030106404) 4th Sem

Practical-5
Aim:- Write a shell script program to perform mathematical
operations (+, -, *, /).

p_5.sh file code :

echo "Enter Two Number:"

read a

read b

sum=`expr $a + $b`

echo Addition = $sum

sub=`expr $a - $b`

echo Subtraction = $sub

mul=`expr $a \* $b`

echo Multiplication = $mul

div=`expr $a / $b`

echo Division = $div

Output:-

Utsav Lankapati(2327010601077) 21
Operating System (2030106404) 4th Sem

Practical-6
Aim:- Write a shell script program to find odd or even numbers.

p_6.sh Code

echo "Enter any number:"

read n

ans=`expr $n % 2`

if [ $ans -eq 0 ]

then

echo "$n is even"

else

echo "$n is odd"

fi

Output:-

Utsav Lankapati(2327010601077) 22
Operating System (2030106404) 4th Sem

Practical-7
Aim:- Write a shell script program to find the maximum of three
numbers.

P_7.sh file code:

echo "Enter Any Three Numbers:"

read a

read b

read c

if [ $a -gt $b ] && [ $a -gt $c ]

then

echo "$a is maximum"

elif [ $b -gt $a ] && [ $b -gt $c ]

then

echo "$b is maximum"

else

echo "$c is maximum"

fi

Output:-

Utsav Lankapati(2327010601077) 23
Operating System (2030106404) 4th Sem

Practical-8
Aim:- Write a shell script program to find the factorial of a given
number.

p8.sh file:

echo "enter any number:"

read n

fact=1

while [ $n -gt 1 ]

do

fact=`expr $fact \* $n`

n=`expr $n - 1`

done

echo "Factorial of given number is : "$fact

Output:-

Utsav Lankapati(2327010601077) 24
Operating System (2030106404) 4th Sem

Practical-9
Aim:- Write a shell script program to concatenate the contents
of two files into a third file.

code in p_9.sh file

echo "Enter two files name: "

read a

read b

cat $a>>intro

cat $b>>intro

echo "Concatation oF 2 files into 3rd file: "

cat intro

Output:-

Utsav Lankapati(2327010601077) 25
Operating System (2030106404) 4th Sem

Practical-10
Aim:- Write a shell script program to generate Fibonacci
numbers from 1 to N.
code in p_10.sh file:

echo "Enter how long you want to genrete series:"

read n

a=0

b=1

i=3

echo "Fabnoci series up to $n terms:"

echo $a

echo $b

while [ $i -le $n ]

do

c=`expr $a + $b`

echo $c

a=$b b=$c

i=`expr $i + 1`

done

Utsav Lankapati(2327010601077) 26
Operating System (2030106404) 4th Sem

Output:-

Utsav Lankapati(2327010601077) 27
Operating System (2030106404) 4th Sem

Practical-11
Aim:- Write a shell script program to read a character from a
user. Determine whether it is uppercase letter, lowercase letter
or digit.

Code in p_11.sh file:

echo "Enter a character:"

read c

if [[ ${#c} -ne 1 ]]; then

echo "Error: Please enter a single character only!"

exit 1

fi

if [[ "$c" =~ ^[A-Z]$ ]]; then

echo "uppercase"

elif [[ "$c" =~ ^[a-z]$ ]]; then

echo "lowercase"

elif [[ "$c" =~ ^[0-9]$ ]]; then

echo "digit"

else

echo "special character"

fi

Utsav Lankapati(2327010601077) 28
Operating System (2030106404) 4th Sem

Output:-

Utsav Lankapati(2327010601077) 29
Operating System (2030106404) 4th Sem

Practical-12
Aim:- Write a shell script program to find the sum of all the
individual digits in a given 5-digit number.

Code in p_12.sh file:

echo "Enter a number:"

read n

sum=0

while [ $n -gt 0 ]

do

mod=`expr $n % 10`

sum=`expr $sum + $mod`

n=`expr $n / 10`

done

echo "the Sum of the given number is : " $sum

Output:-

Utsav Lankapati(2327010601077) 30
Operating System (2030106404) 4th Sem

Practical-13
Aim:- Write a shell script program to check whether string is
palindrome or nt

P13.sh code:

echo "Enter a string:"

read str

rev=$(echo "$str" | rev)

if [ "$(echo "$str" | tr '[:upper:]' '[:lower:]')" = "$(echo "$rev" | tr '[:upper:]'


'[:lower:]')" ]; then

echo "$str is a palindrome."

else

echo "$str is not a palindrome."

fi

Output:-

Utsav Lankapati(2327010601077) 31
Operating System (2030106404) 4th Sem

Practical-14
Aim:- Write a shell script program to copy source file to
destination file.

Code in p_14.sh :

echo "Enter a source file name:"

read sf

echo "Enter the destination file name:"

read df

cp "$sf" "$df"

echo "Contents of the source file:"

cat "$sf"

Output:-

Utsav Lankapati(2327010601077) 32
Operating System (2030106404) 4th Sem

Practical-15
Aim:- Write a shell script program to generate a mark sheet.
Calculate grades of students also.

Code in p_15.sh

#!/bin/bash

echo "Students marks list"

echo "* * * * * * *"

echo "Enter the student's Name"

read name

echo "Enter the register number"

read reg_no

echo "Enter the marks of sub 1"

read sub1

echo "Enter the marks of sub 2"

read sub2

echo "Enter the marks of sub 3"

read sub3

echo "Enter the marks of sub 4"

read sub4

echo "Enter the marks of sub 5"

read sub5

# Calculate total marks

Utsav Lankapati(2327010601077) 33
Operating System (2030106404) 4th Sem

total=$((sub1 + sub2 + sub3 + sub4 + sub5))

# Calculate average as percentage (integer only)

avg=$(((total * 100) / 500))

echo "* * * * * * *"

echo "Marks List"

echo "* * * * * * *"

echo "Student's Name : $name"

echo "Register number : $reg_no"

echo "Sub 1 marks : $sub1"

echo "Sub 2 marks : $sub2"

echo "Sub 3 marks : $sub3"

echo "Sub 4 marks : $sub4"

echo "Sub 5 marks : $sub5"

echo "Total : $total"

echo "Average (%) : $avg"

# Grade Calculation

if [ "$avg" -ge 35 ]; then

echo "Result: Pass"

if [ "$avg" -ge 90 ]; then

echo "Grade: S"

elif [ "$avg" -ge 80 ]; then

echo "Grade: A"

elif [ "$avg" -ge 70 ]; then

Utsav Lankapati(2327010601077) 34
Operating System (2030106404) 4th Sem

echo "Grade: B"

elif [ "$avg" -ge 60 ]; then

echo "Grade: C"

elif [ "$avg" -ge 50 ]; then

echo "Grade: D"

else

echo "Grade: E"

fi

else

echo "Result: Fail"

fi

echo "* * * * * * *"

Utsav Lankapati(2327010601077) 35
Operating System (2030106404) 4th Sem

Output:-

Utsav Lankapati(2327010601077) 36

You might also like