Paper
Paper
Paper
#include<stdio.h>
#define n 4
struct fork{
int taken;
}ForkAvil[n];
struct philosp{
int left;
int right;
}Philostatus[n];
void goForDinner(int philID){ //same like threads concept here cases implemented
if(Philostatus[philID].left==10 && Philostatus[philID].right==10)
printf("Philosopher %d completed his dinner\n",philID+1);
//if already completed dinner
else if(Philostatus[philID].left==1 && Philostatus[philID].right==1){
//if just taken two forks
printf("Philosopher %d completed his dinner\n",philID+1);
if(otherFork== -1)
otherFork=(n-1);
if(philID== -1)
philID=(n-1);
if(ForkAvil[philID].taken == 0){
ForkAvil[philID].taken = Philostatus[dupphilID].right = 1;
printf("Fork %d taken by Philosopher %d\n",philID+1,dupphilID+1);
}else{
printf("Philosopher %d is waiting for Fork %d\n",dupphilID+1,philID+1);
}
}
}
else if(Philostatus[philID].left==0){ //nothing taken yet
if(philID==(n-1)){
if(ForkAvil[philID-1].taken==0){ //KEY POINT OF THIS PROBLEM, THAT LAST PHILOSOPHER TRYING IN
reverse DIRECTION
ForkAvil[philID-1].taken = Philostatus[philID].left = 1;
printf("Fork %d taken by philosopher %d\n",philID,philID+1);
}else{
printf("Philosopher %d is waiting for fork %d\n",philID+1,philID);
}
}else{ //except last philosopher case
if(ForkAvil[philID].taken == 0){
ForkAvil[philID].taken = Philostatus[philID].left = 1;
printf("Fork %d taken by Philosopher %d\n",philID+1,philID+1);
}else{
printf("Philosopher %d is waiting for Fork %d\n",philID+1,philID+1);
}
}
}else{}
}
int main(){
for(i=0;i<n;i++)
ForkAvil[i].taken=Philostatus[i].left=Philostatus[i].right=0;
while(compltedPhilo<n){
/* Observe here carefully, while loop will run until all philosophers complete dinner
Actually problem of deadlock occur only thy try to take at same time
This for loop will say that they are trying at same time. And remaining status will print by go for dinner function
*/
for(i=0;i<n;i++)
goForDinner(i);
printf("\nTill now num of philosophers completed dinner are %d\n\n",compltedPhilo);
}
return 0;
}
3i
Segmentation
A Memory Management technique in which memory is divided into variable sized chunks which
can be allocated to processes. Each chunk is called a Segment.
The mapping of the logical address to the physical address is done with the help of the segment
table.
Segment table is divided into three part : Segment Number, Base Address and Segment Limit.
o Segment Number - Used as an index into a segment table which contains Base Address and
Limit of each segment in physical memory.
o Base Address - Starting address of the corresponding segment in main memory.
o Segment Limit - The length of the segment.
3ii
Paging
Paging is a memory management technique that permits the physical address space of a process to be non-
contiguous.
Pure segmentation is not very popular and not being used in many of the operating systems. However,
Segmentation can be combined with Paging to get the best features out of both the techniques.
In Segmented Paging, the main memory is divided into variable size segments which are further divided
into fixed size pages.
Direct file helps in online transaction processing system (OLTP) like online railway reservation
system.
In direct file, sorting of the records are not required.
It accesses the desired records immediately.
It updates several files quickly.
It has better control over record allocation.
Indexed sequential file combines both sequential file and direct file organization.
In indexed sequential file, records are stored randomly on a direct access device such as magnetic
disk by a primary key.
This file have multiple keys. These keys can be alphanumeric in which the records are ordered is
called primary key.
The data can be access either sequentially or randomly using the index. The index is stored in a file
and read into memory when the file is opened.
In indexed sequential file, sequential file and random file access is possible.
It accesses the records very fast if the index table is properly organized.
The records can be inserted in the middle of the file.
It provides quick access for sequential and direct processing.
It reduces the degree of the sequential search.
The take-grant system models a protection system which consists of a set of states and state transitions. A
directed graph shows the connections between the nodes of this system. These nodes are representative of
the subjects or objects of the model. The directed edges between the nodes represent the rights that one
node has over the linked node.
remove rule allows a subject to remove rights it has over on another object
Example
Q4. (b) Explain Bell and La-Padula Model for security and protection.
Why is security a critical issue in a distributed OS environment ?
er : - The Bell-Lapadula Model of protection systems deals with the control of information flow. It is a
linear non-discretionary model. This model of protection consists of the following components :
A set of subjects, a set of objects, and an access control matrix.
Several ordered security levels. Each subject has a clearance and each object has a classification
which attaches it to a security level. Each subject also has a current clearance level which does not
exceed its clearance level. Thus a subject can only change to a clearance level below its assigned
clearance level.
Control Attribute - This is an attribute given to the subject that creates an object. Due to this, the creator
of an object can pass any of the above four access rights of that object to any subject. However, it cannot
pass the control attribute itself. The creator of an object is also known as the controller of that object.
Reading Down - A subject has only read access to objects whose security level is below the
subject's current clearance level. This prevents a subject from getting access to information
available in security levels higher than its current clearance level.
Writing Up - A subject has append access to objects whose security level is higher than its current
clearance level. This prevents a subject from passing information to levels lower than its current
level.