Os Merged1
Os Merged1
SEMESTER : 4
SUBJECT NAME: OPERATING SYSTEM
SUBJECT CODE : 3140702
FACULTY NAME :PROF. FORAM PATEL
OPERATING SYSTEM
IMPORTANT QUESTIONS:
CHAPTER 1: INTRODUCTION
CHAPTER 3: CONCURRENCY
CHAPTER 5: DEADLOCK
be prevented?
1. Explain virtualization.
2. Explain virtual machine.
3. Explain types of virtualization.
OPERATING SYSTEM
SUBJECT CODE: 3140702
COMPUTER SCIENCE AND ENGINEERING
th
DEPARTMENT B.E. 4 SEMESTER
NAME:
ENROLLMENT NO:
BATCH NO:
YEAR:
CERTIFICATE
Date of Submission:-
commands:
- Show all.
A
- Omits line numbers for blank space in the output.
b
- A $ character will be printed at the end of each line prior to a
e new line.
- Displays a $ (dollar sign) at the end of each line.
E
- Line numbers for all the output lines.
n
-s If the output has multiple empty lines it replaces it with one
empty line.
- Displays the tab characters in the output.
T
- Non-printing characters (with the exception of tabs, new-lines
v and form-feeds) are printed visibly.
7) cmp:- It compares two files and tells you which line numbers are different.
Syntax : - cmp [options..] file1 file2
Description:-
Let’s create a file named os2. And use cmp command to compare os and os1files.
- Output differing bytes as characters.
c
- Print the byte number (decimal) and the differing byte values
l (octal) for each difference.
- Prints nothing for differing files, return exit status only.
s
- Output differing bytes as characters.
c
8) cp:- cp command copy files from one location to another. If the destination is an existing file,
then the file is overwritten; if the destination is an existing directory, the file is copied into the
directory (the directory is not overwritten).
Syntax: - cp [options]... source destination
Description:-
Here, after cp command contents of both source file and destination file files are the same.
It will copy the content of source file to destination file.
If the destination file doesn’t exist, it will be created.
If it exists then it will be overwritten without any warning.
If there is only one file to be copied then destination can be the ordinary file or the directory file.
-a archive files
-f force copy by removing the destination file if needed
-i interactive - ask before overwrite
-l link files instead of copy
-L follow symbolic links
-n no file overwrite
-u update - copy when source is newer than dest
9) bc:- bc command is used for command line calculator. It is similar to basic calculator. By
using which we can do basic mathematical calculations.
Syntax:bc[options]
Description:-
bc is a language that supports arbitrary precision numbers with interactive execution of
statements.
bc starts by processing code from all the files listed on the command line in the order listed. After
all files have been processed, bc reads from the standard input. All code is executed as it is read.
10) exit:Exit immediately after writing the last line of the last file in the argument list.
11) find:- Finds one or more files assuming that you know their approximate path.
Syntax :- find [options] path
Description :-
Find is one of the powerful utility of Unix (or Linux) used for searching the files in a directory
hierarchy
path A path name of a starting point in the directory
hierarchy
- Descend at most levels (a non-negative integer) levels
maxdepth of directories below the command line arguments.
-i ignore the case in the current directory and sub-
directories.
-size Find file based on size
12) ls:- Lists the contents of a directory
Syntax :- ls [options]
Description :-
- Shows you all files, even files that are hidden (these files
a begin with a dot.)
- List all files including the hidden files. However, does not
A display the working directory (.) or the parent directory (..).
- If an argument is a directory it only lists its name not its
d contents
-l Shows you huge amounts of information (permissions,
owners, size, and when last modified.)
- Displays a slash ( / ) in front of all directories
p
-r Reverses the order of how the files are displayed
- Includes the contents of subdirectories
R
13) man:- man command which is short for manual, provides in depth information about the
requested command (or) allows users to search for commands related to a particular keyword.
Syntax:- man commandname [options]
Description :-
-a Print a one-line help message and exit.
-k Searches for keywords in all of the manuals available.
14) mkdir:- This command is used to create a new directory
Syntax :- mkdir [options] directory
Description :-
16) ps:- It is used to report the process status. ps is the short name for Process Status.
Syntax:- ps [options]
Description :-
- List information about all processes most frequently
a requested: all those except process group leaders and
processes not associated with a terminal
- List information for all processes. Identical to -e, below
A
-f Generate a full listing
-j Print session ID and process group ID
-l Generate a long listing
17) pwd:-Displaying your current directory name (Print working directory).
Syntax:-pwd [options]
Description:-
At the time of logging in user is placed in the specific directory of the file system. You can move
around from one directory to another, but any point of time, you are located in only one directory.
This directory is known as your current directory.
pwd command tells your current directory.
18) rmdir:- It is used to delete/remove a directory and its subdirectories.
Syntax :- rmdir [options..] Directory
Description :-
It removes only empty directory.
Example :-
$ rm myfile.txt
Remove the file myfile.txt. If the file is write-protected, you will be prompted to confirm that you
really want to delete it.
$ rm *
Remove all files in the working directory. If it is write-protected, you will be prompted before rm
removes it.
$ rm -f myfile.txt
Remove the file myfile.txt. You will not be prompted, even if the file is writeprotected; if rm can
delete the file, it will.
$ rm -f *
Remove all files in the working directory. rm will not prompt you for any reason before deleting
them.
$ rm -i *
Attempt to remove every file in the working directory, but prompt before each file to confirm.
20) sleep:- Delay for a specified amount of time
Syntax :- sleep NUMBER[SUFFIX]
Description:-
The sleep command pauses for an amount of time defined by NUMBER.
SUFFIX may be "s" for seconds (the default), "m" for minutes, "h" for hours, or "d" for
days.14.ed:
21) wc:- Word Count (wc) command counts and displays the number of lines, words, character
and number of bytes enclosed in a file.
Syntax: - wc [options] [filename]
Description:-
This command counts lines, words and characters depending on the options used. It takes one or
more filenames as its arguments and displays four-columnar output. For example let’s read our
os1 file. And we use wc command with that filename.
-l print the newline counts.
-w print the word counts.
-c print the byte counts.
-m print the character counts.
-L print the length of the longest line.
22) finger:- finger command displays the user's login name, real name, terminal name and write
status (as a ''*'' after the terminal name if write permission is denied), idle time, login time, office
location and office phone number.
Syntax:- finger [username]
Description :-
-l Force long output format
-s Force short output format
PRACTICAL – 2
AIM : Write a shell script to generate marksheet of a student. Take 3
subjects, calculate and display total marks, percentage and Class
obtained by the student.
echo " Enter name "
read name
echo " Enter enrollment number "
read no
echo " Enter your marks "
read m1
read m2
read m3
total=$(expr $m1 + $m2 + $m3 )
avg=$(expr $total / 3)
echo "Student Name : $name"
echo "EnrollMent NUmber: $no"
echo "Average is : $avg"
if [ $m1 -ge 35 ] && [ $m2 -ge 35 ] && [ $m3 -ge 35 ]
then
echo "Result is: Pass"
if [ $avg -ge 80 ] && [ $avg -le 100 ]
then
echo "Result is: Distinction"
elif [ $avg -ge 61 ] && [ $avg -le 79 ]
then
echo "Result is: First class"
elif [ $avg -ge 35 ] && [ $avg -le 60 ]
then
echo "Result is: Second class"
fi
else
echo "Result is: fail"
fi
O/P :
Enter name
DJ
Enter enrollment number
13
Enter your marks
89
90
98
Average is : 92
Result is: Distinction
PRACTICAL – 3
AIM : Write a shell script to find factorial of given number n.
echo "Enter the number to find factorial?"
read number
fact=1
while [ $number -gt 0 ]
do
fact=`expr $number \* $fact`
number=`expr $number - 1`
done
echo "factorial is : $fact"
O/P:
Enter a number
24
PRACTICAL – 4
AIM : Write a shell script which will generate first n fibonnacci numbers
like: 1, 1, 2, 3, 5
N=6
a=0
b=1
Output:
echo “ MENU
a. . Display calendar of current month
b. . Display today’s date and time
c. . Display usernames those are currently logged in the system
d. . Display your terminal number
e. . Exit
Read i
Case “$i” in
1) cal ;;
2) date ;;
3) who;;
4) tty ;;
5) exit ;;
*) echo “enter valid in put” ;;
esac
Output:
Output:
Number is palindrome
PRACTICAL – 7
AIM : Write a shell script which will accept a number b and display
first n prime numbers as output.
prime_1=0
echo "enter the range"
read n
echo " Primenumber between 1 to $n is:"
echo "1"
echo "2"
for((i=3;i<=n;))
do
for((j=i-1;j>=2;))
do
if [ `expr $i % $j` -ne 0 ] ; then
prime_1=1
else
prime_1=0
break
fi
j=`expr $j - 1`
done
if [ $prime_1 -eq 1 ] ; then
echo $i
fi
i=`expr $i + 1`
done
Output:
clear
echo -----------------------------------
echo '\tMultiplication Table'
echo -----------------------------------
echo Enter table number
read tn
echo Enter how many rows
read n
i=1
while [ $i -le $n ]
do
k=$(expr $i \* $tn)
echo "$i * $tn = $k"
i=$(expr $i + 1)
done
Output:
Global
A globally scoped ENV that is defined in a terminal can be accessed from anywhere in that
particular environment which exists in the terminal. That means it can be used in all kind of scripts,
programs or processes running in the environment bound by that terminal.
Local
A locally scoped ENV that is defined in a terminal cannot be accessed by any program or process
running in the terminal. It can only be accessed by the terminal( in which it was defined) itself.
Variable Description
Syntax:
2. cut
Syntax:
The 'cut' command is useful in selecting a specific column of a file. After (-d), delimiter (from
where you want to separate the columns) comes. Delimiters can be a space (' '), a hyphen (-), a slash
(/) or anything else. After (-f), column number is mentioned.
Syntax:
3. grep
Syntax:
The 'comm' command compares two files or streams. By default, 'comm' will always display three
columns. First column indicates non-matching items of first file, second column indicates non-
matching items of second file, and third column indicates matching items of both the files. Both the
files has to be in sorted order for 'comm' command to be executed.
Syntax:
5. sed
Command 'sed' stands for stream editor. You can use this command to edit streams (files) using
regular expressions. But this editing is not permanent. It remains only in display, but in actual, file
content remains same.
Syntax:
6. tee
The 'tee' command is similar to 'cat' command with only one difference. It puts stdin on stdout and
also put them into a file.
Syntax:
7. tr
The command 'tr' stands for 'translate'. It is used to translate, like from lowercase to uppercase and
vice versa or new lines into spaces.
Syntax:
8. uniq
With the help of uniq command you can form a sorted list in which every word will occur only
once.
Syntax:
9. wc
The 'wc' command helps in counting the lines, words and characters in a file.
Syntax:
The 'od' term stands for octal dump. It displays content of a file in different human-readable formats
like hexadecimal, octal and ASCII characters.
Syntax:
Marks
Q.1 (a) Explain any three main functions of an Operating System. 03
(b) Describe the features of a distributed operating system. 04
(c) What is a process? Explain about various fields of process control block. 07
Q.3 (a) What are the advantages of inter-process communication? How communication 03
takes place in a shared-memory environment?
(b) What are the conditions under which a deadlock situation may arise? 04
(c) Explain the readers and writers problem. 07
OR
Q.3 (a) What is race condition? 03
(b) What are the methods for handling deadlocks? 04
(c) Explain the dining-philosophers problem. 07
Q.4 (a) Explain the difference between logical and physical addresses. 03
(b) When do page faults occur? Describe the actions taken by the operating system 04
when a page fault occurs.
(c) Explain Banker's deadlock-avoidance algorithm with an illustration. 07
OR
Q.4 (a) Explain the following allocation algorithms: 03
1) First-fit 2) Best-fit 3) Worst-fit
(b) Explain the difference between internal and external fragmentation. 04
(c) Explain the different file access methods in detail. 07
Marks
Q.1 (a) List any four functions of operating system? 03
(b) Explain the essential properties of 04
i) Batch system ii) Time sharing
iii) Real time iv) Distribute
(c) Explain process states and process control block in details. 07
Q.2 (a) What are the various criteria for a good process scheduling algorithm? 03
(b) What is thread? Explain classical thread model. 04
(c) How semaphores can be used to deal with n-process critical section 07
problem? Explain.
OR
(c) What is monitor? Explain solution for producer-consumer problem using 07
monitor.
2
Seat No.: ________ Enrolment No.___________
Q.1 (a) Define the essential properties of the following types of operating systems: 03
(1) Batch (2) Time-sharing (3) Real-time
(b) What are the advantages of multiprogramming? 04
(c) What is the thread? What are the difference between user-level threads and kernel- 07
supported threads? Under what circumstances is one type “better” than the other?
Q.2 (a) What is Process? Give the difference between a process and a program. 03
(b) What is Process State? Explain different states of a process with various queues 04
generated at each stage.
(c) Write a bounded-buffer monitor in which the buffers (portions) are embedded within 07
the monitor itself.
OR
(c) What is Semaphore? Give the implementation of Readers-Writers Problem using 07
Semaphore.
Q.3 (a) Define the difference between preemptive and nonpreemptive scheduling. 03
(b) What are the Allocation Methods of a Disk Space? 04
(c) What is deadlock? Explain deadlock prevention in detail. 07
OR
Q.3 (a) What are the disadvantages of FCFS scheduling algorithm as compared to shortest 03
job first (SJF) scheduling?
(b) Distinguish between CPU bounded, I/O bounded processes. 04
(c) What is deadlock? Explain deadlock Avoidance in detail. 07
Q.4 (a) What is Access control? 03
(b) What are Pages and Frames? What is the basic method of Segmentation? 04
(c) Briefly explain and compare, fixed and dynamic memory partitioning schemes. 07
OR
Q.4 (a) Explain difference between Security and Protection? 03
(b) Differentiate external fragmentation with internal fragmentation. 04
(c) Explain the best fit, first fit and worst fit algorithm. 07
1
Seat No.: ________ Enrolment No.___________
Marks
Q.3 (a) Give the difference between weak semaphore and strong semaphore. 03
(b) Briefly explain critical section. 04
(c) Explain producer-consumer problem and solve it using semaphore. 07
Write pseudo code for the same.
OR
Q.3 (a) Give the key difference between a mutex and a binary semaphore. 03
(b) List the requirements for mutual exclusion. 04
(c) Explain Dining philosopher problem and its solution using semaphore. 07
1
Q.5 (a) Explain concept of thrashing. 03
(b) Given the following track requests in the disk 04
queue, compute for the Total Head Movement
(THM) of the read/write head and seek time needed for SSTF Disk
Scheduling approach:
86, 147, 91, 230, 94, 168, 270, 30
Consider that the read/write head is positioned at location 150. A seek
takes 3 ms per cylinder move. Consider a disk drive with 300 cylinders.
(c) Explain any three memory placement algorithms with suitable example. 07
OR
Q.5 (a) Compare and contrast paging with fragmentation. 03
(b) Given the following track requests in the disk 04
queue, compute for the Total Head Movement
(THM) of the read/write head and seek time needed for C-SCAN Disk
Scheduling approach:
95, 180, 34, 119, 11, 123, 62, 64
Consider that the read/write head is positioned at location 50. A seek
takes 5 ms per cylinder move. Consider a disk drive with 200 cylinders.
(c) Explain any three page replacement algorithms with suitable example. 07
*******
2
Seat No.: ________ Enrolment No.___________
(c) Draw the block diagram for DMA. Write steps for DMA data transfer. 07
OR
Q.5 (a) Differentiate block and character devices. 03
(b) Explain following Unix command: grep, sort, chmod, mkdir. 04
(c) Write short note on RAID levels. 07
*************
1
Seat No.: ________ Enrolment No.___________
*************
2
Seat No.: ________ Enrolment No.___________
1
(c) Explain producer-consumer problem and solve it using semaphore. 07
Write pseudo code for the same.