Operating Systems Concepts PDF
Document Details
Uploaded by SupportingRhodochrosite
UP Los Baños
JPVJAlbacea and JACHermocilla
Tags
Summary
This document discusses operating system concepts, including the kernel, command language interpreters, processes, interrupts, device drivers, and buffering. It also explains time-sharing systems and utilities.
Full Transcript
Chapter 2: Operating Systems Concepts Prepared by: JPVJAlbacea and JACHermocilla The Kernel - Core of an operating system that provides basic services to all parts of the operating system. - Usually are memory resident - Are made as small as possible but still provide the services - Functions...
Chapter 2: Operating Systems Concepts Prepared by: JPVJAlbacea and JACHermocilla The Kernel - Core of an operating system that provides basic services to all parts of the operating system. - Usually are memory resident - Are made as small as possible but still provide the services - Functions: - Handling interrupts - Managing the computer memory and allocating it - Scheduling the work done by the CPU - Organizing the transfer of data - Accepting instructions from shell and carrying them out - Enforcing access permissions The Kernel Command Language Interpreters -Responsible for taking commands of users and passing it to the operating system - In UNIX systems, they are called shells - Provides function for: - Creating an environment that the user needs - Writing shells scripts - Defining command aliases - Manipulating the command history - Editing command line - Examples of shells are the Bourne shell(sh) and C shell (csh) Command Language Interpreters Processes - A unique execution of a program with a specific data - A program is the static description of an algorithm while a process is a dynamic view of the program - Can be one of two types: user process or system process Processes - One lifetime of an “edit” process: a. A user wanting to use the system may type the name of a program he wants to execute or use (say, program "edit") on the keyboard. b. The command interpreter of the operating system parses the command and locates the executable program "edit" on the disk. c. A new process is created, with an associated address space. d. Sufficient memory (RAM) is allocated to run "edit". e. The executable binary code of "edit" is read from the disk and loaded into the allocated memory. f. The CPU registers are initialized to appropriate initial values. g. The new process corresponding to program "edit" is started by executing a jump to the starting address of "edit" in memory. h. During execution, the process may request some operating system services by making system calls like open a file, get the current date, and display a character on the screen. i. The process may change its status during execution, i.e., it may be in run, blocked or ready status. j. When the process terminates, resources (e.g., RAM, address space, and open file handles) allocated to the process are reclaimed. Interrupts - An event that causes normal execution to be altered - Some conditions when an interrupt occurs: - Completion of an I/O operation - Errors in the process being executed - Arrival of messages from another system - Arrival of data from I/O devices Interrupts - Data loss can happen if there are no interrupts Interrupts - Steps for handling interrupts: - Provide an interrupt line - Modify the microcode of the fetch-decode-execute cycle of the CPU - Include the necessary device(or interrupt) handler Image from https://alex.dzyoba.com Image from Wikipedia Device Drivers - Low-level program written to control a device - Written usually in assembly language or systems programming languages like C - Some are placed inside of the operating system and some must be loaded when the device is first connected to the system Device Drivers Responsibilities of a Device driver: - Identifying and configuring the device on system startup - Queueing and scheduling requests originating from user processes and the operating system itself - Device-dependent calculations like translating logical block numbers to surface/track/sector numbers - Servicing device interrupts Device Drivers Device drivers for single-user systems vs multi-user systems: - Single-user systems use a polling loop to handle the actions it has to take. - Multi-user systems uses interrupts to move control to different processes while other processes wait for their data (for efficiency) - Direct Memory Access (DMA) - allows the device to transfer data directly to memory without CPU Image from https://www.boardinfinity.com Device Drivers Structure of device driver code: 1. Initialization code - called at system startup 2. Interrupt handlers (ISRs) and related code 3. Interface to the operating system Device Drivers Instances when device drivers are accessed: - System initialization - System calls from user process - Device interrupts - Bus reset Supervisor or System Calls - An instruction which lets the user access part of system’s area Supervisor or System Calls - Some examples of system calls: Process management s = execve(name, argv, envp) //Replace a process core image s = wait(&status) //Wait for a child to terminate and get its //exit status Signals s = kill(pid, sig) //Send a signal to a process s = pause() //Suspend the caller until the next signal File management fd = creat(name, mode) //Create a new file s = close(fd) //Close an open file Modes of Execution - Processes should not interfere with each other and with the OS - Has two main types: - Kernel Mode - Executions or calls are considered to be trusted and do not need to be checked - Examples are interrupt handlers, device handlers, etc. - Normally cannot be interrupted - Can access memory directly - User Mode - Executions or calls are to be checked - Also known as non-privileged actions - Has to use system calls to be able to change anything in the Modes of Execution - Switching to kernel mode from user mode can happen in the following: - A user process calls on the OS to execute some functions requiring the use of privileged instruction (system calls). - An interrupt is occurs - An error condition occurs in a user process. - When the user completes execution and control is given back to the operating system. Multiprogramming REVIEW: Multiprogramming - The ability of an Operating System to execute one part of a program then switch to another part of the program, and so on and so forth. Context-switching - A way to transfer control from one process to another without losing progress from the previous process Multiprogramming Process Control Block (PCB) - Contains the following for process context: - Program counter - Registers - Flags and other information used by the process Multiprogramming Example: Interrupt handler: disable_interrupt -> save_state -> identify_interrupting_device -> device_handler -> process_dispatcher -> restore_state -> enable_interrupt Multiprogramming Multitasking - The ability to execute more than one user program at a time - It uses only one CPU but can switch quickly between programs that it seems like they are running at the same time. Multiprogramming Example: PCB for Word PCB for Powerpoint PCB for Excel Current running process: Word Multiprogramming Two types: - Cooperative or non-preemptive multitasking - Multitasking where background processes can take control of the CPU and the foreground process will let it. - Processes tend to hog the CPU - Preemptive multitasking - Forces programs to share the CPU - Interrupts are used to force the CPU to serve another program Buffering - A method of improving performance by overlapping some operations - To do this, some memory must be allocated to it, thus the buffer. - Attempts to keep I/O and CPU devices busy all the time Example: Double Buffering Since there is a problem with data loss in a simple buffer, a solution must be made Solution: Circular Buffering Problems may occur in the first two strategies talk about data that comes in burst. To implement a streaming version that will not run out of space: Circular buffering Problems that can be encountered: 1. if input is faster than processing, the buffering process might overtake the user process, overwriting data that has not yet been read. 2. if processing is faster than input, the user process might overtake the buffering process and attempt to read data that has not yet been placed in the buffer. Batch Processing Systems - Executes jobs in batches - Mainly found on mainframe computers that implement uniprogramming - Collects a bunch of jobs first before starting the process and once a process starts, the only way it will go through the jobs is to finish them all Batch Processing Systems Problems: 1. turnaround time may be long, that is the user may have to wait for a long time before getting his/her output. 2. debugging the program is impossible to do. 3. impossible for the user to interrupt the running job. 4. early batch systems have no protection scheme thus it is basically possible for a user process to adversely affect other user jobs or worst the operating system. Spooling - Simultaneous Peripheral Operation OnLine - Instead of directing Input straight into I/O devices, an intermediate device will handle “spooling” of the data while it waits for the device to be freed - Process for transferring from intermediate device to actual I/O device is called a spooler Spooling Two types of spooling: - Offline spooling Spooling Advantages of Offline Spooling: 1. improved efficiency - the system is bounded by the speed of accessing data from magnetic tapes instead of a card reader or a line printer. 2. simplified operating procedure - I/O operations in the main CPU is now simple since there is only one type of device, i.e., magnetic tapes. 3. convenience for remote users - remote users can use their computer to act as the inexpensive processor and just submit the tape. Spooling Disadvantages of Offline Spooling: 1. long turnaround time - the time spent in filling a tape with batch jobs, run the whole tape and print all the output is quite lengthy. 2. no priority or on-line access - the only way of achieving priority in this system is to take the tape containing the priority job and run it first. But even though, this is done, it will still take more time to run all the jobs in that tape. 3. additional hardware required - aside from the two extra satellite processors there is a need for a lot of magnetic tapes. Spooling - Online Spooling: - Generally the same as offline spooling except there is only one CPU and instead of magnetic tapes, the data is is stored in a large capacity disk Spooling Advantages of Online spooling: - Efficient CPU usage - Efficient peripheral usage - Fast turnaround time - High-level scheduling - Virtual I/O is provided Time-sharing systems - Spooling has shown to be effective enough in providing good performance - Spooling is not convenient to users - Because of the above an extension is necessary to the alleviate the problem Time-sharing systems One solution is time sharing systems: Time-sharing systems Advantages of time-sharing systems: - Fast response times - Higher level of multiprogramming Disadvantage of time-sharing systems: - Very high overhead Utilities - Tools provided for housekeeping services that are not available in the kernel Examples: - Anti-virus software - Temperature Conversion Tool - Zip/Unzip software - Date and Time Utility - Disk Defragmenter - Process Viewer - Disk Scanner - Whois - Spam Filter - Man - PDF Viewer - Cat - Firewall