CPSC 3220 - DAY 6 SEPTEMBER 14, 2017 ================================================================================ Exercises from Chapters: 1, 2, 3 Command Interpreter ("Shell") -Interactive interface to OS system calls -Find executable files associated with a command and creates a process (passing any parameters) -Typically extended as mini-language (control structures, macros, etc) -Shell scripts (batch files, etc) -Start-up files (eg. cshrc, bashrc) and environment variables (predefined macros) -Handles I/O redirection Implementing a Shell Interprocess Communication (IPC) using Pipes It's a queue. pipe allows communication between processes. Allows combination of applications into complex structures. Client-Server IPC Using Pipes Server process can wait on input from multiple client processes using select() Large (or monolithic) kernel provides all or most system services -sometimes called a bloated kernel Microkernel provides minimal services -other services provided by user-mode servers Monolithic means that the kernel handles everything themselves. HAL (hardware abstraction level) - Microkernel Evolution First generation - large amounts of system calls Second generation - less system calls, shorter amounts of time Third generation - Reduction in system calls. Message Passing in Microkernels -Typically define a message object for IPC -Use send() and recieve() operations instead of read/write -Messages may be typed -For checking at compile time or run time -Messages may be buffered in a queue -Also called a channel, endpoint, mailbox, port -Zero-buffer approach is called rendezvous Design Tradeoffs -Performance concerns -Procedure call to library routine is fastest. -Kernel call is slower. -Passing messages to a server process is slowest. -Reliability concerns -Linux 4.11 has 18M lines of code. -seL4 microkernel is 9,7000 lines of C and 500 lines of assembler. -runs on limited number of platforms. Hardware abstraction level - portability across processors, allows rest of OS to be written in a machine-independent manner. All I/O is treated like a file. Motivation for Threads Servers -Multiple connections handled simultaneously Parallel Programs -To achieve better performance Programs with user interfaces -To achieve user responsiveness while doing computation Network and disk bound programs -To hide network/ disk latency. A thread is a single execution sequence that represents a separately schedulable task. -Single execution sequence: familiar programming model -Separately sechedulable: OS can run or suspend a thread at any time. Protection is an orthogonal concept -Can have many threads Threads vs. Process -For Parallel processing involving shared objects, threads are more efficient than processes -Cheaper to create and destroy -Faster to switch among -Communicate through shared memory in single process -But code is hard to get correct when multiple threads can update shared objects. -Non trivial multi-threaded programs are incomprehensible to humans -For most purposes proposed for threads, events are better. Threads should be used only when true CPU concurrency is needed. Thread Abstraction Infinite number of processes Threads execute with variable speed -Programs must be designed to work with any schedule