RESOURCES 3.2 INTRODUCTION TO DEADLOCKS 3.3 THE OSTRICH ALGORITHM 3.4 DEADLOCK DETECTION AND RECOVERY 3.5 DEADLOCK AVOIDANCE 3.6 DEADLOCK PREVENTION 3.7 OTHER ISSUES 3.8 RESEARCH ON DEADLOCKS 3.9 SUMMARY
Trang 110CASE STUDY 1: UNIX AND LINUX
Trang 2Standards utility programs (shell, editors, compliers etc)
Standard library (open, close, read, write, fork, etc)
UNIX operating system (process management, memory management,
the file system, I/O, etc)
Hardware (CPU, memory, disks, terminals, etc)
User interface
Library interface
System
call
interface
User mode
Kernel mode
Fig 10-1 The layers in a UNIX system.
Trang 4System calls Interrupts and traps
Terminal handing Sockets
Network protocols
Routing
File naming
ping
Map-Page faults Signalhandling
Process creation and termination Raw
tty
Cooked tty
Line disciplines
Character
devices
Network device drivers
Hardware
Disk device drivers
Process dispatching
Process scheduling
Page cache
Buffer cache
File systems
Virtual memory
Fig 10-3 Structure of the 4.4BSD kernel.
Trang 5pid = fork( ); /*if the fork succeeds, pid > 0 in the parent */
Trang 7Fig 10-6 Some system calls relating to processes The return code
s is − 1 if an error has occurred, pid is a process ID, and residual is
the remaining time in the previous alarm The parameters are what the name suggests.
Trang 8while (TRUE) { /*repeat forever /*/
type3prompt( ); /*display prompt on the screen*/read3command(command, params); /*read input line from keyboard*/pid = fork( ); /*fork off a child process */
if (pid < 0) {
printf("Unable to fork0); /*error condition*/
continue; /*repeat the loop*/
Trang 10sh sh ls
Fork code Exec code
New process Same process
1 Fork call 3 exec call
4 sh overlaidwith ls
2 new shcreatedPID = 501 PID = 748 PID = 748
Allocate child's process table entry
Fill child's entry from parent
Allocate child's stack and user area
Fill child's user area from parent
Allocate PID for child
Set up child to share parent's text
Copy page tables for data and stack
Set up sharing of open files
Copy parent's registers to child
Find the executable programVerify the execute permissionRead and verify the headerCopy arguments, environ to kernelFree the old address spaceAllocate new address spaceCopy arguments, environ to stackReset signals
Initialize registers
Fig 10-9 The steps in executing the command ls typed to the
shell.
Trang 13Process 0
Process 1 Page Process 2
daemon
Login: login Password: sh % cp f1 f2
cp getty
init
Fig 10-12 The sequence of processes used to boot some UNIX
systems.
Trang 148K
0
Unused memory
24K
8K 0K
BSS
Text Data
Trang 15Unused memory
Fig 10-14 Two processes can share a mapped file.
Trang 16Fig 10-15 Some system calls relating to memory management.
The return code s is − 1 if an error has occurred; a and addr are memory addresses, len is a length, prot controls protection, flags are miscellaneous bits, fd is a file descriptor, and offset is a file
offset.
Trang 17Page frame 3 Page frame 2 Page frame 1 Page frame 0
4.3 BSD kernel
Index of next entry Index of previous entry Disk block number Disk device number Block hash code Index into proc table Text/data/stack Offset within segment
Used when page frame is
on the free list
Locked in memory bit
Wanted
In transit Free
Fig 10-16 The core map in 4BSD
Trang 18directory
Directory
Page middle directory
Page table
Page
Word selected
Virtual address Offset
Page Middle
Fig 10-17 Linux uses three-level page tables.
Trang 19168832
(f)
88832
8
(g)
848
832
(h)
48
8832
(i)16
44832
(c)1616
Trang 20User space
Kernel space
Receiving processSending process
Trang 23Raw interfaceto/dev/tty
Fig 10-22 The UNIX I/O system in BSD.
Trang 24Token ring driver
Token ring controllerProcess
Trang 26bin dev etc lib tmp usr
x y z
x y z
a b c x
Trang 27x y z
x y z
Fig 10-26 (a) Separate file systems (b) After mounting.
Trang 28A's shared lock
Trang 29Fig 10-28 Some system calls relating to files The return code s is
− 1 if an error has occurred; fd is a file descriptor, and position is a
file offset The parameters should be self explanatory.
Trang 31Fig 10-30 Some system calls relating to directories The return
code s is − 1 if an error has occurred; dir identifies a directory stream and dirent is a directory entry The parameters should be
self explanatory.
Trang 32block
Super
block
I nodes Data blocks
Fig 10-31 Disk layout in classical UNIX systems.
Trang 34Mode i-node
Link count Uid Gid File size Times Addresses of first 10 disk blocks Single indirect Double indirect Triple indirect
Pointers to disk blocks
Triple indirect block Double
indirect block Single
indirect block
‘
Fig 10-33 The relation between the file descriptor table, the open file description table, and the i-node table.
Trang 35Fig 10-34 (a) A BSD directory with three files (b) The same
directory after the file voluminous has been removed.
Trang 36Boot Block group 0
Super– Group
block descriptor
Block group 1
Blockbitmap
Datablocks
I–nodebitmap I–nodes
Block group 2 Block group 3 Block group 4
Fig 10-35 Layout of the Linux Ext2 file system.
Trang 37cat cp Is mv sh
a b c d e
/proj2/proj1
/projects
/mnt/bin
Mount/
Fig 10-36 Examples of remote mounted file systems Directories are shown as squares and files are shown as circles.
Trang 38Client kernel Server kernel
System call layer
Virtual file system layer Virtual file system layer
NFS server
Message
to server
Message from client
V- node
Fig 10-37 The NFS layer structure.
Trang 40Fig 10-39 Some system calls relating to security The return code
s is − 1 if an error has occurred; uid and gid are the UID and GID,
respectively The parameters should be self explanatory.