cs431-cotter1 linux operating system review chapter 10
TRANSCRIPT
![Page 1: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/1.jpg)
cs431-cotter 1
Linux Operating System
Review
Chapter 10
![Page 2: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/2.jpg)
cs431-cotter 2
Overview
• System Overview• Linux Processes• CPU Scheduler• Process Synchronization• Memory Management• Input / Output• File Systems • Security
![Page 3: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/3.jpg)
cs431-cotter 3
Figure 10-1. The layers in a Linux system.
Interfaces to Linux
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 4: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/4.jpg)
cs431-cotter 4
Figure 10-2. A few of the common Linux utility programs required by POSIX.
Linux Utility Programs
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 5: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/5.jpg)
cs431-cotter 5Figure 10-3. Structure of the Linux kernel
Kernel Structure
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 6: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/6.jpg)
cs431-cotter 6
Overview
• System Overview• Linux Processes• CPU Scheduler• Process Synchronization• Memory Management• Input / Output• File Systems • Security
![Page 7: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/7.jpg)
cs431-cotter 7
Linux Processesint pid;:pid = fork (); //create a child processif (pid < 0) // fork failed!!
errexit(); // handle errorelse if (pid == 0) {: //child process work goes here}else //pid must be > 0{: //parent process work goes here}
![Page 8: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/8.jpg)
cs431-cotter 8
Figure 10-6. Some system calls relating to processes.
Process Management System Calls in Linux
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 9: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/9.jpg)
cs431-cotter 9
Figure 10-8. The steps in executing the command ls typed to the shell.
Implementation of Exec
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 10: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/10.jpg)
cs431-cotter 10
Overview
• System Overview• Linux Processes• CPU Scheduler• Process Synchronization• Memory Management• Input / Output• File Systems • Security
![Page 11: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/11.jpg)
cs431-cotter 11
Linux Scheduling Algorithm
• SCHED_FIFO Designed for static priority. Soft real-time processes.
• SCHED_RR designed for real-time processes that require fair assignment of CPU time.
• SCHED_OTHER designed for normal user processes. Preemptible. Priority determined by base priority and time remaining in quantum.
![Page 12: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/12.jpg)
cs431-cotter 12
Figure 10-10. Illustration of Linux runqueue and priority arrays.
Scheduling in Linux
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 13: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/13.jpg)
cs431-cotter 13
Overview
• System Overview• Linux Processes• CPU Scheduler• Process Synchronization• Memory Management• Input / Output• File Systems • Security
![Page 14: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/14.jpg)
cs431-cotter 14
Figure 10-5. The signals required by POSIX.
Signals in Linux (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 15: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/15.jpg)
cs431-cotter 15
Signals must be captured with signal handler
• Program must explicitly handle signals, if it does not want to use default handling (usually termination)
• sigaction (signal_to_catch, new_action, old_action)• struct sigaction {
void * sa_handler; // What function do we call?sigset_t mask; // Mask of signals to block when calledint sa_flags; // Special flags to set.};
• Will be executed automatically on reception of appropriate signal
![Page 16: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/16.jpg)
cs431-cotter 16
Semaphores
• POSIX version of semaphores– #include <semaphore.h>– classic semaphore implementation
• System V version of semaphores– #include <sys/sem.h>– Enhanced version of semaphores to include sets
![Page 17: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/17.jpg)
cs431-cotter 17
Figure 2-30. Some of the Pthreads calls relating to mutexes.
Mutexes in Pthreads
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 18: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/18.jpg)
cs431-cotter 18
Named Pipes
• Permanent objects• Available to processes that can access the
filespace (same system or on a shared file system)
• Processes do not have to be related.
![Page 19: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/19.jpg)
cs431-cotter 19
Message Queues
• A “linked list of messages”• Message queue has kernel persistence
– Supports asynchronous communications.– Messages are stored in the queue, independent of the
sender (sender can close queue without losing messages).
– Receiver can retrieve messages at a later time.
• Messages have a priority– Higher priority messages are retrieved first (POSIX)– Max priority is 32768
![Page 20: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/20.jpg)
cs431-cotter 20
Shared Memory
• Allows 2 or more processes to share the same main memory space– Memory can be allocated as blocks (pages) of
memory– Memory can be mapped as a file that is
available in memory to multiple processes
![Page 21: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/21.jpg)
cs431-cotter 21
Overview
• System Overview• Linux Processes• CPU Scheduler• Process Synchronization• Memory Management• Input / Output• File Systems • Security
![Page 22: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/22.jpg)
cs431-cotter 22
Figure 10-12. (a) Process A’s virtual address space. (b) Physical memory. (c) Process B’s virtual address space.
Memory Management in Linux (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
(a) (b) (c)
![Page 23: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/23.jpg)
cs431-cotter 23
Figure 10-13. Two processes can share a mapped file.
Memory Management in Linux (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
(a) (b) (c)
![Page 24: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/24.jpg)
cs431-cotter 24
Figure 10-16. Linux uses four-level page tables.
Physical Memory Management (3)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 25: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/25.jpg)
cs431-cotter 25
Figure 10-17. Operation of the buddy algorithm.
Memory Allocation Mechanisms
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
(a) (b) (c) (d) (e) (f) (g) (h) (i)
![Page 26: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/26.jpg)
cs431-cotter 26
Overview
• System Overview• Linux Processes• CPU Scheduler• Process Synchronization• Memory Management• Input / Output• File Systems • Security
![Page 27: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/27.jpg)
cs431-cotter 27
Figure 10-22. The Linux I/O system showing one file system in detail.
Implementation of Input/Output
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 28: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/28.jpg)
cs431-cotter 28
Overview
• System Overview• Linux Processes• CPU Scheduler• Process Synchronization• Memory Management• Input / Output• File Systems • Security
![Page 29: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/29.jpg)
cs431-cotter 29
System Organization
• Like UNIX...
• Predefined root directory structure with preferred locations for kernel files
/ (root)
bin
boot
dev
etc
home
lib
mnt
proc
root
sbin
tmp
usr
var
![Page 30: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/30.jpg)
cs431-cotter 30
Figure 10-24. (a) Before linking. (b) After linking.
The Linux File System (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 31: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/31.jpg)
cs431-cotter 31
Figure 10-25. (a) Separate file systems. (b) After mounting.
The Linux File System (3)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 32: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/32.jpg)
cs431-cotter 32
Figure 10-30. File system abstractions supported by the VFS.
The Linux Virtual File System
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 33: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/33.jpg)
cs431-cotter 33
Figure 10-31. Disk layout of the Linux ext2 file system.
The Linux Ext2 File System (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 34: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/34.jpg)
cs431-cotter 34
Figure 10-34. The relation between the file descriptor table, the open file description table, and the i-node table.
The Linux Ext2 File System (4)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 35: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/35.jpg)
cs431-cotter 35
Journal File Systems
• Designed to speed file system recovery from system crashes.
• Traditional systems use an fs recovery tool (e.g. fsck) to verify system integrity
• As file system grows, recovery time grows. • Journal File Systems track changes in meta-data
to allow rapid recovery from crashes
![Page 36: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/36.jpg)
cs431-cotter 36
Journal File System
• Uses a version of a transaction log to track changes to file system directory records.
• If a system crash occurs, the transaction log can be reviewed back to a check point to verify any pending work (either undo or redo).
• For large systems, recovery time goes from hours or days to seconds.
![Page 37: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/37.jpg)
cs431-cotter 37
Journal File System - Examples
• ReiserFS– Designed originally for Linux (32 bit system)– Supports file systems to 2TB -> 16TB– Journal support of meta-data– Btree structure supports large file counts– Supports block packing for small files– No fixed inode allocation - more flexible.
![Page 38: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/38.jpg)
cs431-cotter 38
Figure 10-35. Examples of remote mounted file systems. Directories shown as squares, files shown as circles.
NFS Protocols
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 39: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/39.jpg)
cs431-cotter 39Figure 10-36. The NFS layer structure
NFS Implementation
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 40: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/40.jpg)
cs431-cotter 40
Overview
• System Overview• Linux Processes• CPU Scheduler• Process Synchronization• Memory Management• Input / Output• File Systems • Security
![Page 41: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/41.jpg)
cs431-cotter 41
Figure 10-37. Some example file protection modes.
Security In Linux
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 42: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/42.jpg)
cs431-cotter 42
Figure 10-38. system calls relating to security.
Security System Calls in Linux
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 43: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/43.jpg)
cs431-cotter 43
Summary
• System Overview• Linux Processes• CPU Scheduler• Process Synchronization• Memory Management• Input / Output• File Systems • Security
![Page 44: Cs431-cotter1 Linux Operating System Review Chapter 10](https://reader035.vdocuments.net/reader035/viewer/2022062305/56649d6e5503460f94a4faa8/html5/thumbnails/44.jpg)
cs431-cotter 44
Questions• What command would be needed to print the last 250
characters of a file “data.txt”• What function can a parent process use to capture the
exit code from a child process?• In terms of Linux scheduling what is a runqueue?• How does Linux use the Buddy algorithm to allocate
memory for a process?• What information is kept in an open file description table
that isn’t kept anywhere else?• What is the primary advantage of a journaling file system
over earlier file systems (such as ext2fs)?