Professional Documents
Culture Documents
Lecture w4 01
Lecture w4 01
Structures
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Examples of Windows and Unix System Calls
Operating System Concepts – 10th Edition 2 Silberschatz, Galvin and Gagne ©2018
Standard C Library Example
• C program invoking printf() library call, which calls write() system call
Operating System Concepts – 10th Edition 3 Silberschatz, Galvin and Gagne ©2018
Example: Arduino
• Single-tasking
• No operating system
• Programs (sketch) loaded via
USB into flash memory
• Single memory space
• Boot loader loads program
• Program exit -> shell reloaded
Operating System Concepts – 10th Edition 4 Silberschatz, Galvin and Gagne ©2018
Example: FreeBSD
• Unix variant
• Multitasking
• User login -> invoke user’s choice of shell
• Shell executes fork() system call to create
process
• Executes exec() to load program into
process
• Shell waits for process to terminate or
continues with user commands
• Process exits with:
• code = 0 – no error
• code > 0 – error code
Operating System Concepts – 10th Edition 5 Silberschatz, Galvin and Gagne ©2018
Linkers and Loaders
• Source code compiled into object files designed to be loaded into any physical
memory location – relocatable object file
• Linker combines these into single binary executable file
• Also brings in libraries for example c standard and c math library
• Program resides on secondary storage as binary executable
• Must be brought into memory by loader to be executed
• Relocation assigns final addresses to program parts and adjusts code and data
in program to match those addresses
• Modern general purpose systems don’t link libraries into executables
• Rather, dynamically linked libraries (in Windows, DLLs) are loaded as needed,
shared by all that use the same version of that same library (loaded once)
• for example, if two processes need C math both use the same one loaded in
memory
• Object, executable files have standard formats, so operating system knows how to
load and start them
Operating System Concepts – 10th Edition 6 Silberschatz, Galvin and Gagne ©2018
The Role of the Linker and Loader
Operating System Concepts – 10th Edition 7 Silberschatz, Galvin and Gagne ©2018
Why Applications are Operating System Specific
Operating System Concepts – 10th Edition 8 Silberschatz, Galvin and Gagne ©2018
Operating System Design and Implementation
Operating System Concepts – 10th Edition 9 Silberschatz, Galvin and Gagne ©2018
Operating System Design and Implementation (Cont.)
Operating System Concepts – 10th Edition 10 Silberschatz, Galvin and Gagne ©2018
Implementation
• Much variation
• Early OSes in assembly language
• Then system programming languages like Algol, PL/1
• Now C, C++
• Actually usually a mix of languages
• Lowest levels in assembly
• Main body in C
• Systems programs in C, C++, scripting languages like PERL, Python,
shell scripts
• More high-level language easier to port to other hardware
• But slower
Operating System Concepts – 10th Edition 11 Silberschatz, Galvin and Gagne ©2018
Operating System Structure
• General-purpose OS is very large program
• Various ways to structure ones
• Simple structure – MS-DOS
• More complex -- UNIX
• Layered – an abstraction
• Microkernel -Mach
Operating System Concepts – 10th Edition 12 Silberschatz, Galvin and Gagne ©2018
Monolithic Structure – Original UNIX
Operating System Concepts – 10th Edition 13 Silberschatz, Galvin and Gagne ©2018
Traditional UNIX System Structure
Beyond simple but not fully layered
Operating System Concepts – 10th Edition 14 Silberschatz, Galvin and Gagne ©2018
Linux System Structure
Monolithic plus modular design
Operating System Concepts – 10th Edition 15 Silberschatz, Galvin and Gagne ©2018
Modules
• Many modern operating systems implement loadable kernel
modules (LKMs)
• Uses object-oriented approach
• Each core component is separate
• Each talks to the others over known interfaces
• Each is loadable as needed within the kernel
• Overall, similar to layers but with more flexible
• Linux, Solaris, etc
Operating System Concepts – 10th Edition 16 Silberschatz, Galvin and Gagne ©2018
Layered Approach
Operating System Concepts – 10th Edition 17 Silberschatz, Galvin and Gagne ©2018
Microkernels
• Moves as much from the kernel into user space
• Mach example of microkernel
• Mac OS X kernel (Darwin) partly based on Mach
• Communication takes place between user modules using
message passing
• Benefits:
• Easier to extend a microkernel
• Easier to port the operating system to new architectures
• More reliable (less code is running in kernel mode)
• More secure
• Detriments:
• Performance overhead of user space to kernel space
communication
Operating System Concepts – 10th Edition 18 Silberschatz, Galvin and Gagne ©2018
Microkernel System Structure
Operating System Concepts – 10th Edition 19 Silberschatz, Galvin and Gagne ©2018
Hybrid Systems
• Most modern operating systems are actually not one pure model
• Hybrid combines multiple approaches to address performance,
security, usability needs
• Linux and Solaris kernels in kernel address space, so monolithic,
plus modular for dynamic loading of functionality
• Windows mostly monolithic, plus microkernel for different
subsystem personalities
• Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa programming
environment
• Below is kernel consisting of Mach microkernel and BSD Unix
parts, plus I/O kit and dynamically loadable modules (called kernel
extensions)
Operating System Concepts – 10th Edition 20 Silberschatz, Galvin and Gagne ©2018
System Boot
Operating System Concepts – 10th Edition 21 Silberschatz, Galvin and Gagne ©2018
Operating-System Debugging
Operating System Concepts – 10th Edition 22 Silberschatz, Galvin and Gagne ©2018
Performance Tuning
Operating System Concepts – 10th Edition 23 Silberschatz, Galvin and Gagne ©2018
Tracing
• Collects data for a specific event, such as steps involved in a system call
invocation
• Tools include
• strace – trace system calls invoked by a process
• Strace command, strace ls
• gdb – source-level debugger
• perf – collection of Linux performance tools
• tcpdump – collects network packets
Operating System Concepts – 10th Edition 24 Silberschatz, Galvin and Gagne ©2018
Linux bcc/BPF Tracing Tools
Operating System Concepts – 10th Edition 25 Silberschatz, Galvin and Gagne ©2018
End of Chapter 2
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018