Chapter 12 Summary

Chapter 12 Summary

SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 2 SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.2 4 Operating System Components • Process management Chapter 12 • Main memory management Summary • File management • I/O management • Secondary storage management • Networking • Security • Command Interpreter SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.1 3 SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.3 5 Concurrency UNIX Flavours A concurrent system consists of a set (with at least two elements) of threads of control or processes that UNIX • execute (essentially) independently BSD System V • may access common resources OpenBSD Ultrix • may communicate with each other SunOS 4 NetBSD Linux HPUX = Solaris 1.4 Solaris 2 OSF1 FreeBSD IRIX AIX MacOS X True64 Unix POSIX SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.4 6 SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.6 8 Bash Summary man bash (ctd.) • Complex language • Redirection: command args < infile > outfile 2>> errfile • Context-sensitive lexing • Aliases: “The rules […] are somewhat confusing”. • Complete imperative control structures “For almost every purpose, aliases are superseded by shell • Mostly dynamic binding (static binding with local) functions.” • Iterated expansion mechanisms — functional flavour • Functions: local variables need to be declared local • Arithmetic evaluation, conditional expressions • Concise syntax for command-line interaction • Simple command expansion, command execution • Shell scripts need documentation! environment • Shell scripts need robustness! • Signals, job control • Shell scripts need security awareness! • Prompting, readline, history, history expansion • Shell builtin commands SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.5 7 SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.7 9 man bash Expansion • Options: shell mode, and set options • Brace expansion: a{d,c,b}e → ade ace abe • Invocation: shell modes, initialisation, sh emulation • Tilde expansion: Home directories ~user and ~ • Shell Grammar: simple commands, pipelines, lists, • Parameter and variable expansion: $varname compound commands, function definitions with default: $varname:-default • Quoting: special characters in different contexts various string manipulations possible • Parameters: • Command substitution: $(command) or `command` • Arithmetic expansion: $((expression)) – positional parameters (arguments) • Process substitution: (obtaining FIFOs for processes) – special parameters $[*@#?-$0_] • Word splitting: results of parameter expansion, command – shell variables $BASH*, $HOSTNAME, $PWD, $HOME, $PS1 substitution, and arithmetic expansion are split into words – user-defined variables (outside "...") – array variables • Pathname expansion (globbing): dir*/file?.[coh] • Expansion: “seven kinds”! • Quote Removal SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.8 10 SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.10 12 Disk Organization File Tables in UNIX In-memory Inode Table • One boot control block per disk — information for booting • For each open file a single copy of its file control blocks an OS from that disk. • Acts as cache for file control blocks • Several partitions: System File Table – partition control block: partition size, block size, block • one entry per active open management data structures (free block count, free bolck • contains reference to in-memory inode pointer, free FCB count, free FCB pointer) • current position, access rights, access mode – directory structure File Descriptor Table – File Control Blocks (FCBs) — in UNIX: inode: • one per process — copied by fork – Ownership, premission information • contains reference to system file table entry • In user space, references to file descriptors are int indexes – Location of data blocks into this table. • file locks — not copied by fork SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.9 11 SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.11 13 inodes in Detail Building Software Packages From Source – mode (permissions) • source-code only – number of hard links — look for main module, config.h; read; compile… – owner, group • README-based – timestamps: modification mtime, access atime, change — read README, INSTALL; follow instructions ctime • Makefile-based – size (in bytes) – edit configuration part of Makefile – number of blocks allocated – make all – Pointers to allocated blocks: – make install (as root) – 12 direct block pointers to the first data blocks of the file • configure-based (GNU auto-tools) – one single indirect pointer, points to a block containing – ./configure --help — notice enable* and with* options pointers to the next (blocksize / pointersize) data blocks – ./configure --prefix=/usr/local/packages/XYZ – one double indirect pointer – make — sometimes separately: make doc html ps – one triple indirect pointer – make install (as root) SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.12 14 SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.14 16 Process Management Overview Context Switch Steps •A process is a program in execution (Assuming a user process is interrupted) • The CPU is shared among the processes ready to run – CPU senses interrupt – Only one process can run at a time – CPU starts the interrupt handler in privileged mode – (Interrupt handler may disable all interrupts) – The CPU is rapidly switched between processes — “context switch” – Interrupt handler stores state of interrupted process – Interrupt handler executes (kernel) code for the • Processes communicate with the OS using system calls interrupt • A process can be interrupted at any time by a device – Interrupt handler ends by calling the CPU scheduler interrupt or a system call – CPU scheduler loads the state of the process it selects • A process is represented by a data structure called a process – (Interrupt handler would re-enable interrupts) control block (PCB) or a process descriptor – CPU switches back to user mode and executes selected process SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.13 15 SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.15 17 Context Switching Process Scheduling A context switch saves the state of the current running • All processes are on the job queue / process table process and then loads the state of the next process to – Some ready processes may be swapped to disk. be executed. – Processes in memory that are ready to execute are also on the ready queue It needs to save enough information about the current – Processes waiting for an I/O device are also on its device running process so that it can be resumed later as if queue nothing had happened. This determines important • The job scheduler selects processes from the job queue to components of the PCB. load into and out of memory A context switch is initiated by an interrupt: • When the CPU is free, the CPU scheduler selects one process from the ready queue to be executed by the CPU – software interrupt (system call) – A process can run until a timer interrupt or some other – device interrupt interrupt occurs – timer interrupt (quantum expired) – The CPU scheduler is called after the processing of each interrupt SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.16 18 SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.18 20 Unix-Style Process Creation Signal Lifecycle, Long Version Process creation in Unix involves four system calls: 1. A signal is generated and directed to a process 2. If the process ignores this signal, the signal is discarded • fork: Creates an exact copy of the calling process — KILL, STOP cannot be ignored – Returns process id of child to parent 3. If the process blocks this signal, it is kept pending until the process unblocks it – Returns 0 to child — KILL, STOP cannot be blocked • execve: Overwrites the calling process’s program 4. Otherwise, the signal is delivered to the process 5. Once delivered, the signal must be handled • exit: Causes the calling process to terminate – The default action is to terminate the process; • the process is stopped by STOP (^Z), TTIN, TTOU, – Returns process id to waiting processes TSTP (^S — type ^Q to continue) • CONT continues the process; CHLD is ignored • wait: Causes the calling process to wait until one of its – The default action is not taken if a signal handler has been children exits installed for catching the signal – Returns process id of exited child to process — KILL, STOP cannot be caught SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.17 19 SFWR ENG 3BB4 — Software Design 3 — Concurrent System Design 12.19 21 Interruption by Signals Pipes • Signals are a special kind of IPC “messages” • Pipes are kernel data structures for inter-process • A process can install signal handlers communication • (Most) unhandled signals terminate the process • int pipe(int filedes[2]); • Signals can arrive at any time • Linux: pipe creates a pair of file descriptors, pointing to a • Signals can interrupt certain system calls — EINTR pipe inode, and places them in the array pointed to by filedes. #include <errno.h> /* r_wait.c */ filedes[0] is for reading, filedes[1] is for writing. < > #include sys/wait.h • “The POSIX standard does not specify what happens if a process tries to write to filedes[0] or read from filedes[1].” pid_t r_wait(int *stat_loc){ int retval; • Solaris: The pipe() function creates an I/O

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    14 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us