Operating Systems Process Managment.

Slides:



Advertisements
Similar presentations
1 Processes and Threads Creation and Termination States Usage Implementations.
Advertisements

Scheduling Introduction to Scheduling
Uniprocessor Scheduling Chapter 9 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
CS 149: Operating Systems February 3 Class Meeting
Operating Systems Process Scheduling (Ch 3.2, )
Operating Systems COMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money.
1 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5.
Chapter 2: Processes Topics –Processes –Threads –Process Scheduling –Inter Process Communication (IPC) Reference: Operating Systems Design and Implementation.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
1 Thursday, June 15, 2006 Confucius says: He who play in root, eventually kill tree.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Processes and Threads.
1 Process States (1) Possible process states –running –blocked –ready Transitions between states shown.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 2 Processes and Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
CE Operating Systems Lecture 11 Windows – Object manager and process management.
1 Scheduling The part of the OS that makes the choice of which process to run next is called the scheduler and the algorithm it uses is called the scheduling.
2.5 Scheduling Given a multiprogramming system. Given a multiprogramming system. Many times when more than 1 process is waiting for the CPU (in the ready.
Chapter 5 Processor Scheduling Introduction Processor (CPU) scheduling is the sharing of the processor(s) among the processes in the ready queue.
2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
UNIT–II: Process Management
OPERATING SYSTEM CONCEPT AND PRACTISE
Processes and threads.
CPU SCHEDULING.
Chapter 6: CPU Scheduling
Process Management Process Concept Why only the global variables?
EEE Embedded Systems Design Process in Operating Systems 서강대학교 전자공학과
Chapter 5a: CPU Scheduling
Processes and Threads Processes and their scheduling
Networks and Operating Systems: Exercise Session 2
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 2 Scheduling.
Operating Systems Processes Scheduling.
Processes in Unix, Linux, and Windows
Chapter 2.2 : Process Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Process management Information maintained by OS for process management
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Lecture 8: CPU Scheduling
CPU Scheduling Basic Concepts Scheduling Criteria
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Introduction What is an operating system bootstrap
Processes in Unix, Linux, and Windows
Operating System Concepts
Scheduling Adapted from:
Scheduling.
Chapter 5: CPU Scheduling
CPU SCHEDULING.
Outline Scheduling algorithms Multi-processor scheduling
Threads and Concurrency
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Process Scheduling Decide which process should run and for how long
Process Description and Control
Chapter 3: Processes.
Outline Announcement Process Scheduling– continued
Processes in Unix, Linux, and Windows
CS510 Operating System Foundations
Shortest-Job-First (SJR) Scheduling
Chapter 6: Scheduling Algorithms Dr. Amjad Ali
Scheduling 21 May 2019.
CSE 153 Design of Operating Systems Winter 2019
CPU Scheduling CSE 2431: Introduction to Operating Systems
Presentation transcript:

Operating Systems Process Managment

Processes

Process Definition A process is a program in execution.

Multi-Programming Modern Operating Systems, 3rd ed., Andrew Tanenbuam 

Process Creation Principal events that cause process creation: 1. System initialization 2. Execution of a process creation system by a running processes 3. User request to create a new process 4. Initiation of a batch job

Creating a new process in Unix Fork: Unix system call to create an copy of the invoking process. The calling process is called the parent, the newly created process is the parent. Fork is standardized by POSIX (Portable Operating System Interface). Implemented by most UNIX (including Mac OS as of Leopard) and is closely adhered to in Linux.

Question Who & where is fork implemented?

Fork Details Everything gets copied, PCB is an exact copy, address space, registers, file descriptors, etc. (Process id would be different). The child process starts off and the first thing it does is return from the very system call its parent made! How can the child’s and parent’s execution path separate? Hint: Interface: int fork ()

Fork Skeleton A multi-perspective episodic approach, Jae C. Oh

Possible Fork implementation A multi-perspective episodic approach, Jae C. Oh

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

Foreground, Background & Daemons Foreground processes: interacting with user Background processes: running without input from user What is the significance in windowed systems? Daemons: Wait in background to handle event or activity.

Process Life Cycle

Process States Running: Process is currently running in the CPU. Ready: Process is ready to run (waiting for scheduler to choose it to run). Blocked: Process is waiting for some external event to happen (example process is waiting for an file read).

Process State Diagram Modern Operating Systems, 3rd ed., Andrew Tanenbuam 

Process Termination Conditions which terminate processes Normal exit (voluntary) Error exit (voluntary) Fatal error (involuntary) Killed by another process (involuntary) Kill command A Daemon process finds Zombie processes Within a program

Process System Calls Modern Operating Systems, 3rd ed., Andrew Tanenbuam 

Using Exec & Waitpid A multi-perspective episodic approach, Jae C. Oh

Question What happens if you don’t put exit system call at the end of your program?

Implementation of Processes Fields of a process data structure

Scheduling Introduction to Scheduling (1)‏ Bursts of CPU usage alternate with periods of I/O wait a CPU-bound process an I/O bound process

When to schedule? When a process is created Parent or child? When a process exits When a process requests an I/O (I.e., blocked)‏ When a process blocks due to C.R. mutual exclusion When an I/O interrupt occurs When a clock interrupt occurs (e.g., quantum expires)‏

Introduction to Scheduling (2)‏ Scheduling Algorithm Goals

Preemtpion Pre-emptive Scheduler – removes process P from CPU without P's consent, after some fixed amount of time. Non-Pre-emptive Scheduler – Process P must actively release the the CPU (Yield, Exit, Sleep, or blocking system call).

Metrics Throughput: The number of processes a system can complete in a set amount of time. i.e. # per minute, # per hour, etc. Turn Around time: The time a process takes from being created to being finished. Response Time: The time an interactive process takes to respond to user input.

Scheduling algorithms for batch systems FCFS Shortest Job First All jobs must be available simultaneously (is provably optimal). Shortest Remaining Time Next Preemptive verson of SJF

Scheduling in Batch Systems (2)‏ Three level scheduling

Scheduling in Interactive Systems Round Robin Scheduling list of ready processes list of ready processes after B uses up its quantum

Time Quota If time quota is too long, what can happen? If time quota is too short what happens?

Priority Scheduling We can assign an importance factor to our processes. Priority can be static or dynamic Why would we ever change priority? Higher priority equals longer time quota? Or All good priorities should finish first?

Scheduling in Interactive Systems A scheduling algorithm with four priority classes

Shortest Job First Scheduling Always produces the minimum average response time. We need to know how long each process/thread takes!

Lottery Scheduling Each runable entity is given a certain number of tickets. The more tickets you have, higher your odds of winning. Trade tickets? Problems?

Fair Share Scheduler Schedule not only based on individual process, but process's owner. N users, each user may have different # of processes. Does this make sense on a PC?

Policy versus Mechanism Separate what is allowed to be done with how it is done a process knows which of its children threads are important and need priority Scheduling algorithm parameterized mechanism in the kernel Parameters filled in by user processes policy set by user process

User-level Thread Scheduling Possible scheduling of user-level threads 50-msec process quantum threads run 5 msec/CPU burst

Kernel-Level Thread Scheduling Possible scheduling of kernel-level threads 50-msec process quantum threads run 5 msec/CPU burst

1. User-Level Threads: Thread data structure maintained in user-space. 2. Kernel-Level Threads: Thread data structure maintained in kernel. 3. Hybrid Threads: Mixture of User & Kernel. 4. Process data structure: Address space, open files, list of threads. 5. Thread data structure: registers, stack, state. 6. Context Switch: Assembly needed to save/load regs. MMU updated. 7. Critical region: Code where data is shared amongst processes. 8. Mutual Exclusion: Only one process has access to a CR. 9. Busy waiting: Keep checking (loop) some condition. 10. Deadlock: Process(es) are waiting (sleeping) for an event that can never occur. No work is done. 11. Starvation: Process(es) wait for an event that can happen, but doesn’t. 12. Semaphore: A counter and queue, implements P (down) & V (up). 13. Mutex: IS A TYPE OF SEMAPHORE! Used for mutual exclusion. 14. Monitor: Part of a language, provides mutual exclusion. 14. Throughput, turn around time, 15. Round-Robin, Priority, Multi-queue, MLFQ, Lottery, SJF

Round Robin Scheduler

Round Robin Scheduler RR scheduler is a pre-emptive scheduler. Each job is given a fixed quanta of time to run in the CPU. All jobs are treated equally (no priority classes). Straight forward and starvation free.

Round Robin Example Quanta = 10ms Process Arrival Time Run Time P0 22 22 P1 5 15 P2 13 8

Round Robin Example Time Current Process Next Process Ready Queue Notes EMPTY P0 P0, P0 arrives 5 N/A P1, P1 arrives 10 P1 Quanta Expired 13 P0, P2 P2 arrives 20 P2, P1 30 P2 P1, P0 38 P2 Completes 43 P1 Completes 45 P0 Completes

Question Other than quanta expiration what are two other reasons the scheduler might have to choose a different job to run?

Completely Fair Scheduler

Completely Fair Scheduler Tries to model an ideal multi-tasking CPU: Run each task at 1/ N equal speed, in parallel. When a process arrives, record the current system time. Keep track of how long each process has been waiting for the CPU (update the wait time based on process ID and the number of processes in the queue). Decrement the wait value when the process gets on the CPU.

Implementation Details Use a Red/Black Tree to keep track of which process has the longest wait. Red/Black Tree: Self balancing binary tree Operations take Log(N)

Multi Level Feedback Queues

Multi Level Queue Multiple Queues tiered by priority. All jobs from highest priority queue must be empty to begin next lower queue. Within a given queue, any other scheduling algorithm can be used (FCFS, SJF, RR). Jobs do not change queue. Provides a strict way of grouping together jobs from different users but same priority.

Multi Level Feedback queue Multiple Queues Most jobs are mixture of I/O and CPU. Highest priority queue is for I/O heavy jobs. Lowest priority queue is for CPU heavy jobs. All jobs start at highest priority queue. Jobs that are preempted (use all of time quanta) are booted to lower priority queue. Quanta generally increases indirectly with priority. Jobs that block on I/O go up to next higher priority queue. Job is pre-empted if higher priority jobs arrives.

Multi-Level Feedback Queue Example

Question Between Multi-Level Queue and Multi-Level Feedback Queue which is more likely to have starvation?

Threads

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

Each thread has its own stack The Thread Model Each thread has its own stack

Thread library calls thread_create thread_exit thread_yield Etc.

Thread Motivation Blocking system call needs to wait on some I/O, e.g. disk read. Sometimes called synchronous call. Entire process is put into blocked state. Non-Blocking system call (i.e. asynchronous) kicks off a request (typically to a device) but doesn’t wait for completion. Polling, signals, callbacks or threads would be needed to handle the result.

A word processor with three threads Thread Usage Example 1 A word processor with three threads

Threads A thread (or thread-of-execution) is a component of a process that allows intra-process parallelization. A thread has stack and its own set of registers, but shares process address space with other threads within the same process.

Thread Example Web-Server processes (e.g. Google) takes thousands of requests per second. Modern Operating Systems, 3rd ed., Andrew Tanenbuam 

Process vs Thread Modern Operating Systems, 3rd ed., Andrew Tanenbuam 

Implementation of Threads In user space In kernel space

User Threads vs. Kernel Threads Threads can be implemented in either the kernel or user space. Kernel threads: Kernel manages thread state. Scheduling can be pre-emptive (we can force out a thread). Easy support for blocking system calls. System calls required for scheduling, update or creation. User threads: Kernel is completely unaware of threading. User process/library manages thread state. Pre-emption is not possible, threads must leave on their own. Generally require non-blocking system calls (in OS). No System call for scheduling, update or creation.

Implementing Threads in User Space A user-level threads package

User level thread implementation + Fast switching between threads (no kernel code needed). + Can do for existing non-multithreaded OS + Each process can have its own customized scheduling algorithm/policy - Blocking system calls can we change system calls to be non-blocking calls? May be the select system call? - No preemption among threads

Implementing Threads in the Kernel A threads package managed by the kernel

Hybrid Implementations Multiplexing user-level threads onto kernel- level threads

Scheduler Activations Hybrid User & Kernel Space Threads A thread blocked, should not block the process User space decides which thread to run next Upcall notifies User space that thread is blocked

Pop-Up Threads Create a new thread on event Short life span, only handles that event

Threads in Java JVM is really a specification, native (kernel threads) may not exist on the host OS. In that case JVM uses user-space threads (called Green Threads). Two ways to implement: Implement Thread sub-class Write class that implements Runnable interface

Thread Usage Rough outline of code for previous slide (a) Dispatcher thread (b) Worker thread

Question How can you write a Java program to test if threads are natively supported in the OS?