CS510 Operating System Foundations

Slides:



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

Operating Systems COMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money.
Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
The Process Model.
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972.
Processes CSCI 444/544 Operating Systems Fall 2008.
Jonathan Walpole Computer Science Portland State University
1 CS 333 Introduction to Operating Systems Class 3 – Threads & Concurrency Jonathan Walpole Computer Science Portland State University.
Page 1 Processes and Threads Chapter 2. Page 2 Processes The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
1 CS 333 Introduction to Operating Systems Class 2 – OS-Related Hardware & Software The Process Concept Jonathan Walpole Computer Science Portland State.
1 What is a Process ? The activity of program execution. Also called a task or job Has associated with it: Code Data Resources A State An executing set.
CSCE 351: Operating System Kernels
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
CSSE Operating Systems
CSE451 Processes Spring 2001 Gary Kimura Lecture #4 April 2, 2001.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Processes April 5, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control A process is sometimes called a task, it is a program in execution.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Processes and Threads.
Implementing Processes and Process Management Brian Bershad.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
CS333 Intro to Operating Systems Jonathan Walpole.
CS333 Intro to Operating Systems Jonathan Walpole.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Operating Systems Processes 1.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
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.
What is a Process ? A program in execution.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Process concept.
Process Management Process Concept Why only the global variables?
Jonathan Walpole Computer Science Portland State University
CS399 New Beginnings Jonathan Walpole.
Processes A process is a running program.
System Structure and Process Model
System Structure and Process Model
Processes in Unix, Linux, and Windows
System Structure B. Ramamurthy.
More examples How many processes does this piece of code create?
Jonathan Walpole Computer Science Portland State University
Processes in Unix, Linux, and Windows
System Structure and Process Model
Process & its States Lecture 5.
Process Description and Control
Processes Hank Levy 1.
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Process Description and Control
Jonathan Walpole Computer Science Portland State University
Process Description and Control
Lecture 6: Multiprogramming and Context Switching
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Process Description and Control
Process Management -Compiled for CSIT
Processes Hank Levy 1.
Process Management -Compiled for CSIT
Presentation transcript:

CS510 Operating System Foundations Jonathan Walpole

The Process Concept

The Process Concept Process – a program in execution Program Process - description of how to perform an activity instructions and static data values Process - a snapshot of a program in execution - memory (program instructions, static and dynamic data values) - CPU state (registers, PC, SP, etc) - operating system state (open files, accounting statistics etc)

Process Address Space Each process runs in its own virtual memory address space that consists of: - Stack space – used for function and system calls - Data space – variables (both static and dynamic allocation) - Instructions – the program code (usually read only) Invoking the same program multiple times results in the creation of multiple distinct address spaces stack Address space data instructions

Switching Among Processes Program instructions operate on operands in memory and (temporarily) in registers CPU Memory Load A1, R1 Load A2, R2 Add R1, R2, R3 Store R3, A3 … Prog2 Code ALU Prog1 Code Prog2 Data Prog1 Data SP PC Prog1 has CPU Prog2 is suspended Prog2 State

Switching Among Processes Saving all the information about a process allows a process to be temporarily suspended and later resumed CPU Memory Prog2 Code ALU Prog1 Code Prog2 Data Prog1 Data SP PC OS suspends Prog1 Prog1 State Prog2 State

Switching Among Processes Saving all the information about a process allows a process to be temporarily suspended and later resumed CPU Memory Prog2 Code ALU Prog1 Code Prog2 Data Prog1 Data SP PC OS resumes Prog2 Prog1 State Prog2 State

Switching Among Processes Program instructions operate on operands in memory and in registers CPU Memory Load A1, R1 Load A2, R2 Sub R1, R2, R3 Store R3, A3 … Prog2 Code ALU Prog1 Code Prog2 Data Prog1 Data SP PC Prog2 has CPU Prog1 is suspended Prog1 State

The Process Abstraction Multiprogramming of four programs in the same address space Conceptual model of 4 independent, sequential processes Only one program active at any instant

The Scheduler Lowest layer of process-structured OS - handles interrupts & scheduling of processes Sequential processes only exist above that layer

Process States

How Are Processes Created? Events that cause process creation: System startup Initiation of a batch job User request to create a new process Program request to create a new process All result in the execution of a process creation system call (fork) from another process

Process Hierarchies Parent process creates/forks child process - each process is assigned a unique identifying number or process ID (PID) system calls for communicating with and waiting for child processes Child processes can create their own child processes

How Do Processes Terminate? Conditions that terminate processes: Normal exit (voluntary) Error exit (voluntary) Fatal error (involuntary) Killed by another process (involuntary) All of the above are system calls!

Process Creation in UNIX All processes have a unique process id getpid(), getppid() system calls allow processes to get their information Process creation fork() system call creates a copy of a process and returns in both processes (parent and child), but with a different return value exec() replaces an address space with a new program Process termination, signaling signal(), kill() system calls allow a process to be terminated or have specific signals sent to it

Process Creation Example csh (pid = 22) … pid = fork() if (pid == 0) { // child… exec(); } else { // parent wait();

Process Creation Example csh (pid = 22) … pid = fork() if (pid == 0) { // child… exec(); } else { // parent wait(); csh (pid = 24) … pid = fork() if (pid == 0) { // child… exec(); } else { // parent wait();

Process Creation Example csh (pid = 22) csh (pid = 24) … pid = fork() if (pid == 0) { // child… exec(); } else { // parent wait(); … pid = fork() if (pid == 0) { // child… exec(); } else { // parent wait();

Process Creation Example csh (pid = 22) csh (pid = 24) … pid = fork() if (pid == 0) { // child… exec(); } else { // parent wait(); … pid = fork() if (pid == 0) { // child… exec(); } else { // parent wait();

Process Creation Example csh (pid = 22) ls (pid = 24) … pid = fork() if (pid == 0) { // child… exec(); } else { // parent wait(); //ls program main(){ //look up dir … }

Process Creation (fork) Fork creates a new process by copying the calling process The new process has its own - Memory address space (copied from parent) Instructions (same program as parent!) Data Stack - Register set (copied from parent) - Process table entry in the OS

Multiprocessors How can we execute concurrent programs on multiprocessors using processes? It would be nice to harness multiple CPUs in the execution of a single program instance Processes are a poor match for this

Threads Processes have the following components: an address space a collection of operating system state a CPU context … a flow or thread of control To use multiple CPUs on a multiprocessor system, a process would need several CPU contexts Thread fork creates new thread not memory space Multiple threads of control could run in the same memory space Can even be used in a single CPU system! Context switching between thread is cheaper… ASK WHY? Because you don’t have O.S. to change.

Threads Threads share a process address space with zero or more other threads Threads have their own CPU context - PC, SP, register state, - Stack A traditional process could be viewed as a memory address space with a single thread

Single Thread in Address Space

Multiple Threads in Address Space

What Is a Thread? A thread executes a stream of instructions it is an abstraction for a control-flow Practically, it is a processor context and stack - Allocated a CPU by a scheduler - Executes in a memory address space

Private Per-Thread State Things that define the state of a particular flow of control in an executing program - Stack (local variables) - Stack pointer Registers Scheduling properties (i.e., priority) The memory address space is shared with other threads in that process

Concurrent Access to Shared State Changes made to shared state by one thread will be visible to the others! Reading and writing memory locations requires synchronization This is a major topic for later!

Programming With Threads Split program into routines to execute in parallel - True or pseudo (interleaved) parallelism Alternative strategies for executing multiple rountines

User-level threads The idea of managing multiple abstract program counters above a single real one can be implemented without using privileged instructions - Threads can be implemented in the OS or at user level User level thread implementations - Thread scheduler runs as user code (thread library) - Manages thread contexts in user space - The underlying OS sees only a traditional process above

Kernel-Level Threads OS threads: Thread-switching code is in the kernel

User-Level Threads Package The thread-switching code is in user space

Implementing Threads We need a CPU in order to run a kernel thread We need a kernel thread or process in order to run a user-level thread We need a thread control block (TCB) structure in memory to hold thread state It can be in user memory for user-level threads

Implementing Threads When a thread is created, what needs to happen? When a thread exits, what needs to happen? What will cause a thread switch to occur? What will happen when a thread switch occurs? Is the kernel really needed?

User-level threads Advantages Disadvantages Cheap context switch costs among threads in the same process! Calls are procedure calls not system calls! User-programmable scheduling policy Disadvantages - How to deal with blocking system calls! - How to overlap I/O and computation!

Types of “Context Switch” Process switch Thread switch Kernel thread switch User-level thread switch Interrupt? Function call?