Documente Academic
Documente Profesional
Documente Cultură
1.1
1.2
1.3
Tannenbaums Solution
This solution uses only boolean semaphors. There is one global semaphore
to provide mutual exclusion for exectution of critical protocols. There is one
semaphore for each chopstick. In addition, a local two-phase prioritization
scheme is used, under which philosophers defer to their neighbors who have
declared themselves hungry. All arithmetic is modulo 5.
system DINING PHILOSOPHERS
VAR
me :
semaphore , i n i t i a l l y 1 ;
s [ 5 ] : semaphore s [ 5 ] , i n i t i a l l y 0 ;
p f l a g [ 5 ] : {THINK, HUNGRY, EAT} , i n i t i a l l y THINK;
/ f o r mutual e x c l u s i o
/ f o r s y n c h r o n i z a t i o n
/ p h i l o s o p h e r f l a g /
As b e f o r e , each p h i l o s o p h e r i s an e n d l e s s c y c l e o f t h i n k i n g and e a t i n g .
procedure philosopher ( i )
{
w h i l e TRUE do
{
THINKING ;
take chopsticks ( i );
EATING;
drop chopsticks ( i ) ;
}
}
The take chopsticks procedure involves checking the status of neighboring
philosophers and then declaring ones own intention to eat. This is a twophase protocol; first declaring the status HUNGRY, then going on to EAT.
procedure take chopsticks ( i )
{
DOWN(me ) ;
/ c r i t i c a l s e c t i o n /
p f l a g [ i ] := HUNGRY;
test [ i ] ;
UP(me ) ;
/ end c r i t i c a l s e c t i o n /
2
/ Eat i f e n a b l e d /
DOWN( s [ i ] )
}
void t e s t ( i )
/ Let p h i l [ i ] eat , i f w a i t i n g /
{
i f ( p f l a g [ i ] == HUNGRY
&& p f l a g [ i 1] != EAT
&& p f l a g [ i +1] != EAT)
then
{
p f l a g [ i ] := EAT;
UP( s [ i ] )
}
}
Once a philosopher finishes eating, all that remains is to relinquish the
resourcesits two chopsticksand thereby release waiting neighbors.
void drop chopsticks ( i n t i )
{
DOWN(me ) ;
t e s t ( i 1);
t e s t ( i +1);
UP(me ) ;
}
/
/
/
/
c r i t i c a l s e c t i o n /
Let p h i l . on l e f t e a t i f p o s s i b l e /
Let p h i l . on r g h t e a t i f p o s s i b l e /
up c r i t i c a l s e c t i o n /
OS Lab
Bankers Algorithm
Aim
Implementation of Bankers Algorithm
Theory
The Banker's algorithm, sometimes referred to as the avoidance algorithm, is a resource
allocation and deadlock avoidance algorithm that tests for safety by simulating the allocation of
predetermined maximum possible amounts of all resources, and then makes an "s-state" check
to test for possible deadlock conditions for all other pending activities, before deciding
whether allocation should be allowed to continue.
When a new process enters a system, it must declare the maximum number of instances of
each resource type that it may ever claim; clearly, that number may not exceed the total
number of resources in the system. Also, when a process gets all its requested resources it
must return them in a finite amount of time.
Let n be the number of processes in the system and m be the number of resource types. Then
we need the following data structures:
Safety Algorithm
The algorithm for checking whether a system is in safe state or not is as follows
1.
If request[i] <=need[i]
Goto 2, otherwise raise error
2.
If request[i] <=available
Goto 3 otherwise process must wait
3.
1
1.1
1.2
Synopsis
1.3
Description
The function statvfs() returns information about a mounted file system. path
is the pathname of any file within the mounted file system. buf is a pointer
to a statvfs structure defined approximately as follows:
struct statvfs {
unsigned long
unsigned long
fsblkcnt t
fsblkcnt t
fsblkcnt t
fsfilcnt t
fsfilcnt t
fsfilcnt t
unsigned long
unsigned long
unsigned long
};
f bsize ;
f frsize ;
f blocks ;
f bfree ;
f bavail ;
f files ;
f ffree ;
f favail ;
f fsid ;
f flag ;
f namemax ;
/
/
/
/
/
/
/
/
/
/
/
f i l e system b l o c k s i z e /
fragment s i z e /
s i z e o f f s i n f f r s i z e u n i t s /
# f r e e b l o c k s /
# free blocks for unprivileged user
# i n o d e s /
# f r e e i n o d e s /
# f r e e inodes for unprivileged user
f i l e system ID /
mount f l a g s /
maximum f i l e n a m e l e n g t h /
Here the types fsblkcnt t and fsfilcnt t are defined in sys/types.h Both
used to be unsigned long. The field f flag is a bit mask . Bits defined by
POSIX are
ST RDONLY : Read-only file system.
ST NOSUID : Set-user-ID/set-group-ID bits are ignored by exec(3).
It is unspecified whether all members of the returned struct have
meaningful values on all file systems.
1
1.4
Return Value
1.5
1.5.1
Errors
EACCES
EBADF
EFAULT
EINTR
EIO
ELOOP
ENAMETOOLONG
1.5.8
ENOENT
ENOMEM
ENOSYS
ENOTDIR
EOVERFLOW
return 0;
1:
2:
3:
4:
5:
6:
7:
Theory:
A sliding window protocol is a feature of packet-based data transmission protocols. Sliding
window protocols are used where reliable in-order delivery of packets is required, Eg: in TCP.
Each portion of the transmission is assigned a unique consecutive sequence number, and the
receiver uses the numbers to place received packets in the correct order, discard duplicate
packets and identify missing ones. The problem with this is that there is no limit on the size of
the sequence number that can be required.
By placing limits on the number of packets that can be transmitted or received at any given time,
a sliding window protocol allows an unlimited number of packets to be communicated using
fixed-size sequence numbers. The term "window" on the transmitter side represents the logical
boundary of the total number of packets yet to be acknowledged by the receiver. The receiver
informs the transmitter in each acknowledgment packet the current maximum receiver buffer
size (window boundary).
If acknowledgement does not come in time, the sender assumes that either the
frame or its acknowledgement is lost in transit. Sender retransmits the frame
and starts the timeout counter.
Go Back N ARQ
The sending-window size enables the sender to send multiple frames without
receiving the acknowledgement of the previous ones. The receiving-window
enables the receiver to receive multiple frames and acknowledge them. The
receiver keeps track of incoming frames sequence number.
When the sender sends all the frames in window, it checks up to what sequence
number it has received positive acknowledgement. If all frames are positively
acknowledged, the sender sends next set of frames. If sender finds that it has
received NACK or has not receive any ACK for a particular frame, it retransmits all
the frames after which it does not receive any positive ACK.