INFO1218 Operating System Fundamentals: System Calls and Processes PDF

Summary

This document covers the fundamentals of operating systems, focusing on system calls and processes. Topics include CPU operation, multitasking, interrupts, and device controllers. The content appears to be from a university course named INFO1218.

Full Transcript

Lesson 2-1 System Calls & Processes Multitasking Interrupts User & Kernel Modes System Calls INFO1218 Operating System Fundamentals 3 The CPU can only execute one task at a time The CPU operates much faste...

Lesson 2-1 System Calls & Processes Multitasking Interrupts User & Kernel Modes System Calls INFO1218 Operating System Fundamentals 3 The CPU can only execute one task at a time The CPU operates much faster than the other components of the computer  CPU runs at multiples speeds of the system bus  Hard drive read and write operations are very slow compared to CPU cycles There are several methods to increase CPU utilization by organizing jobs for the processors to perform when it is waiting for disk read/writes or other input/output operations  Keyboard input or video output to monitor  Print jobs Multiprogramming, Multitasking, Multiprocessing & Multithreading INFO1218 Operating System Fundamentals 4 Multiprogramming  Increased CPU utilization by loading multiple programs into memory at the same time  The O/S switched the processor between each programs jobs so the processor was not idle  One program runs until it reaches a point were it releases control so another program can run  Co-operative multitasking Multitasking  Method used on modern operating systems  Runs several programs at the same time as multiprogramming – Logical extension of multiprogramming  Also runs other system tasks  CPU assigns time slices to each running process  Appears as if several programs are running at same time INFO1218 Operating System Fundamentals 5 Multiprocessing  Multiple CPUs processors on a motherboard  Multiple processor cores in same CPU package  Program instructions are directed to the different processors so several instructions can be completed at same time Multithreading  Requires multiple processors  Several strings of commands can be directed to different processors to be executed in parallel  Speeds up execution of a program https://gabrieletolomei.wordpress.com/miscellanea/operating- systems/multiprogramming-multiprocessing-multitasking-multithreading/ INFO1218 Operating System Fundamentals 6 The processor switches between multiple jobs Each process or job is scheduled based on equal time  Time slice Pre-emptive multitasking  Stop current process execution and return to a previous process Since user interaction is slow each process appears to run simultaneously INFO1218 Operating System Fundamentals 7 Operating systems are interrupt driven The O/S may be executing commands for a process when a packet arrives at the network interface card (NIC) An interrupt will be sent from the NIC to the CPU along the control bus  Hardware interrupts come from a device controller O/S suspends execution of the current process to service the arriving packets INFO1218 Operating System Fundamentals 8 The O/S will sit idle unless it has a process to execute The O/S waits for an event to initiate action Event can be a user opening an executable program A hardware device requiring action Most actions performed by the operating system are triggered by either a hardware or software interrupt INFO1218 Operating System Fundamentals 9 A device controller manages a specific device An application program executes code that requires interaction with a device. Applications do not have direct access to devices so a system call is initiated from the application to the operating system The O/S takes over and issues the appropriate instructions to the CPU  The CPU sends commands and data to the device controller by writing to local buffers (memory) in the controller The device controller has the instruction required to perform the actions requested by the CPU INFO1218 Operating System Fundamentals 10 The device controller signals an interrupt to notify the CPU that the requested task is complete The CPU stops its current task to service the interrupt The value of the interrupt is a pointer to a data structure called the interrupt vector The interrupt vector points to the memory address of the service routine with instructions to handle the device request  Called an interrupt handler  The table of interrupt vectors is stored in low memory locations The operating system then passes the results back to the application program INFO1218 Operating System Fundamentals 11 A device can also issue a hardware interrupt when an event happens The interrupt is a request to the O/S to service the device  Key pressed on keyboard  Data arrives at Network Interface Card (NIC) INFO1218 Operating System Fundamentals 12 A trap or exception is a software interrupt from applications or system programs Request for a specific service or action be performed  Save data to disk, send to printer  When a software error has occurred: o Division by zero o Invalid memory access o Attempts by a program to modify another running programs data INFO1218 Operating System Fundamentals 13 The O/S supports multiple privilege levels that are used to protect both the system hardware and operating system These privilege levels restrict the CPU instructions that can be used by programs running at a particular level Source - https://en.wikipedia.org/wiki/Protection_ring INFO1218 Operating System Fundamentals 14 In the original model Ring 0 is the level with the most privileges and interacts directly with the physical hardware such as the CPU and memory. Rings 1 & 2 give privileges to hardware device drivers Ring 3 was for User applications  Programs at ring 3 are not permitted to access hardware at Ring 0 Most operating systems only supported 2 modes operation  Ring 0 & Ring 3 Source - https://en.wikipedia.org/wiki/Protection_ring INFO1218 Operating System Fundamentals 15 Both Windows and Linux use two levels of protection: User Mode  Prevents access to system instructions that can damage the hardware, damage the kernel or gain access to other processes o Ring 3 Kernel Mode  Also called Privilege Mode, Supervisor Mode or System Mode o Ring 0 Hardware that support virtualization often use more levels  Virtual box and VMware put the guest kernel code in ring 1 o The guest operating system has more privileges than user applications but not full kernel mode privileges INFO1218 Operating System Fundamentals 16 A computer may have multiple users and run multiple processes at the same time (concurrent) Access to data must be controlled so that only the proper authorized user or process has access to that data Processes only execute in their assigned address space Processes and file permissions are tied to a User ID Privilege escalation allows a user to change to an effective ID with more rights  Run as administrator – Windows  sudo - Linux INFO1218 Operating System Fundamentals 17 Operating systems provide many services  File management, print services User applications and system programs access these services via system calls  A system call is a request by a user program to perform a task reserved for the operating system A system call is a programming interface to the operating system with a request to switch from user mode to privileged mode Typically written in a high-level language (C or C++) Calls directed to hardware devices could be written in low level assembly language INFO1218 Operating System Fundamentals 18 The relationship between users/applications and the operation system services Via system calls. Source: Fig. 2.1 INFO1218 Operating System Fundamentals 19 The CPU uses a mode bit to determine the level of privilege operation  Kernel Mode = 0 & User Mode = 1 When a user application is started the mode bit is set to 1 When the user application requires a privileged action it must make a System Call (trap or interrupt) to the O/S The O/S switches to Kernel Mode 0 and performs the operation Source: Fig. 1.10 INFO1218 Operating System Fundamentals 20 System calls are programmed directly Programming language compilers and interpreters include libraries to make using system calls easier  These libraries are sometimes called Application Programming Interfaces (APIs)  The API specifies a library of available functions that the application programmer can access Windows API  Windows API functions are located in dynamic link libraries (dlls)  Kernel32dll, User32dll, shell32dll, Gui32.dll INFO1218 Operating System Fundamentals 21 Details of the O/S interface are hidden from the programmer by the API Source: Fig. 2.6 INFO1218 Operating System Fundamentals 22 Generally, systems provide a library or API that sits between normal programs and the operating system. On Unix-like systems, that API is usually part of an implementation of the C library (libc), On Windows NT, that API is part of the Native API, ntdll.dll library INFO1218 Operating System Fundamentals 23 A function call is the loading of a piece of code into user space to perform a specific task. When this task or subroutine is complete control is passed back to the main program The C standard library provides numerous built-in functions that a program can call. A function often in the process of its execution will do a system call INFO1218 Operating System Fundamentals 24 A program is a passive entity  Just a block of instruction code stored on disk A process is an active entity  Process is an executing program Each process is given a process id (PID) The user may be running several programs at the same time and each will be a separate process  Running a word processor  Browsing the Internet  Listening to music When a process is terminated assigned memory space is released back to the O/S for other processes INFO1218 Operating System Fundamentals 25 A register is a small memory area that is built into a CPU Each process instruction and its related data must be loaded from memory into registers before the instruction can be executed by the CPU Each process is given a unique number  Process id (pid) A program counter is a special register that indicates the next instruction be executed The contents of the registers and counter must be saved when a computer is multitasking and switching between each active process INFO1218 Operating System Fundamentals 26 Each process has a Process Control Block (PCB)  Information used by the operating system to monitor and manage a process On a multi-tasking systems processes do not run continuously, so the program counter and register portions of the PCB are used to store these values when the process is not actually running Source: Fig. 3.3 INFO1218 Operating System Fundamentals 27 New - The process is being created  Assigned Process ID (PID) & memory addresses (stack & heap) Running - Instructions are being executed  Program counter Waiting - The process is waiting for some event to occur  Interrupt Ready - The process is waiting to be assigned to a processor  Time slice Terminated - The process has finished execution INFO1218 Operating System Fundamentals 28 The operating system assigns a dedicated memory space to each process id (PID) dived as follows:  Code segment (text) - Binary executable code (read only)  Initial Data segment - Assigned variables for the process  BSS o Block Started by Symbol o Variables without a default value  Heap - Memory allocated for use by process  Stack - Temporary space for functions called by the process  Base and Limit registers o Define the protected memory area addresses for a process INFO1218 Operating System Fundamentals 29 Each process is allocated dynamic High memory address memory addresses called a heap  Storing data calculated by an instruction A process may also be allocated dynamic memory space called a stack  The stack is assigned memory space (buffers) at the highest usable memory location and grows downwards  The stack holds temporary user input variables into a program such as a number entered into calculator program Low memory address INFO1218 Operating System Fundamentals 30 A text mode interface where users interact with programs via a keyboard and screen using only simple text characters Command line interfaces are often called shells or command interpreters  Operate at Ring level 3 the outer shell with the kernel in the middle Widely used for system administration purposes due to its flexibility and efficiency. Command line interfaces are available on Windows, Mac OSX and Linux INFO1218 Operating System Fundamentals 31 Commands used at the CLI can be either built into the shell or external. Built-in commands are part of the shell program and always run within the process running the shell External commands are separate programs that a shell loads and executes There is often no visible difference between the use of internal or external commands from the user’s perspective Windows shells  Command Prompt (based on the original MS-DOS shell)  PowerShell ( a new shell with much more functionality built into it) INFO1218 Operating System Fundamentals 32 Many Linux servers have CLI only, no GUI environment running  Common configuration on servers for performance and security reasons Linux desktop with GUI environment running will have CLI access via terminal application Bash (Bourne again shell) - Most widely-used shell Bourne shell (sh) - One of the oldest Unix/Linux shells Korn shell (ksh) - Tiny shell (tsh)  Small, limited functionality shell for systems with limited resources INFO1218 Operating System Fundamentals 33 Pointing devices (mouse) for input operations  Click on image or icon as input to operating system Keyboards for text input Multiple windows can be displayed at once, but the user can only interact with one application (and its window) at a time Mobile systems include a touch screen that can combine keyboard, pointing device and basic screen functionality into a single device INFO1218 Operating System Fundamentals 34 CDE – Common Desktop Environment X–Windows  IBM AIX, SUN Solaris KDE – K Desktop Environment GNOME INFO1218 Operating System Fundamentals 35 Silberschatz, A., Galvin, P.B., Gagne, G., Operating System Concepts, Essentials 10th Edition John Wiley & Sons, Inc., 2014 (the course textbook) Chapter 1 Pg. 21-23, 43-47 Chapter 2 Pg. 62-71, 78-81 Chapter 3 Pg. 105-110 INFO1218 Operating System Fundamentals 36

Use Quizgecko on...
Browser
Browser