1 / 83

Introduction to Operating Systems

Introduction to Operating Systems. CS 499: Special Topics in Cyber Security S. Sean Monemi. Overview. Operating Systems Definition Processes and Threads Program Control Blocks Process Scheduling and Interrupts. What is an Operating System.

falala
Download Presentation

Introduction to Operating Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Operating Systems CS 499: Special Topics in Cyber Security S. Sean Monemi

  2. Overview • Operating Systems Definition • Processes and Threads • Program Control Blocks • Process Scheduling and Interrupts

  3. What is an Operating System • A program that acts as an intermediary between a user and the computer hardware • Operating system goals: • Make the computer system convenient to use • Use the computer hardware in an efficient manner • Execute user programs and make solving user problems easier

  4. What is an Operating System • The operating system is that portion of the software that runs in Kernel mode or Supervisormode • It performs two basic unrelated functions: • Extending the machine • Managing resources

  5. What is an Operating System • An extended machine • Hides the messy details which must be performed • Presents user with a virtual machine, easier to use • Controls the execution of user programs and operations of I/O devices • Resourcemanager (allocator) • Manages and allocates resources • Each program gets time with the resource • Each program gets space on the resource

  6. Example • A computer system consists of • hardware • system programs • application programs

  7. Process

  8. Introduction • Computers perform operations concurrently • Examples: • compiling a program • sending a file to a printer • rendering a Web page • playing music • receiving e-mail • Process – an abstraction of a running program • The terms joband processused almost interchangeably

  9. Process Definition • Process • Processes enable systems to perform and track simultaneous activities • A program in execution; process execution must progress in sequential fashion • Processes transition between process states • Operating systems perform operations on processes such as creating, destroying, suspending, resuming and waking • A process includes: • program counter • stack • data section

  10. Definition of Process • A program in execution • A process has its own address space consisting of: • Text region • Stores the code that the processor executes • Data region • Stores variables and dynamically allocated memory • Stack region • Stores instructions and local variables for active procedure calls

  11. Processes • Multiprogramming of four programs • Conceptual model of 4 independent, sequential processes • Only one program active at any instant

  12. Process Creation Ways to cause process creation • System initialization • Execution of a process creation system • User request to create a new process • Initiation of a batch job

  13. Process Termination Conditions which terminate processes • Normal exit (voluntary) • Error exit (voluntary) • Fatal error (involuntary) • Killed by another process (involuntary)

  14. Process Management • OS provide fundamental services to processes: • Creating processes • Destroying processes • Suspending processes • Resuming processes • Changing a process’s priority • Blocking processes • Waking up processes • Dispatchingprocesses • Interprocess communication (IPC)

  15. Process States • A process moves through a series of discrete process states: • Runningstate • The process is executing on a processor • Instructions are being executed, using CPU • Readystate • The process could execute on a processor if one were available • Runnable; temporarily stopped to let another process run • Blockedstate • The process is waiting for some event to happen before it can proceed • Unable to run until some external event happens

  16. Process Transitions • State Transitions 4 possible state transitions: • ready to running: • when a process is dispatched • running to ready: • when the quantum expires • running to blocked: • when a process blocks • blocked to ready: • when the event occurs

  17. Suspend and Resume • Suspending a process • Indefinitely removes it from contention for time on a processor without being destroyed • Useful for detecting security threats and for software debugging purposes • A suspension may be initiated by the process being suspended or by another process • A suspended process must be Resumedby another p • Two suspended states: • suspendedready • suspendedblocked

  18. Process Hierarchies • Parent creates a child process, child processes can create its own process • Forms a hierarchy • UNIX calls this a "process group“ • Windows has no concept of process hierarchy • all processes are created equal

  19. Process Control Blocks (PCBs)Process Descriptors

  20. Process Control Blocks • PCBs maintain information that the OS needs to manage the process • Typically include information such as • Process identification number (PID) • Process state • Program counter • Scheduling priority • Credentials • A pointer to the process’s parent process • Pointers: • to the process’s child processes • to locate the process’s data and instructions in memory • to allocated resources

  21. Process Control Blocks • Process table • The OS maintains pointers to each process’s PCB in a system-wide or per-user process table • Allows for quick access to PCBs • When a process is terminated, the OS removes the process from the process table and frees all of the process’s resources Process table and process control blocks

  22. Context Switching • Context switches • Performed by the OS to stop executing a running process and begin executing a previously ready process • Save the execution context of the running process to its PCB • Load the ready process’s execution context from its PCB • Must be transparent to processes • Require the processor to not perform any “useful” computation • OS must therefore minimize context-switching time • Performed in hardware by some architectures

  23. Threads

  24. The Thread Model (a) Three processes (unrelated) each with one thread, each of them with a different address space (b) One process with three threads (part of the same job), (Multithreading), all three of them share the same address space

  25. The Thread Model Each thread has its own stack • Each thread designate a portion of a program that may execute concurrently with other threads

  26. Thread Definition • Processes are used to group resources togetherand threads are the entities scheduled for execution on the CPU • A traditional or heavyweight process is equal to a task with one thread • A thread (orlightweight process) is a basic unit of CPU utilization; it consists of: • program counter • register set • stack space • Thread shares with its peer threads: • code section • datasection • OS resources • collectively known as a task

  27. The Thread Model Items shared by all threads in a process Items private to each thread

  28. Thread States • Thread states • Born state • Ready state (runnable) • Running state • Deadstate • Blocked state • Waiting state • Sleeping state • Sleep interval specifies for how long a thread will sleep

  29. Thread Operations • Threads and processes have common operations • Create • Exit (terminate) • Suspend • Resume • Sleep • Wake

  30. The Thread Library Multithreading Library Procedure Calls: • thread_create • Thread has the ability to create new threads • thread_exit • When a thread has finished its work, it can exit • thread_wait • One thread can wait for a (specific) thread to exit • thread_yield • Allows a thread to voluntarily give up the CPU to let another thread run

  31. Windows XP Threads • Windows XP threads can create fibers • Fiber is similar to thread • Fiber is scheduled for execution by the thread that creates it • Thread is scheduled by the scheduler • Windows XP provides each process: • with a thread pool that consists of a number of worker threads, which are kernel threads that execute functions specified by user threads Windows XP thread state-transition diagram

  32. Linux Threads • Linux allocates the same type of process descriptor to processes and threads (tasks) • Linux uses the UNIX-based system call fork to spawn child tasks • To enable threading, Linux provides a modified version named clone • Clone accepts arguments that specify which resources to share with the child task Linux task state-transition diagram

  33. Thread Usage A word processor with three threads • T1 – interact with user • T2 – handles reformatting • T3 – save to disk

  34. Thread Usage A multithreaded Web server • (a) Dispatcher thread • (b) Worker thread

  35. Threading Models • Three most popular threading models • User-level threads • Kernel-level threads • Hybrid- level threads (Combination of user-level and kernel-level threads)

  36. User-level Threads • - Thread Management done by User-Level Threads Library • supported above the kernel, via a set of library calls at the user level • - Each process has its own private thread table • to keep track of the threads in that process, • such as thread’ PC, SP, RX’s, state, etc. • -The thread table is managed by the • run-time system • Many-to-one thread mappings • OS maps all threads in a multithreaded • process to single execution context • Examples: • POSIX Pthreads • Mach C-threads • Solaris threads A user-level threads package

  37. Implementing Threads in User Space • Advantages: • They can run with existing OS • Thread switching is faster than trapping to the kernel • no trap and context switch is needed • the memory cache need not be flashed • Thread scheduling is very fast • local procedures used to save the thread’s state and the scheduler • Each process has its own customized scheduling algorithm • Better scalability • kernel threads invariably require some table and stack space in the kernel

  38. Implementing Threads in User Space • Disadvantages: • The problem of how blocking system calls are implemented • a thread reads from the keyboard before any keys have been hit • letting the thread actually make the system call is unacceptable • (this will stop all the threads) • Kernel blocking the entire process • if a thread causes a page fault, the kernel, not even knowing about the existence of threads, naturally blocks the entire process until the disk I/O is complete, even though other threads might be runnable • If a thread starts running, no other thread in that process will ever run unless the 1st thread voluntary gives up the CPU • unless a thread enters the run-time system of its own free will, the scheduler will never get a chance

  39. Implementing Threads in the Kernel • Supported by the Kernel • - kernel know about & manage threads • - no run-time system is needed in each process • - no thread table in each process • Kernel has a thread table • - thread table keeps track of all threads in the system • Thread makes a kernel call • - when a thread wants to create a new thread • - when a thread wants to destroy an existing thread • - updates the kernel thread table • Examples • - Windows 95/98/NT • - Solaris • - Digital UNIX A threads package managed by the kernel

  40. Implementing Threads in the Kernel • Kernel-level threads attempt to address the limitations of user-level threads by mapping each thread to its own execution context • Kernel-level threads provide a one-to-one thread mapping • Advantages: • Increased scalability, interactivity, and throughput • Disadvantages: • Overhead due to context switching and reduced portability due to OS-specific APIs • Kernel-level threads are not always the optimal solution for multithreaded applications

  41. Hybrid Implementations • The combination of user- and kernel-level thread implementation • Many-to-many thread mapping (m-to-n thread mapping) • Number of user and kernel threads need not be equal • Can reduce overhead compared to one-to-one thread mappings by implementing thread pooling

  42. Pop-Up Threads • Threads are frequently useful in distributed system • No more of traditional approach to have a thread that is blocked on a receive system call waiting for an incoming message • Pop-up thread - Creation of a new thread caused by the arrival of a new message (a) before message arrives (b) after message arrives

  43. Java Multithreading • Java allows the application programmer to create threads that can port to many computing platforms • Threads • Created by class Thread • Execute code specified in a Runnable object’s run method • Java supports operations such as naming, starting and joining threads

  44. Java Multithreading • Java allows the application programmer to create threads that can port to many computing platforms • Threads • Created by class Thread • Execute code specified in a Runnable object’s run method • Java supports operations such as naming, starting and joining threads Java threads being created, starting, sleeping and printing

  45. Java Multithreading

  46. Processor Scheduling

  47. Scheduling Concepts • Scheduling is a fundamental OS function • Scheduling is central to OS design • Almost, all computer resources are scheduled before use • Maximum CPU utilization obtained with multiprogramming • CPU scheduling is the basics of multiprogrammed OS • Scheduler – the part of OS that makes the decision which process (in ready state) to run next

  48. Scheduling Concepts CPU–I/O Burst Cycle The success of CPU scheduling, depends on the following observed property of processes: • Process execution consist of: • a cycle of CPU execution • and I/O wait. • Process alternate back and forth between theses two states.

  49. Scheduling ConceptsAlternating sequence of CPU and I/O bursts • Process execution begins with: • a CPU burst • then an I/O burst • then another CPU burst • then another I/O burst • …..and so on • Eventually, the final CPU burst ends with a • system request to terminate execution, rather than with another I/O burst

  50. SchedulingHistogram of CPU-burst times • Bursts of CPU usage alternate with periods of I/O wait • a CPU-bound program might have a few long CPU bursts • an I/O-bound program typically will have many short CPU bursts

More Related