OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

Similar documents
www nfsd emacs lpr Process Management CS 537 Lecture 4: Processes Example OS in operation Why Processes? Simplicity + Speed

OS lpr. www. nfsd gcc emacs ls 9/18/11. Process Management. CS 537 Lecture 4: Processes. The Process. Why Processes? Simplicity + Speed

CS 537 Lecture 2 - Processes

CSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

CSE 153 Design of Operating Systems Fall 2018

SE350: Operating Systems

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

Processes. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! Scheduling processes

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

Lec 26: Parallel Processing. Announcements

Lecture 2: Processes. CSE 120: Principles of Opera9ng Systems. UC San Diego: Summer Session I, 2009 Frank Uyeda

csci3411: Operating Systems

Processes. CS439: Principles of Computer Systems January 24, 2018

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission 1

Chap 4, 5: Process. Dongkun Shin, SKKU

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Lecture 4: Process Management

Processes and Threads

Processes. Sanzheng Qiao. December, Department of Computing and Software

Operating Systems. II. Processes

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Processes & Threads. Process Management. Managing Concurrency in Computer Systems. The Process. What s in a Process?

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Processes. CS439: Principles of Computer Systems January 30, 2019

Chapter 3 Process Description and Control

What is a Process? Processes and Process Management Details for running a program

Processes & Threads. (Chapter 3) CS 4410 Operating Systems. [R. Agarwal, L. Alvisi, A. Bracy, M. George, E. Sirer, R. Van Renesse]

The Big Picture So Far. Today: Process Management

OS Structure, Processes & Process Management. Don Porter Portions courtesy Emmett Witchel

Operating Systems CMPSC 473. Process Management January 29, Lecture 4 Instructor: Trent Jaeger

Processes. CS3026 Operating Systems Lecture 05

Today: Process Management. The Big Picture So Far. What's in a Process? Example Process State in Memory

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

518 Lecture Notes Week 3

CS153: Process 2. Chengyu Song. Slides modified from Harsha Madhyvasta, Nael Abu-Ghazaleh, and Zhiyun Qian

CS510 Operating System Foundations. Jonathan Walpole

Operating System Structure

Processes & Threads. Recap of the Last Class. Microkernel System Architecture. Layered Structure

CSE 451: Operating Systems Winter Processes. Gary Kimura

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Chapter 3: Processes. Operating System Concepts 8th Edition,

Processes. q Process concept q Process model and implementation q Multiprocessing once again q Next Time: Scheduling

CSCE 313: Intro to Computer Systems

Chapter 3: Process Concept

Chapter 3: Process Concept

W4118 Operating Systems. Junfeng Yang

Killing Zombies, Working, Sleeping, and Spawning Children

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

Mon Sep 17, 2007 Lecture 3: Process Management

The Kernel. wants to be your friend

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

CSci 4061 Introduction to Operating Systems. Processes in C/Unix

High Performance Computing Lecture 11. Matthew Jacob Indian Institute of Science

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

CSCC69H3. Operating Systems Sina Meraji U of T

CHAPTER 2: PROCESS MANAGEMENT

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

What is a Process. Processes. Programs and Processes. System Classification 3/5/2013. Process: An execution stream and its associated state

Lecture 4: Memory Management & The Programming Interface

Chapter 3: Process Concept

CSC 539: Operating Systems Structure and Design. Spring 2006

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Processes. CSE 2431: Introduction to Operating Systems Reading: Chap. 3, [OSC]

COMP 3100 Operating Systems

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

Processes & Threads. Recap of the Last Class. Layered Structure. Virtual Machines. CS 256/456 Dept. of Computer Science, University of Rochester

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha

Processes. OS Structure. OS Structure. Modes of Execution. Typical Functions of an OS Kernel. Non-Kernel OS. COMP755 Advanced Operating Systems

The Kernel Abstraction. Chapter 2 OSPP Part I

CS240: Programming in C

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Processes. Today. Next Time. Process concept Process model Implementing processes Multiprocessing once again. Scheduling processes

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Chapter 3: Processes. Operating System Concepts 8th Edition, modified by Stewart Weiss

Notice: This set of slides is based on the notes by Professor Perrone of Bucknell and the textbook authors Silberschatz, Galvin, and Gagne

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Fall 2015 COMP Operating Systems. Lab #3

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

A process. the stack

CSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018

Transcription:

Process Management CS 537 Lecture 3: Processes Michael Swift This lecture begins a series of topics on processes, threads, and synchronization Today: processes and process management what are the OS units of execution? how are they represented inside the OS? how is the CPU scheduled across processes? what are the possible execution states of a process? and how does the system move between them? 1 2 Example OS in operation Why Processes? Simplicity + Speed User Apps Operating System Firefox File Systems Device Drivers Photoshop Application Interface (API) Memory Manager Interrupt Handlers Acrobat Process Manager Hardware Abstraction Layer Hardware (CPU, devices) Acrobat Network Support Boot & Init Portable Hundreds of things going on in the system nfsd gcc emacs ls OS www lpr nfsd ls How to make things simple? Separate each in an isolated process Decomposition How to speed-up? Overlap I/O bursts of one process with CPU bursts of another www OS emacs lpr 3 4 1

The Process What is a program? The process is the OS s abstraction for execution the unit of execution the unit of scheduling the dynamic (active) execution context compared with program: static, just a bunch of bytes Process is often called a job, task, or sequential process a sequential process is a program in execution defines the instruction-at-a-time execution of a program A program consists of: Code: machine instructions Data: variables stored and manipulated in memory initialized variables (globals) dynamically allocated variables (malloc, new) stack variables (C automatic variables, function arguments) DLLs: libraries that were not compiled or linked with the program containing code & data, possibly shared with other programs mapped files: memory segments containing variables (mmap()) used frequently in database programs Whats the relationship between a program and process? A process is a executing program 5 6 Preparing a Program Running a program compiler/ assembler Linker OS creates a process and allocates memory for it The loader: source file Header.o files static libraries (libc, streams ) reads and interprets the executable file sets process s memory to contain code & data from executable pushes argc, argv, envp on the stack sets the CPU registers properly & calls start() [Part of CRT0] Code Program start running at start(), which calls main() Initialized data BSS Executable file (must follow standard format, such as ELF on Linux, Microsoft PE on Windows) we say process is running, and no longer think of program When main() returns, CRT0 calls exit() destroys the process and returns all resources Symbol table Line numbers Ext. refs 7 8 2

What s in a Process? Process!= Program mapped segments A process consists of (at least): an address space the code for the running program the data for the running program an execution stack and stack pointer (SP) traces state of procedure calls made the program counter (PC), indicating the next instruction a set of general-purpose processor registers and their values a set of OS resources open files, network connections, sound channels, The process is a container for all of this state a process is named by a process ID (PID) just an integer Header Code Initialized data BSS Symbol table Line numbers Ext. refs Executable Program is passive Code + data Process is running program stack, regs, program counter SP Process Example: address space We both run IE: - Same program - Separate processes DLL s Stack Heap BSS Initialized data 9 PC Code 10 Process states Each process has an execution state, which indicates what it is currently doing ready: waiting to be assigned to CPU could run, but another process has the CPU running: executing on the CPU is the process that currently controls the CPU pop quiz: how many processes can be running simultaneously? waiting: waiting for an event, e.g. I/O cannot make progress until event happens As a process executes, it moves from state to state UNIX: run ps, STAT column shows current state which state is a process is most of the time? New Terminated Process state transitions create unschedule kill Ready Running schedule I/O done Waiting I/O, page fault, etc. What can cause schedule/unschedule transitions? 11 12 3

Process data structures How does the OS represent a process in the kernel? at any time, there are many processes, each in its own particular state the OS data structure that represents each is called the process control block (PCB) PCB contains all info about the process OS keeps all of a process hardware execution state in the PCB when the process isn t running PC SP registers when process is unscheduled, the state is transferred out of the hardware into the PCB PCB The PCB is a data structure with many, many fields: process ID (PID) execution state program counter, stack pointer, registers memory management info UNIX username of owner scheduling priority accounting info pointers into state queues In linux: defined in task_struct (include/linux/sched.h) over 95 fields!!! 13 14 Simple Process Control Block PCBs and Hardware State process state process number program counter stack pointer registers (general, FP) memory management info username of owner queue pointers for state queues scheduling info (priority, etc.) accounting info When a process is running, its hardware state is inside the CPU PC, SP, registers CPU contains current values When the OS stops running a process (puts it in the waiting state), it saves the registers values in the PCB when the OS puts the process in the running state, it loads the hardware registers from the values in that process PCB The act of switching the CPU from one process to another is called a context switch timesharing systems may do 100s or 1000s of switches/s takes about 5 microseconds on today s hardware 15 16 4

Context Switch CPU Switch From Process to Process For a running process All registers are loaded in CPU and modified E.g. Program Counter, Stack Pointer, General Purpose Registers When process relinquishes the CPU, the OS Saves register values to the PCB of that process To execute another process, the OS Loads register values from PCB of that process Context Switch Process of switching CPU from one process to another Very machine dependent for types of registers 17 Details of Context Switching State queues Very tricky to implement OS must save state without changing state Should run without touching any registers CISC: single instruction saves all state RISC: reserve registers for kernel Or way to save a register and then continue Overheads: CPU is idle during a context switch Explicit: direct cost of loading/storing registers to/from main memory Implicit: Opportunity cost of flushing useful caches (cache, TLB, etc.) Wait for pipeline to drain in pipelined processors The OS maintains a collection of queues that represent the state of all processes in the system typically one queue for each state e.g., ready, waiting, each PCB is queued onto a state queue according to its current state as a process changes state, its PCB is unlinked from from queue, and linked onto another 19 20 5

State queues PCBs and State Queues Ready queue header head ptr tail ptr Wait queue header head ptr tail ptr netscape pcb emacs pcb ls pcb cat pcb netscape pcb There may be many wait queues, one for each type of wait (particular device, timer, message, ) PCBs are data structures dynamically allocated inside OS memory When a process is created: OS allocates a PCB for it OS initializes PCB OS puts PCB on the correct queue As a process computes: OS moves its PCB from queue to queue When a process is terminated: OS deallocates its PCB 21 22 How to create a process? Process creation Double click on a icon? After boot OS starts the first process E.g. sched for Solaris, ntoskrnel.exe for XP The first process creates other processes: the creator is called the parent process the created is called the child process the parent/child relationships is expressed by a process tree For example, in UNIX the second process is called init it creates all the gettys (login processes) and daemons it should never die it controls the system configuration (#processes, priorities ) Explorer.exe in Windows for graphical interface One process can create another process creator is called the parent created process is called the child UNIX: do ps, look for PPID field what creates the first process, and when? In some systems, parent defines or donates resources and privileges for its children UNIX: child inherits parents userid field, etc. when child is created, parent may either wait for it to finish, or it may continue in parallel, or both! 23 24 6

UNIX process creation UNIX process creation through fork() system call creates and initializes a new PCB creates a new address space initializes new address space with a copy of the entire contents of the address space of the parent initializes kernel resources of new process with resources of parent (e.g. open files) places new PCB on the ready queue the fork() system call returns twice once into the parent, and once into the child returns the child s PID to the parent returns 0 to the child fork( ) int main(int argc, char **argv) { char *name = argv[0]; int child_pid = fork(); if (child_pid == 0) { printf( Child of %s is %d\n, name, child_pid); return 0; else { printf( My child is %d\n, child_pid); return 0; 25 26 output spinlock% gcc -o testparent testparent.c spinlock%./testparent My child is 486 Child of testparent is 0 spinlock%./testparent Child of testparent is 0 My child is 486 Fork and exec So how do we start a new program, instead of just forking the old program? the exec() system call! int exec(char *prog, char ** argv) exec() stops the current process loads program prog into the address space initializes hardware context, args for new program places PCB onto ready queue note: does not create a new process! what does it mean for exec to return? what happens if you exec csh in your shell? what happens if you exec ls in your shell? 27 28 7

UNIX shells int main(int argc, char **argv) { while (1) { char *cmd = get_next_command(); int child_pid = fork(); if (child_pid == 0) { manipulate STDIN/STDOUT/STDERR fd s exec(cmd); panic( exec failed! ); else { wait(child_pid); Windows CreateProcess function Open the program file to be executed Create the Windows executive process object Create the initial thread (stack, context,...) Notify Win32 subsystem about new process Start execution of the initial thread Complete initialization (eg, load dlls) Continue execution in both processes Copied frominside Windows 2000 29 30 Unix int child_pid = fork(); if (child_pid == 0) { exec( myprog ); Which is better? More flexible? Easier? Faster? Which is better? STARTUPINFO si = {0; PROCESS_INFORMATION pi = {0; si.cb = sizeof(si); if(!createprocess( NULL, "c:\\myprog.exe 1 2", NULL, NULL, { Windows FALSE, 0, NULL, NULL, &si, &pi ) ) printf( "CreateProcess failed (%d).\n", GetLastError() ); return; Process Termination Process executes last statement and OS decides(exit) Output data from child to parent (via wait) Process resources are deallocated by operating system Parent may terminate execution of child process (abort) Child has exceeded allocated resources Task assigned to child is no longer required If parent is exiting Some OSes don t allow child to continue if parent terminates All children terminated - cascading termination 31 32 8