Professional Documents
Culture Documents
OS LAB Manual 2018-2019 Wihtout Program
OS LAB Manual 2018-2019 Wihtout Program
1
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
command prompt commands can be issued to perform file and disk management
and to run program. Results of these commands are presented to the user as text
message.
C:\>-The command prompt can be an alphabet followed by one colon (:), one
back slash (\), one greater than sign (>) and one blinking element called cursor
(_).
2
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
3
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Aim:
To Understand the basic commands of UNIX operating system.
Description:
Unix is a family of multitasking, multiuser computer operating systems that derive
from the original AT&T . Unix was designed to be portable, multi-tasking and multi-
user in a time-sharing configuration. Unix systems are characterized by various
concepts: the use of plain text for storing data; a hierarchical file system; treating
devices and certain types of inter-process communication (IPC) as files; and the use of
a large number of software tools, small programs that can be strung together through
a command-line interpreter using pipes, as opposed to using a single monolithic
program that includes all of the same functionality. The Unix Programming
Environment as "the idea that the power of a system comes more from the
relationships among programs than from the programs themselves. Unix, the operating
system consists of many utilities along with the master control program, the kernel.
The kernel provides services to start and stop programs, handles the file system and
other common "low-level" tasks that most programs share, and schedules access to
avoid conflicts when programs try to access the same resource or device
simultaneously. To mediate such access, the kernel has special rights, reflected in the
division between user space and kernel space. The microkernel concept was
introduced in an effort to reverse the trend towards larger kernels and return to a
system in which most tasks were completed by smaller utilities.
I. Basic Commands:
1. Echo Command :
This command is used to print the arguments on the screen .
Syntax : $echo <text>
Multi line echo command :
To have the output in the same line , the following commands can be
used.
Syntax : $echo <text\>text
To have the output in different line, the following command can be used.
Syntax : $echo “text
>line2
>line3”
2. ’who’ Command :
It is used to display who are the users connected to our computer
currently.
Syntax : $who – option’s
Options : -
H–Display the output with headers.
b–Display the last booting date or time or when the system was lastly
rebooted.
3. ’who am i’ Command :
Display the details of the current working directory.
Syntax : $who am i
4. ’tty’ Command :
It will display the terminal name.
4
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Syntax : $tty
5. ’Binary’ Calculator Command :
It will change the „$‟ mode and in the new mode, arithmetic operations
such as +,-,*,/,%,n,sqrt(),length(),=, etc can be performed . This
command is used to go to the binary calculus mode.
Syntax :
$bc operations
^d
$
1 base –inputbase
0 base – outputbase are used for base conversions.
Base :
Decimal = 1 Binary = 2 Octal = 8 Hexa = 16
5
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
8. WORD Command :
To list the content count of no of lines , words, characters .
Syntax :
$wc<filename>
Options :
-c – to display no of characters.
-l – to display only the lines.
-w – to display the no of words.
9. LIST Command :
It is used to list all the contents in the current working directory.
Syntax : $ ls – options <arguments>
If the command does not contain any argument means it is working in the
Current directory.
Options :
a– used to list all the files including the hidden files.
c– list all the files columnwise.
d- list all the directories.
m- list the files separated by commas.
p- list files include „/‟ to all the directories.
r- list the files in reverse alphabetical order.
f- list the files based on the list modification date.
x-list in column wise sorted order.
6
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
7
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
3.PAGE : This command shows the page by page a screen full of information is
displayed after which the page command displays a prompt and passes for the
user to strike the enter key to continue scrolling.
Syntax: $ls –a\p
4. MORE : It also displays the file page by page .To continue scrolling with
more command , press the space bar key.
Syntax: $more<filename>
5.PIPE : It is a mechanism by which the output of one command can be
channeled into the input of another command.
Syntax: $who | wc-l
Description:
- grep command searches the given file for lines containing a match to the given
strings or words. By default, grep prints the matching lines. Use grep to search for
lines of text that match one or many regular expressions, and outputs only the
matching lines. The name, "grep", derives from the command used to perform a
similar operation, using the Unix/Linux text editor ed:
g/re/p
Syntax
grep 'word' filename
grep 'string1 string2' filename
cat otherfile | grep 'something'
command | grep 'something'
8
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
MODES:
a) ABSOLUTE MODE:
SYNTAX: $chmod <octal representation> filename
DESCRIPTION: This mode uses number to alter permissions for a file or for
all the users.
OCTAL MEANING
4 Read permissions
2 Write
1 Execute
0 No permissions
Eg: $chmod 644 file.c
DESCRIPTION: Read and write to owner and read to groups and others.
b) SYMBOLIC MODE:
SYNTAX: $chmod <type of user><operation><access permission> filename
DESCRIPTION: This mode uses letters to alter permissions for a file and for
all users.
DESCRIPTION :
The Vi editor is a visual editor used to create and edit text, files,
documents and programs. It displays the content of files on the screen and allows
a user to add, delete or change part of text . There are three modes available in
the Vi editor , they are
1.Command mode
2.Input (or) insert mode.
9
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
I.Starting Vi :
The Vi editor is invoked by giving the following commands in UNIX
prompt.
Syntax : $vi <filename> (or)
$vi
This command would open a display screen with 25 lines and with tilt (~)
symbol at the start of each line. The first syntax would save the file in the
filename mentioned and for the next the filename must be mentioned at the end.
Options :
1.vi +n <filename> - this would point at the nth line (cursor pos).
2.vi –n <filename> - This command is to make the file to read only to
change from one mode to another press escape key.
10
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Syntax :
<ESC> 0
9.<ESC> $ :
This command will bring the cursor to the end of the current line.
Syntax :
<ESC> $
10.<ESC> ^ :
This command is used to move to first character of first lines.
Syntax :
<ESC> ^
11.<ESC> b Command :
This command is used to move back to the previous word (or) a number
of words.
Syntax :
<ESC> b <ESC>nb
12.<ESC> e Command :
This command is used to move towards and replace the cursor at last
character of the word (or) no of words.
Syntax :
<ESC> e <ESC>ne
13.<ESC> w Command :
This command is used to move forward by a single word or a group of
words.
Syntax :
<ESC> w <ESC> nw
III. DELETING THE TEXT FROM Vi :
1.<ESC> x Command :
To delete a character to right of current cursor positions , this command
is used.
Syntax :
<ESC> x <ESC> nx
2.<ESC> X Command :
To delete a character to left of current cursor positions , this command is
used.
Syntax :
<ESC> X <ESC> nX
3.<ESC> dw Command :
This command is to delete a single word or number of words to right of
current cursor position.
Syntax :
<ESC> dw <ESC> ndw
4.db Command :
This command is to delete a single word to the left of the current cursor
position.
Syntax :
<ESC> db <ESC> ndb
5.<ESC> dd Command :
This command is used to delete the current line (or) a number of line
below the current line.
Syntax :
11
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Result:
Thus the basic commands of UNIX operating system has been successfully
practiced.
VIVA QUESTIONS
1. What is UNIX?
2. What are filters?
3. What is Kernel?
4. What is an operating system?
5. List the types of operating system?
6. Give some example os for wireless devices.
7. What is a bootstrap program?
8. What is BIOS?
9. What are system calls?
10. How to open a file in read only mode in vi editor?
12
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
AIM:
To write a program for implementing Directory management using the following
system calls of UNIX operating system: opendir, readdir.
ALGORITHM:
1. Start the program.
2. Read the input from the command line.
3. Declare the pid and get the pid by using the getpid() method. execlp() system
call used to execute specified command.
4. Create a child process by calling the fork() system call.Open the directory at
specified in command line input.
5. Check if(pid==0) then print the child process id and if(pid==1) then print the
parent process value. Otherwise print fork failed.
6. Check if pid==0 then execute the ‘ls’ command and display the list of files and
dir.
7. Stop the program.
OUTPUT:
before fork 4258
thisline from child,
the child process id 4259
a.out
ch.c
come.c
data
file1.c
file2.c
first.c
fit.c
sysytem.c
before fork 4258
RESULT:
Thus the process system call program was executed and verified successfully.
AIM:
ALGORITHM:
13
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
OUTPUT:
NAME OF ITEM
pri_output.doc
sjf_output.doc
fcfs_output.doc
rr_output.doc
ipc_pipe_output.doc
pro_con_prob_output.doc
TOTAL NUMBER OF ITEM IN THAT DIRECTORY IS 8
RESULT:
Thus the program for directory management was written and successfully
executed.
VIVA QUESTIONS
14
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
EX NO:3 Write a programs to simulate UNIX commands like ls, grep, etc.
AIM:
To write a program to simulate UNIX commands like ls, grep, etc.
ALGORITHM:
1. Start the program.
2. Read the input through command line.
3. Open the specified file.
4. Options (c & i) are performed.
5. Stop the program.
OUTPUT:
[root@localhost ~]# cat tst sd
dsaASD[root@localhost ~]# ./a.out -i a tst
aA[root@localhost ~]# ./a.out -c a tst 1[root@localhost ~]# ./a.out -c A tst
1[root@localhost ~]# ./a.out -c sd tst 1[root@localhost ~]# ./a.out -c s tst 2
RESULT:
Thus the program to stimulate the UNIX commands was written and successfully
executed.
VIVA QUESTIONS
15
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Aim:
Write the shell program to compare two strings, to find the greatest of three
numbers, Fibonacci series and to perform the arithmetic operations using switch
case.
Description:
A Shell offers a user an interface with the OS kernel. A user obtains OS services
through an OS shell. When a user logs in, he has a login shell. The login shell offers
the first interface that the user interacts with either as a terminal console, or through a
window interface which emulates a terminal. A shell is essentially a process which is a
command interpreter. Every Unix shell offers two key facilities. In addition to an
interactive command interpreter, it also offers a very useful programming
environment. The shell programming environment accepts programs written in shell
programming language. In later sections in this chapter we shall learn about the shell
programming language and how to make use of it for enhancing productivity. A user
obtains maximum gains when he learns not only to automate a sequence of commands
but also to make choices within command sequences and invoke repeated executions.
Aim:
To write a shell program to compare two strings.
Algorithm:
1. Start the program
2. Enter into the vi editor and go to the insert mode for entering the code.
3. Read the first string.
4. Read the second string .
5. Compare the two strings using the if loop
6. If the condition satisfies then print that two strings are equal else print two
strings are not equal.
16
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Sample I/P: 1
Enter first string: hai
Enter second string: hai
Sample O/P:1
The two strings are equal
Sample I/P:2
Enter first string: hai
Enter second string: cse
Sample O/P:2
The two strings are not equal
Result:
Thus the shell program to compare the two strings has been executed and output is
verified successfully.
Algorithm:
1. Start the program
2. Enter into the vi editor and go to the insert mode for entering the code.
3. Read three variables A,B,C.
4. Check if A is greater than B and C.
5. If so print A is greater.
6. Else check if B is greater than C.
7. If so print B is greater.
8. Else print C is greater.
9. Save and exit from the vi editor by using ‘:wq!’
10. Execute the program by ./filename.sh.
11. Stop the program.
Sample I/P:
Enter A:23
Enter B:45
Enter C:67
Sample O/P: C is greater
Result:
Thus the shell program to find the maximum of three numbers has been executed
and output is verified successfully.
Algorithm :
17
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Sample I/P :
Enter the no: 5
Sample O/P:
0
1
1
2
3
5
Result :
Thus the shell program to find the Fibonacci series has been executed and
output is verified successfully.
Sample I/P :
1.Addition
2.Subraction
3.Multiplication
4.Division
Enter your choice:1
Enter the value of b:3
Enter the value of c:4
18
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
b is 3 c is 4
the sum is 7
Sample O/P:
b is 3 c is 4
the sum is 7
Result :
Thus the shell program to perform arithmetic operations using switch case has
been executed and the output is verified successfully.
VIVA QUESTIONS
1. What is shell programming?
2. What are shell variables?
3. What is Bash Shell?
4. What is a superuser?
5. Is UNIX open source?
6. Which language is used in the design of UNIX OS?
7. Which command can be used to alter the file access permissions?
8. Which command can be used to delete a shell variable?
9. Which shell variable holds the shell script file name?
10. Is it compulsory to have the extension ‘sh’ for a shell script?
19
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
20
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Amount of time it takes from when a request was submitted until the first
response is produced. Remember, it is the time till the first response and not
the completion of process execution(final response).
Shortest-Job-First(SJF) Scheduling
Shortest job first (SJF) or shortest job next, is a scheduling policy that selects
the waiting process with the smallest execution time to execute next. SJN is a
non-preemptive algorithm.
21
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Priority Scheduling
Priority is assigned for each process.
Process with highest priority is executed first and so on.
Processes with same priority are executed in FCFS manner.
Priority can be decided based on memory requirements, time requirements or
any other resource requirement.
Algorithm
1. Start the program.
2.Accept the number of processes in the ready Queue and time quantum (or)
time slice
3.For each process in the ready Q, assign the process id and accept the CPU
burst time
4.Calculate the no. of time slices for each process where
No. of time slice for process(n) = burst time process(n)/time slice
5.If the burst time is less than the time slice then the no. of time slices =1.
6. Consider the ready queue is a circular Q, calculate
22
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
OUTPUT:
Enter the number of Processors
4
Enter Arrival Time and Burst Time for Process Process Number 1: 0
9
Enter Arrival Time and Burst Time for Process Process Number 2: 1
5
Enter Arrival Time and Burst Time for Process Process Number 3: 2
3
Enter Arrival Time and Burst Time for Process Process Number 4: 3
4
Enter the quantum
5
P[ 2] 9 4
P[3] 10 8
P[4] 14 10
P[1] 21 12
Aim:
Write a C program to implement the Shortest Job First (SJF)CPU
scheduling algorithm to find turnaround time and waiting time.
23
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Algorithm:
1.Start the program
2.Accept the number of processes in the ready Queue. Assume that all process
arrive at same time.
3.For each process in the ready Q, assign the process id and accept the CPU
burst time
4. Start the Ready Q according the shortest Burst time by sorting according to
lowest to highest burst time.
5. Set the waiting time of the first process as ‘0’ and its turnaround time as its
burst time.
6. For each process in the ready queue, calculate
(a) Waiting time for process(n)= waiting time of process (n-1) + Burst
time of process(n-1)
(b) Turn around time for Process(n)= waiting time of Process(n)+ Burst
time for process(n)
7.Calculate
(c) Average waiting time = Total waiting Time / Number of process
(d) Average Turnaround time = Total Turnaround Time / Number of
process
8.Stop the program.
OUTPUT:
Enter number of process 3
1 3 0 3
0 4 3 7
2 5 7 12
Algorithm:
1.Start the program
24
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
2. Accept the number of processes in the ready Queue. Assume that all process
arrive at same time.
3. For each process in the ready Q, assign the process id and accept the CPU
burst time
4. Set the waiting of the first process as ‘0’ and its burst time as its turn around
time
5. for each process in the Ready Q calculate
(c) Waiting time for process(n)= waiting time of process (n-1) + Burst
time of process(n-1)
(d) Turn around time for Process(n)= waiting time of Process(n)+ Burst
time for process(n)
6. Calculate
(e) Average waiting time = Total waiting Time / Number of process
(f) Average Turnaround time = Total Turnaround Time / Number of
process
7. Stop the program.
OUTPUT:
2 2 7
3 7 11
25
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
OUTPUT:
-----------PRIORITY SCHEDULING--------------
Enter the No of Process: 4
Enter the Burst time of Pid 0 : 2
Enter the Priority of Pid 0 : 3
Enter the Burst time of Pid 1 : 6
Enter the Priority of Pid 1 : 2
Enter the Burst time of Pid 2 : 4
Enter the Priority of Pid 2 : 1
Enter the Burst time of Pid 3 : 5
Enter the Priority of Pid 3 : 7
----------------------------------------------------------------------------------------
Pid Priority Burst time WaitingTime TurnArroundTime
----------------------------------------------------------------------------------------
2 1 4 0 4
1 2 6 4 10
0 3 2 10 12
3 7 5 12 17
Result :
Thus the C program to implement Priority scheduling was written and
waiting time and turnaround time was calculated successfully.
VIVA QUESTIONS
1. What is First-Come-First-Served (FCFS) Scheduling?
2. Why CPU scheduling is required?
3.Which technique was introduced because a single job could not keep both the
CPU and the I/O devices busy?
a) Time-sharing b) SPOOLing c) Preemptive scheduling d) Multiprogramming
4. CPU performance is measured through ________.
a) Throughput b) MHz c) Flaps d) None of the above
5. Which of the following is a criterion to evaluate a scheduling algorithm?
a)CPU Utilization: Keep CPU utilization as high as possible.
26
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
27
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
AIM:
Write a C program to implement producer/consumer problem using semaphore.
Description:
A semaphore is a data structure used to help threads work together without
interfering with each other. Mutual exclusion on the semaphore is enforced
within P(S) and V(S). If a number of processes attempt P(S) simultaneously,
only one process will be allowed to proceed & the other processes will be
waiting.
P(S) or wait(S):
If S > 0 then
Set S to S-1
Else
Block the calling process (i.e. Wait on S)
V(S) or signal(S):
If any processes are waiting on S
Start one of these processes
Else
Set S to S+1
Semaphores are of two types −
1. Binary semaphore
2. Counting semaphore
Binary semaphore can take the value 0 & 1 only. Counting semaphore can take
nonnegative integer values.
Producer consumer problem
Producer consumer problem is also known as bounded buffer problem. In this
problem we have two processes, producer and consumer, who share a fixed size
buffer. Producer work is to produce data or items and put in buffer. Consumer
work is to remove data from buffer and consume it. We have to make sure that
producer do not produce data when buffer is full and consumer do not remove
data when buffer is empty.
Algorithm:
1. Start the program.
2. Define producer() and consumer() and declare the variables
mutex=1,full=0,empty=3
3. Read the value for switch case to decide the operation.
4. If mutex=1 & empty!=0, the producer posts to the empty buffer semaphore.
5. This will increment its value, and if it were 0 it would wake up consumer threads
waiting on that semaphore.
6. The consumer thread that waits on that semaphore, upon waking up it will
decrement the value of the semaphore.
7. The empty buffer semaphore basically follows up with the buffer index.
8. The full buffer semaphore does the opposite.
9. The Consumer threads post to it when they dequeue from the buffer, which
increments the semaphore value.
28
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
10.The producer threads wait in them, which means they sleep if buffer is full, and
decrement the semaphore value each time they add element to buffer.
11.A mutex is used to protect access to buffer.
12. Stop the program.
Output:
1.Producer
2.Consumer
3.Exit
Enter your choice:1
Producer produces the item 1
Enter your choice:2
Consumer consumes item 1
Enter your choice:2
Buffer is empty!!
Enter your choice:1
Producer produces the item 1
Enter your choice:1
Producer produces the item 2
Enter your choice:1
Producer produces the item 3
Enter your choice:1
Buffer is full!!
Enter your choice:3
Result:
Thus the C program to implement producer consumer problem using
semaphore has been executed and verified successfully.
VIVA QUESTIONS
1. What is a semaphore?
2. What are the kinds of semaphore?
3. What integer values a binary semaphore has?
4. Semaphores are mostly used to implement :
a)System calls
b) IPC mechanisms
c) System protection
d) None of the mentioned
5. Spinlocks are intended to provide __________ only.
a) Mutual Exclusion
b) Bounded Waiting
c) Aging
d) Progress
6. What is mutex?
7. What is the difference between mutex and semaphore?
8. Are binary semaphore and mutex same?
9. What is a mutex and critical section?
10. Can a mutex be locked more than once?
29
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
FIFO(NAMED PIPES):
The solution to problem in pipes is given by means of named pipes. The
communication can be done between unrelated processes. It can be bi-
directional as well. One more difference between pipes and named pipes is that
the capacity of data that is the amount of data flow through a pipe during
execution.
SHARED MEMORY:
As the name implies, the same area of the physical memory is shared by one or
more processes. This memory segment is mapped into virtual memory spaces.
In shared memory two or more process can access the same memory segment.
Consider there are three process p1, p2 and p3. Processes p1 and p2 are
accessing the segment in read mode, and p3 in write mode. If p3 makes any
changes to the data, then it is automatically updated for the process p1 and p2
also.
The advantage of shared memory is Shared memory provides fastest
mechanism of communication than the others. The process can read or write
without using any system call.
The disadvantage of shared memory is it does not benefit from the protection
that the operating system normally provides.
MESSAGE QUEUE:
The message queue also provides the way for unrelated processes to
communicate with each other. Comparing with other IPC mechanisms this
provides the easiest way of communication than others. Instead of sending data
one by one, it sends block of data. This is the difference between the pipes and
message queue. The difference between message queue and named pipes is that
the messages in the queue can be prioritized which cannot be done in the later.
As message queues are attached with the kernel, whenever a message is sent or
received it has to visit the kernel, which makes the communication slow.
Because of this, the communication process is little bit slower than the shared
memory.
30
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
SEMAPHORE:
In a multi-user or multiprocessing systems, there is a problem to have an exclusive
access over the shared resource. But it is difficult to write code to ensure the exclusive
access to a particular resource.
Algorithm:
1.Start the program.
2. In terminal change directory using : cd /home/exam1/Tc
3. Four child process were created under the parent process IPC.C
4. Communication between child Process is established through pipe.
5.Create a text file before executing IPC program using cat >filename
6.Command to compile : g++ filename.c -o filename
7.Command to execute: ./filename textfilname
8.Stop the program.
Output:
WORD COUNT: 8
CHARACTER COUNT: 67
SENTENCE COUNT : 0
LINE COUNT: 5
Result:
Thus the Inter process communication using shared memory has been
implemented successfully and the output was verified.
VIVA QUESTIONS
1. What is IPC?
2. List out the IPC techniques.
3. What is shared memory?
4. List the advantages and disadvantages of shared memory.
5. List the advantages and disadvantages of pipes.
6. List the advantages and disadvantages of message queue.
7. List the advantages and disadvantages of semaphore
8. List the advantages and disadvantages of named pipes.
9. The link between two processes P and Q to send and receive messages is
called :
a) communication link
b) message-passing link
c) synchronization link
10. In indirect communication between processes P and Q :
a) there is another process R to handle and pass on the messages between
P and Q
b) there is another machine between the two processes to help
communication
c) there is a mailbox to help communication between P and Q
31
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Aim:
Write a C program to implement deadlock avoidance & Prevention by
using Banker’s Algorithm.
Description:
Banker’s Algorithm
When a new process enters a system, it must declare the maximum
number of instances of each resource type it needed. This number may exceed
the total number of resources in the system. When the user request a set of
resources, the system must determine whether the allocation of each resources
will leave the system in safe state. If it will the resources are allocation;
otherwise the process must wait until some other process release the resources.
Data structures
n-Number of process, m-number of resource types.
Available: Available[j]=k, k – instance of resource type Rj is available.
Max: If max[i, j]=k, Pi may request at most k instances resource Rj.
Allocation: If Allocation [i, j]=k, Pi allocated to k instances of resource
Rj
Need: If Need[I, j]=k, Pi may need k more instances of resource type Rj,
Need[I, j]=Max[I, j]-Allocation[I, j];
Safety Algorithm
1. Work and Finish be the vector of length m and n respectively,
Work=Available and Finish[i] =False.
2. Find an i such that both
Finish[i] =False
Need<=Work
If no such I exists go to step 4.
3. work=work+Allocation, Finish[i] =True;
4. if Finish[1]=True for all I, then the system is in safe state.
ALGORITHM:
1. Start the program.
32
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
2. Get the number of processes and values of resources needed for each
process.
3. Get the available value of resources.
4. After allocation find the need value.
5. Check whether its possible to allocate.
6. If it is possible then the system is in safe state.
7. Else system is not in safety state.
8. If the new request comes then check that the system is in safety.
9. Stop the program.
OUTPUT:
//TEST CASE 1:
ENTER THE NO. OF PROCESSES:4
ENTER THE NO. OF RESOURCES:3
PROCESS 1
MAXIMUM VALUE FOR RESOURCE 1:3
MAXIMUM VALUE FOR RESOURCE 2:2
MAXIMUM VALUE FOR RESOURCE 3:2
ALLOCATED FROM RESOURCE 1:1
ALLOCATED FROM RESOURCE 2:0
ALLOCATED FROM RESOURCE 3:0
PROCESS 2
MAXIMUM VALUE FOR RESOURCE 1:6
MAXIMUM VALUE FOR RESOURCE 2:1
MAXIMUM VALUE FOR RESOURCE 3:3
ALLOCATED FROM RESOURCE 1:5
ALLOCATED FROM RESOURCE 2:1
ALLOCATED FROM RESOURCE 3:1
PROCESS 3
MAXIMUM VALUE FOR RESOURCE 1:3
MAXIMUM VALUE FOR RESOURCE 2:1
MAXIMUM VALUE FOR RESOURCE 3:4
ALLOCATED FROM RESOURCE 1:2
ALLOCATED FROM RESOURCE 2:1
ALLOCATED FROM RESOURCE 3:1
PROCESS 4
MAXIMUM VALUE FOR RESOURCE 1:4
MAXIMUM VALUE FOR RESOURCE 2:2
MAXIMUM VALUE FOR RESOURCE 3:2
ALLOCATED FROM RESOURCE 1:0
ALLOCATED FROM RESOURCE 2:0
ALLOCATED FROM RESOURCE 3:2
ENTER TOTAL VALUE OF RESOURCE 1:9
ENTER TOTAL VALUE OF RESOURCE 2:3
ENTER TOTAL VALUE OF RESOURCE 3:6
33
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Result:
Thus the C program to implement deadlock avoidance and Prevention
by using Banker’s Algorithm was executed and the output is verified
successfully.
VIVA QUESTIONS
1. What is deadlock?
2. What is safe state?
3. A state is safe, if :
a) the system does not crash due to deadlock occurrence
b) the system can allocate resources to each process in some order and
still avoid a deadlock
c) the state keeps the system protected and safe
d) all of the mentioned
4. A system is in a safe state only if there exists a :
a) safe allocation b) safe resource
c) safe sequence d) all of the mentioned
5. All unsafe states are :
a) deadlocks b) not deadlocks
c) fatal d) none of the mentioned
6. If no cycle exists in the resource allocation graph :
a) then the system will not be in a safe state b) then the system will be in
a safe state
c) all of the mentioned d) none of the mentioned
7. The Banker’s algorithm is _____________ than the resource allocation
graph algorithm.
a) less efficient b) more efficient
c) equal d) none of the mentioned
8. The data structures available in the Banker’s algorithm are :
a) Available b) Need
c) Allocation d) All of the mentioned
9. The content of the matrix Need is :
a) Allocation – Available b) Max – Available
c) Max – Allocation d) Allocation – Max
10. The resource allocation graph is not applicable to a resource allocation
system :
a) with multiple instances of each resource type b) with a single instance
of each resource type
c) single & multiple instance of each resource type d) none of the mentio
34
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Aim:
Write a C program to implement deadlock detection.
Description:
Deadlock Definition:
A set of processes is deadlocked if each process in the set is waiting for an event
that only another process in the set can cause (including itself).Waiting for an
event could be:
waiting for access to a critical section
waiting for a resource Note that it is usually a non-preemptable
(resource).
ALGORITHM:
1.Start the program.
2.Initialize vectors of length m and n. Initialize
(a) Work = Available
(b) For i = 1,2, …, n, if Allocation i ≠ 0, then Finish[i] = false; otherwise,
Finish[i] = true.
3. Find an index i such that both:
(a) Finish[i] == false
(b) Requesti ≤ Work If no such i exists, go to step 4.
3.Work = Work + Allocationi Finish[i] = true go to step 2.
4. If Finish[i] == false, for some i, 1 ≤ i ≤ n, then the system is in deadlock state.
Moreover, if Finish[i] == false, then Pi is deadlocked.
5.Stop the program.
Output:
enter total no. of processes : 4
enter claim matrix :
01001
35
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
00101
00001
10101
enter allocation matrix :
10110
11000
00010
00000
enter resource vector :
21121
enter the availability vector :
00001
Result:
Thus the C program to implement deadlock detection was executed and
the output is verified successfully.
VIVA QUESTIONS
1. The wait-for graph is a deadlock detection algorithm that is applicable when
a) all resources have a single instance b) all resources have multiple
instances
c) all resources have a single 7 multiple instance d) all of the mentioned
2. An edge from process Pi to Pj in a wait for graph indicates that :
a) Pi is waiting for Pj to release a resource that Pi needs
b) Pj is waiting for Pi to release a resource that Pj needs
c) Pi is waiting for Pj to leave the system
d) Pj is waiting for Pi to leave the system
3. If the wait for graph contains a cycle :
a) then a deadlock does not exist b) then a deadlock exists
c) then the system is in a safe state d) either deadlock exists or system is in a
safe state
4. If deadlocks occur frequently, the detection algorithm must be invoked
________
a) rarely b) frequently c) rarely & frequently d) none of the mentioned
5. The disadvantage of invoking the detection algorithm for every request is :
a) overhead of the detection algorithm due to consumption of memory
b) excessive time consumed in the request to be allocated memory
c) considerable overhead in computation time
d) all of the mentioned
6. A deadlock eventually cripples system throughput and will cause the CPU
utilization to ______
a) increase b) drop c) stay still d) none of the mentioned
7. Every time a request for allocation cannot be granted immediately, the
detection algorithm is invoked. This will help identify :
a) the set of processes that have been deadlocked b) the set of processes in
the deadlock queue
c) the specific process that caused the deadlock d) all of the mentioned
36
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
8. A computer system has 6 tape drives, with ‘n’ processes competing for them.
Each process may need 3 tape drives. The maximum value of ‘n’ for which
the system is guaranteed to be deadlock free is :
a) 2 b) 3 c) 4 d) 1
9. A system has 3 processes sharing 4 resources. If each process needs a
maximum of 2 units then, deadlock :
a) can never occur b) may occur
c) has to occur d) none of the mentioned
10. ‘m’ processes share ‘n’ resources of the same type. The maximum need of
each process doesn’t exceed ‘n’ and the sum of all their maximum needs is
always less than m+n. In this setup, deadlock :
a) can never occur b) may occur
c) has to occur d) none of the mentioned
37
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Solution: To solve this Dead Lock situation, Last philosopher (any one can do
this) first try to take right side fork and then left side fork. i.e in our example 5th
person tries to take 4th Fork instead of 5th one. Since 4th Fork already taken by
4th the person, he gets nothing. But he left 5th Fork. Now the first person will
take this 5th Fork and complete dinner and make 1st and 5th available for
remaining people. Next 2nd person takes 1st fork and completes and releases 1st
and 2nd. This continuous until all finishes dinner.
Output:
Philosopher 1 is thinking
Philosopher 2 is thinking
Philosopher 3 is thinking
Philosopher 4 is thinking
Philosopher 5 is thinking
Philosopher 5 is Hungry
Philosopher 5 takes fork 4 and 5
38
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Philosopher 5 is Eating
Philosopher 3 is Hungry
Philosopher 3 takes fork 2 and 3
Philosopher 3 is Eating
Philosopher 1 is Hungry
Philosopher 4 is Hungry
Philosopher 2 is Hungry
Philosopher 5 putting fork 4 and 5 down
Philosopher 5 is thinking
Philosopher 1 takes fork 5 and 1
Philosopher 1 is Eating
Philosopher 3 putting fork 2 and 3 down
Philosopher 3 is thinking
Philosopher 4 takes fork 3 and 4
Philosopher 4 is Eating
Philosopher 5 is Hungry
Result:
Thus a C program to implement threading and synchronization
applications was successfully executed and the output was verified.
VIVA QUESTIONS
1. What is a thread?
2. What is process synchronization?
3. What is producer consumer problem?
4. What is multithreading?
5. Why synchronization is needed?
6. Thread synchronization is required because
a) all threads of a process share the same address space
b) all threads of a process share the same global variables
c) all threads of a process can share the same files
7. A deadlock free solution to the dining philosophers problem :
a) necessarily eliminates the possibility of starvation
b) does not necessarily eliminate the possibility of starvation
c) eliminates any possibility of any kind of problem further
8. The bounded buffer problem is also known as :
a) Readers – Writers problem b) Dining – Philosophers problem
c) Producer – Consumer problem
9. What is a thread pool?
10. The number of the threads in the pool can be decided on factors such as :
a) number of CPUs in the system b) amount of physical memory
c) expected number of concurrent client requests
39
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Aim:
To write a c program to implement memory management techniques such as first fit,
best fit and worst fit.
Description:
MEMORY MANAGEMENT
The purpose of the memory manager is
to allocate primary memory space to processes
to map the process address space into the allocated portion of the primary
memory
to minimize access times using a cost-effective amount of primary memory
Solution:One way to avoid making little holes is to give the client a bigger block than
it asked for. For example, we might round all requests up to the next larger multiple of
64 bytes. That doesn't make the fragmentation go away, it just hides it.
Unusable space in the form of holes is called external fragmentation
Worst Fit
The memory manager places process in the largest block of unallocated memory
available. The ides is that this placement will create the largest hole after the
allocations, thus increasing the possibility that, compared to best fit, another process
can use the hole created as a result of external fragmentation.
First Fit
Another strategy is first fit, which simply scans the free list until a large enough hole is
found. Despite the name, first-fit is generally better than best-fit because it leads to less
fragmentation.
Algorithm
1.Start the program.
2.Enter the number and size of blocks, number of files.
40
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
3.In first fit, allocate the process to free memory by sequential order if free memory
size>=process size.
4.In best fit, allocate the process to free memory, if the memory size is first, equal to
free memory then go for greater memory size.
5.In worst fit, allocate the process to free memory, if the memory size is greater then
go for equal memory size.
6.Stop the program.
INPUT
Enter the number of blocks: 3
Enter the number of files: 2
Enter the size of the blocks:-
Block 1: 5
Block 2: 2
Block 3: 7
Enter the size of the files:- File 1: 1
File 2: 4
OUTPUT
File No File Size Block No Block Size Fragment
1 1 1 5 4
2 4 3 7 3
BEST-FIT
INPUT
Enter the number of blocks: 3
Enter the number of files: 2
Enter the size of the blocks:-
Block 1: 5
Block 2: 2
Block 3: 7
Enter the size of the files:-
File 1: 1
File 2: 4
OUTPUT
File No File Size Block No Block Size Fragment
1 1 2 2 1
2 4 1 5 1
FIRST-FIT
INPUT
Enter the number of blocks: 3
Enter the number of files: 2
Enter the size of the blocks:-
Block 1: 5
Block 2: 2
Block 3: 7
Enter the size of the files:-
File 1: 1
File 2: 4
OUTPUT
File No File Size Block No Block Size Fragment
41
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
1 1 3 7 6
2 4 1 5 1
Result:
Thus the program for memory management technique first fit, best fit and worst fit
has been implemented successfully and the output was verifed.
42
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Aim:
Write a C program to implement paging technique of Memory
management.
Description:
Memory management is the functionality of an operating system which handles
or manages primary memory and moves processes back and forth between main
memory and disk during execution. Memory management keeps track of each
and every memory location, regardless of either it is allocated to some process or
it is free. It checks how much memory is to be allocated to processes. It decides
which process will get memory at what time. It tracks whenever some memory
gets freed or unallocated and correspondingly it updates the status. The set of all
logical addresses generated by a program is referred to as a logical address
space. The set of all physical addresses corresponding to these logical addresses
is referred to as a physical address space.
Paging
A computer can address more memory than the amount physically installed on
the system. This extra memory is actually called virtual memory and it is a
section of a hard that's set up to emulate the computer's RAM. Paging technique
plays an important role in implementing virtual memory.
Paging is a memory management technique in which process address space is
broken into blocks of the same size called pages (size is power of 2, between
512 bytes and 8192 bytes). The size of the process is measured in the number of
pages.
Similarly, main memory is divided into small fixed-sized blocks of (physical)
memory called frames and the size of a frame is kept the same as that of a page
to have optimum utilization of the main memory and to avoid external
fragmentation.
43
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Address Translation
Page address is called logical address and represented by page number and
the offset.
Logical Address = Page number + page offset
A data structure called page map table is used to keep track of the relation
between a page of a process to a frame in physical memory.
Algorithm:
1.Start the program.
2.Read physical memory, logical memory and partition size.
3.Calculate the physical address using the following
Physical address = ( Frame number * Frame size ) + offset
4.Display the page table, frame table and physical address.
5.Stop the program.
OUTPUT:
MEMORY MANAGEMENT USING PAGING
Enter the Size of Physical memory: 16
Enter the size of Logical memory: 8
Enter the partition size: 2
The physical memory is divided into 8 no.of frames
The Logical memory is divided into 4 no.of pages
Enter the Frame number where page 0 must be placed: 5
Enter the Frame number where page 1 must be placed: 6
Enter the Frame number where page 2 must be placed: 7
Enter the Frame number where page 3 must be placed: 2
44
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
PAGE TABLE
PageAddress FrameNo. PresenceBit
0 5 1
1 6 1
2 7 1
3 2 1
FRAME TABLE
FrameAddress PageNo
0 32555
1 32555
2 3
3 32555
4 32555
5 0
6 1
7 2
Process to create the Physical Address
Enter the Base Address: 1000
Enter theLogical Address: 3
Result:
Thus a C program to implement paging technique of Memory management
was implemented and the output was verified successfully.
VIVA QUESTIONS
1. What is paging?
2. What is page table?
3. What is physical address?
4. What is logical address?
5. What is virtual memory?
6. What are frames?
7. How physical address is calculated?
8. What is an offset?
9. What is mapping?
10. What is page number and frame number?
45
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Aim:
Write the C program to implement all page replacement algorithms
a) First In First Out(FIFO)
b) Least Recently Used(LRU)
c)Least Frequently Used(LFU)
Description:
Page Replacement Algorithm
Page replacement algorithms are the techniques using which an Operating
System decides which memory pages to swap out, write to disk when a page of
memory needs to be allocated. Paging happens whenever a page fault occurs
and a free page cannot be used for allocation purpose accounting to reason that
pages are not available or the number of free pages is lower than required
pages. There are many different page replacement algorithms such as
First In First Out(FIFO)
Least Recently Used(LRU)
Least Frequently Used(LFU)
First In First Out (FIFO) algorithm
Oldest page in main memory is the one which will be selected for
replacement.
Easy to implement, keep a list, replace pages from the tail and add new
pages at the head.
46
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Algorithm:
1.Start the program.
47
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Output:
Enter no.of frames....4
Enter number of reference string..
6
Reference np5-> 5 -1 -1 -1
Reference np6-> 5 6 -1 -1
Reference np4-> 5 6 4 -1
Reference np1-> 5 6 4 1
Reference np2-> 2 6 4 1
Reference np3-> 2 3 4 1
Result:
Thus the C program to implement First In First Out (FIFO) page
replacement algorithm was successfully executed and the result is verified.
Aim:
Write a C program to implement Least Recently Used (LRU) page
replacement algorithm .
ALGORITHM:
1.Start the program.
2.Read the number of frames.
3. Read the number of reference string.
4. Read the reference string.
5. Initialize the values in frames to -1.
6. Allocate the pages in to frames by selecting the page that has not been used
for the longest period of time.
7. Display the number of page faults.
8.Stop the program.
Output
LRU PAGE REPLACEMENT ALGORITHM
48
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Reference NO 6-> 6 -1 -1
Reference NO 5-> 6 5 -1
Reference NO 4-> 6 5 4
Reference NO 2-> 2 5 4
Reference NO 3-> 2 3 4
Reference NO 1-> 2 3 1
Aim:
Write a C program to implement Least Frequently Used (LFU) page
replacement algorithms
Algorithm:
1.Start the program.
2.Read the number of frames.
3. Read the number of reference string.
4. Read the reference string.
5. Initialize the values in frames to -1.
6. Allocate the pages in to frames by selecting the page with the smallest count
is the one which will be selected for replacement.
7. Display the number of page faults.
8. Stop the program.
OUTPUT:
49
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
…………………. 6 5 4 2 3 1
Reference NO 6-> 6 -1 -1
Reference NO 5-> 6 5 -1
Reference NO 4-> 6 5 4
Reference NO 2-> 2 5 4
Reference NO 3-> 2 3 4
Reference NO 1-> 2 3 1
50
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Linked Allocation
Each file carries a list of links to disk blocks.
Directory contains link / pointer to first block of a file.
No external fragmentation
Effectively used in sequential access file.
Inefficient in case of direct access file.
Indexed Allocation
Provides solutions to problems of contiguous and linked allocation.
A index block is created having all pointers to files.
Each file has its own index block which stores the addresses of disk
space occupied by the file.
Directory contains the addresses of index blocks of files.
51
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
AIM:
Write a C Program to implement Sequential File Allocation method.
ALGORITHM:
1. Start the program.
2. Read the number of files.
3. For each file, read the number of blocks required and the starting block of the
file.
4. Allocate the blocks sequentially to the file from the starting block.
5. Display the file name, starting block , and the blocks occupied by the file.
6.Stop the program.
OUTPUT:
Enter no.of files: 2
Enter no. of blocks occupied by file1 4
Enter the starting block of file1 2
Enter no. of blocks occupied by file2 10
Enter the starting block of file2 5
Filename Start block length
1 2 4
2 5 10
Result:
Thus the C Program to implement Sequential File Allocation method was
executed successfully and the result is verified.
Aim:
Write a C Program to implement Indexed File Allocation method.
Algorithm:
1. Start the program.
2. Read the number of files
3. Read the index block for each file.
4. For each file, read the number of blocks occupied and number of blocks of the
file.
5. Link all the blocks of the file to the index block.
6. Display the file name, index block, and the blocks occupied by the file.
52
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
OUTPUT:
Enter no. of files: 2
Enter index block 3
Enter blocks occupied by file1: 4
Enter blocks of file1:
9467
Enter index block 5
Enter blocks occupied by file2: 2
enter blocks of file2: 10 8
File Index Length
1 3 4
2 5 2
Blocks occupied are:
file1 3--->9 3--->4 3--->6 3--->7
file2 5--->10 5--->8
Result:
Thus the C Program to implement indexed File Allocation method was
executed successfully and the result is verified.
Aim:
Write a C Program to implement Linked File Allocation method.
Algorithm:
1. Start the program.
2. Read the number of files.
3. For each file, read the file name, starting block, number of blocks and block
numbers of the file.
4. Start from the starting block and link each block of the file to the next block in
a linked list fashion.
5. Display the file name, starting block, size of the file , and the blocks occupied
by the file.
6. Stop the program.
Output:
Enter no. of files : 2
Enter file name : venkat
Enter starting block : 20
Enter no.of blocks : 6
Enter block numbers : 4
12
15
45
32
25
Enter file name : rajesh
Enter starting block : 12
53
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Result:
Thus the C Program to implement linked File Allocation method was
executed successfully and the result is verified.
VIVA QUESTIONS:
1.What file access pattern is particularly suited to chained file allocation on
disk?
2. Define Sequential File allocation
3. Why we use file allocation strategies?
4.what are the advantages and dis-advantages of Sequential File allocation?
5. The average waiting time =________________________________.
6. What file allocation strategy is most appropriate for random access files?
7.Define File?
8.Define Directory?
9. Why we use file allocation strategies?
10.what are the advantages and dis-advantages Indexed Allocation?
11.What file access pattern is particularly suited to chained file allocation on
disk?
12. What file allocation strategy is most appropriate for random access files?
13.Mention different file allocation strategies?
14. Why we use file allocation strategies?
15.what are the advantages and dis-advantages of each strategies?
16. The ______________contains a pointer to the first and last blocks of the file.
54
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
55
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
with this architecture. Personal computers use hierarchical directory system for
managing files.
Aim:
Write a C program to implement Single level Directory in file organization.
Algorithm:
1. Start the program.
2.Intialize struct with filename, directory name.
3.Read the directory name and option for switch case.
4. If the operation to be performed is to create file , a new file under the root directory
is created.
5. The file created under the root directory can be searched deleted.
6.stop the program.
56
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
OUTPUT:
Enter name of directory -- IT
Result:
Thus the program to implement Single level directory was executed and
verified successfully
Aim:
Write a C program to implement Two level Directory in file organization.
Algorithm:
1. Start the program.
2. Initialize values dname[10],fname[10][10],dir[10],dcnt;
3. Read number of directories.
57
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
OUTPUT:
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 1
Directory created
58
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
File A2 is deleted
Result:
Thus the program to implement Two level directory was executed and verified
successfully
Aim:
Write a C program to implement Hierarchical level Directory in file
organization.
Algorithm:
1.Start the program.
2. Initialize values x,y,ftype,lx,rx,nc,level.
3. Initialize struct tree_element to store pointers.
4.Read number of directories under root directory.
5. Read file name under each directory.
6. All sub directories holds two pointers. One is to point its child directory/filename
and another is to points its parent directory.
7. If the directory name matches with the existing directory create and display the files
under the mentioned directory name.
8. Include the created directories under a single root directory.
9. If a filename which does not exist under a directory is mentioned, then print file not
found.
10. Stop the program.
OUTPUT:
Enter Name of dir/file (under root): ROOT
Enter 1 for Dir / 2 For File : 1
No of subdirectories / files (for ROOT) :2
Enter Name of dir/file (under ROOT):USER 1
Enter 1 for Dir /2 for file:1
No of subdirectories /files (for USER 1):1
Enter Name of dir/file (under USER 1):SUBDIR
Enter 1 for Dir /2 for file:1
59
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Result:
Thus the program to implement Hierarchical directory was executed and
verified successfully.
Aim:
Write a C program to implement Direct Acyclic Graph (DAG ) in File
Organization Technique .
Algorithm:
60
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
Output:
Result:
Thus the program to implement Direct Acyclic Graph was executed and
verified successfully.
VIVA QUESTIONS
1. What is file organization?
2. What are advantages and disadvantages in single level directory?
3. What are advantages and disadvantages in two level directory?
4. What are advantages and disadvantages in hierarchical level directory?
5. What is root directory?
6. What is DAG?
7. List some of the file organization technique?
8. What is the advantages of organizing the files?
9. List out the file accessing permissions.
10. What is a sub directory?
61
KLNCE/IT /2018-2019 (EVEN) CS8461-OPERATING SYSTEMS LAB
62