Deakin University - SIT222 Operating Systems Concepts Assignment

Verified

Added on  2023/06/11

|16
|2684
|171
Homework Assignment
AI Summary
This assignment solution for SIT222 Operating Systems Concepts covers key areas including paging and segmentation, inter-process communication (IPC), and file systems. It discusses the working set concept, compares paging and segmentation, and analyzes page replacement algorithms like FIFO, LRU, and Optimal. The solution also addresses deadlock prevention and avoidance strategies, along with an example of the Banker's algorithm. Furthermore, it includes a C code implementation of the producer-consumer problem using semaphores. Finally, the assignment explores file allocation methods such as FAT and contiguous allocation, and discusses techniques for improving file system performance. Desklib offers a wealth of similar resources for students.
Document Page
Running Head: SIT222 OPERATING SYSTEMS CONCEPTS
SIT222 Operating Systems Concepts
[Student Name]
[University Name]
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1SIT222 OPERATING SYSTEMS CONCEPTS
Table of Contents
Question 1: Paging and Segmentation.............................................................................................2
Answer to question a)..................................................................................................................2
Answer to question b)..................................................................................................................2
Answer to question c)..................................................................................................................3
Question 2: Inter-process Communication......................................................................................5
Answer to question a)..................................................................................................................5
Answer to question b)..................................................................................................................6
Answer to question c)................................................................................................................10
Question 3: Files and File Systems................................................................................................11
Answer to question a)................................................................................................................11
Answer to question b)................................................................................................................12
Answer to question c)................................................................................................................13
Answer to question d)................................................................................................................13
Document Page
2SIT222 OPERATING SYSTEMS CONCEPTS
Question 1: Paging and Segmentation
Answer to question a)
The "working set" is short hand for "parts of memory that the present algorithm is
utilizing" and is dictated by which parts of memory the CPU simply happens to get to.
The main point is to find the pages within and outside of the working set. The inexact
time the page was last utilized and the R (Referenced) bit. The vacant white rectangle symbolizes
alternate fields not required for this algorithm, for example, the page outline number, the
insurance bits, and the M (Modified) bit.
Answer to question b)
The memory administration in the working framework is a basic usefulness, which
enables the portion of memory to the procedures for execution and deallocates the memory when
the procedure is never again required. In this article, we will talk about two memory
administration plans paging and segmentation. On the off chance that we discuss the essential
contrasts between the paging and segmentation it is, a page is a settled sized block though, a
segment is a variable-sized block.
1. The fundamental contrast amongst segmentation and paging is that a page is
dependably of settled block size.
2. Paging may prompt internal fragmentation as the page is of settled block size,
however it might happen that the procedure does not obtain the whole block size which will
create the internal section in memory. The segmentation may prompt external fragmentation as
the memory is loaded with the variable sized blocks.
Document Page
3SIT222 OPERATING SYSTEMS CONCEPTS
3. In paging the client just gives a solitary whole number as the address which is
partitioned by the equipment into a page number and Offset. On alternate hands, in segmentation
the client indicates the address in two amounts i.e. segment number and offset.
4. The size of the page is chosen or indicated by the equipment. On alternate hands,
the size of the segment is determined by the client.
In a joined paging/segmentation framework a client address space is separated into
various segments at the watchfulness of the software engineer. Each segment is thusly separated
into various settled size pages which are equivalent long to a fundamental memory outline. On
the off chance that a segment is not as much as a page long, the segment involves only one page.
From the programmer`s perspective, a legitimate address still comprises of a segment number
and a segment offset. From the system`s perspective, the segment offset is seen as a page number
and page offset for a page inside the predefined segment.
Answer to question c)
1, 2, 3, 4, 1, 2, 5, 3, 4, 1, 3, 2, 5, 6, 4, 3, 7, 6, 3, 4
FIFO
1 2 3 4 1 2 5 3 4 1 3 2 5 6 4 3 7 6 3 4
0 1 1 1 4 4 4 5 5 5 1 1 1 1 6 6 6 7 7 7 7
1 2 2 2 1 1 1 3 3 3 3 3 5 5 5 3 3 3 3 4
2 3 3 3 2 2 2 4 4 4 2 2 2 4 4 4 6 6 6
* *
Page Hit – 2
Page Fault – 20-2 = 18
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4SIT222 OPERATING SYSTEMS CONCEPTS
LRU
1 2 3 4 1 2 5 3 4 1 3 2 5 6 4 3 7 6 3 4
0 1 1 1 4 4 4 5 5 5 1 1 1 5 5 5 3 3 3 3 3
1 2 2 2 1 1 1 3 3 3 3 3 3 6 6 6 7 7 7 4
2 3 3 3 2 2 2 4 4 4 2 2 2 4 4 4 6 6 6
* *
Page Hit – 2
Page Fault – 20-2 = 18
OPTIMAL
1 2 3 4 1 2 5 3 4 1 3 2 5 6 4 3 7 6 3 4
0 1 1 1 1 1 1 1 1 1 1 1 2 5 6 6 6 6 6 6 6
1 2 2 2 2 2 5 3 3 3 3 3 3 3 3 3 3 3 3 3
2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 7 7 7 7
* * * * * * * * *
Page Hit - 9
Page Fault – 20-9 = 11
Question 2: Inter-process Communication
Answer to question a)
1. We can utilize a convention to counteract or stay away from deadlocks,
guaranteeing that the framework will never enter a deadlock state.
o To guarantee that deadlocks never occur, the framework can utilize either a
deadlock-prevention or a deadlock-avoidance conspire.
Document Page
5SIT222 OPERATING SYSTEMS CONCEPTS
o Deadlock prevention gives a set of techniques to guaranteeing that no less than
one of the essential conditions (Section 7.2.1) can't hold.
o Design a framework such that the likelihood of deadlock is avoided from the
earlier (gather time/statically, by outline).
o Deadlock avoidance requires that the OS be given ahead of time extra data
concerning which assets a procedure will demand and use amid its lifetime. With
this extra learning, it can choose for each demand regardless of whether the
procedure should pause.
o Make a choice powerfully checking whether the demand will, if in all actuality,
possibly prompt a deadlock or not. (run-time/powerfully, before it happens).
2. We can enable the framework to enter a deadlock state, identify it, and recuperate.
o If a framework does not utilize either a deadlock-prevention or a deadlock-
avoidance algorithm, at that point a deadlock circumstance may emerge.
o In this condition, the framework can give an algorithm that looks at the state of
the framework to decide if a deadlock has occurred and an algorithm to recoup
from the deadlock.
o Let deadlocks occur, recognize them, and make a move (run-time/progressively,
after it happens)
3. We can overlook (The Ostrich Algorithm; possibly on the off chance that you
disregard it, it will overlook you) the issue by and large and imagine that deadlocks never occur
in the framework.
Document Page
6SIT222 OPERATING SYSTEMS CONCEPTS
o If a framework neither guarantees that a deadlock will never occur nor gives an
instrument to deadlock detection and recovery, at that point we may touch base at
a circumstance where the framework is in a deadlocked state yet has no chance to
get of perceiving what has happened.
o Eventually, the framework will quit functioning and should be restarted
physically.
o In numerous frameworks, deadlocks occur occasionally (say, once every year);
hence, this strategy is less expensive than the prevention, avoidance, or detection
and recovery strategies.
Answer to question b)
Allocation Max Available
A B C A B C A B C
P0 1 2 2 9 8 8 2 2 2
P1 1 1 2 4 3 3
P2 2 1 1 2 1 7
P3 2 2 1 3 3 2
P4 2 2 2 7 7 7
Need Matrix
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
7SIT222 OPERATING SYSTEMS CONCEPTS
A B C
P0 8 6 6
P1 3 2 1
P2 0 0 6
P3 1 1 1
P4 5 5 5
P0 need <= available
866<= 222
Not execute
P1 need <= available
321 <= 222
Not execute
P2 need <=available
006<=222
Not execute
P3 need <= available
111<=222
Execute the process
Now available = allocation + available = 221+222 = 443
Document Page
8SIT222 OPERATING SYSTEMS CONCEPTS
P4 need <= available
555<= 443
Not execute
P0 need <= available
866<= 443
Not execute
P1 need <= available
321 <= 443
Execute the process
Now available = 112+443 = 555
P2 need <=available
006<=555
Not execute
P4 need <= available
555<= 555
Process execute
Now available = 222+555 = 777
P0 need <= available
Document Page
9SIT222 OPERATING SYSTEMS CONCEPTS
866<= 777
Not execute
P2 need <=available
006<=777
Process execute
Now available = 211+777 = 988
P0 need <= available
866<= 988
Process execute
Now available = 1 2 2 + 9 8 8 = 10 10 10
Process sequence {P3, P1, P4, P2, P0}
The system is in safe state
Answer to question c)
#include<stdio.h>
#include<stdlib.h>
int mutex=1,full=0,empty=3,x=0;
int main()
{
int n;
void producer();
void consumer();
int wait(int);
int signal(int);
printf("\n1.Producer\n2.Consumer\n3.Exit");
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
10SIT222 OPERATING SYSTEMS CONCEPTS
while(1)
{
printf("\nEnter your choice:");
scanf("%d",&n);
switch(n)
{
case 1: if((mutex==1)&&(empty!=0))
producer();
else
printf("Buffer is full!!");
break;
case 2: if((mutex==1)&&(full!=0))
consumer();
else
printf("Buffer is empty!!");
break;
case 3:
exit(0);
break;
}
}
return 0;
}
int wait(int s)
{
return (--s);
}
int signal(int s)
{
return(++s);
}
void producer()
{
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
x++;
printf("\nProducer produces the item %d",x);
mutex=signal(mutex);
}
void consumer()
Document Page
11SIT222 OPERATING SYSTEMS CONCEPTS
{
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\nConsumer consumes item %d",x);
x--;
mutex=signal(mutex);
}
Question 3: Files and File Systems
Answer to question a)
The File Allocation Table, FAT, utilized by DOS is a variety of linked allocation, where
every one of the connections are put away in a different table toward the start of the disk. The
advantage of this approach is that the FAT table can be reserved in memory, extraordinarily
enhancing irregular access speeds.
Answer to question b)
In contiguous allocation, files are relegated to contiguous regions of auxiliary stockpiling.
A client determines ahead of time the size of the region expected to hold a file to be made. In the
event that the coveted measure of contiguous space isn't accessible, the file can't be made.
Answer to question c)
Numerous apparently basic I/O tasks are really made out of sub-activities. For instance,
erasing a file on an I-node based system (extremely this implies erasing the last connect to the I-
node) requires expelling the passage from the catalog, setting the I-node on the free rundown,
and putting the file blocks on the free rundown. Since I/O tasks can command the time required
for finish client forms, extensive exertion has been used to enhance the execution of these
chevron_up_icon
1 out of 16
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]