Process Time. Steven M. Bellovin January 25,

Similar documents
What is an Operating System? A Whirlwind Tour of Operating Systems. How did OS evolve? How did OS evolve?

Processes and Non-Preemptive Scheduling. Otto J. Anshus

2 Processes. 2 Processes. 2 Processes. 2.1 The Process Model. 2.1 The Process Model PROCESSES OPERATING SYSTEMS

3. Process Management in xv6

Computer Systems II. First Two Major Computer System Evolution Steps

System Call. Preview. System Call. System Call. System Call 9/7/2018

Operating Systems Process description and control

Why use an Operating System? Operating System Definition

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

CS 326: Operating Systems. Process Execution. Lecture 5

Announcement. Exercise #2 will be out today. Due date is next Monday

W4118 Operating Systems. Junfeng Yang

CSE325 Principles of Operating Systems. Processes. David P. Duggan February 1, 2011

Lecture 4: Memory Management & The Programming Interface

Operating Systems Structure and Processes Lars Ailo Bongo Spring 2017 (using slides by Otto J. Anshus University of Tromsø/Oslo)

3.1 Introduction. Computers perform operations concurrently

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

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

Chap 4, 5: Process. Dongkun Shin, SKKU

15 Sharing Main Memory Segmentation and Paging

CS 111. Operating Systems Peter Reiher

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

CS 111. Operating Systems Peter Reiher

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

Major Requirements of an OS

B. V. Patel Institute of Business Management, Computer &Information Technology, UTU

IT 540 Operating Systems ECE519 Advanced Operating Systems

Operating System Review

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5

16 Sharing Main Memory Segmentation and Paging

Timers 1 / 46. Jiffies. Potent and Evil Magic

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

CS 31: Intro to Systems Processes. Kevin Webb Swarthmore College March 31, 2016

1.Define signal? NOV DEC 2011 MAY JUNE 2011

Eastern Mediterranean University School of Computing and Technology Department of Information Technology. ITEC202 Operating Systems

Processes. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

CSE 380 Computer Operating Systems. Instructor: Insup Lee. University of Pennsylvania Fall 2003

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems, 3rd edition. Uses content with permission from Assoc. Prof. Florin Fortis, PhD

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

PROCESS STATES AND TRANSITIONS:

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

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

Pebbles Kernel Specification September 26, 2004

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: Processes and Threads

CSC369 Lecture 2. Larry Zhang

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

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

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Processes. Dr. Yingwu Zhu

Processes and Threads

CSC369 Lecture 2. Larry Zhang, September 21, 2015

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

Course: Operating Systems Instructor: M Umair. M Umair

Mon Sep 17, 2007 Lecture 3: Process Management

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

Process Description and Control. Chapter 3

Process Description and Control

Processes and Threads

Processes in linux. What s s a process? process? A dynamically executing instance of a program. David Morgan. David Morgan

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

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

Templates what and why? Beware copying classes! Templates. A simple example:

Design Overview of the FreeBSD Kernel CIS 657

Processes COMPSCI 386

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Computer Systems Engineering: Spring Quiz I Solutions

Processes. Process Scheduling, Process Synchronization, and Deadlock will be discussed further in Chapters 5, 6, and 7, respectively.

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

CS370 Operating Systems

Exam Guide COMPSCI 386

آنستیتیوت تکنالوجی معلوماتی و مخابراتی ICTI

CPS221 Lecture: Operating System Protection

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

OPERATING SYSTEMS: Lesson 4: Process Scheduling

Processes and Threads Implementation

CS 326: Operating Systems. CPU Scheduling. Lecture 6

CS2028 -UNIX INTERNALS

Midterm Exam CPS 210: Operating Systems Spring 2013

Process. Discussion session 3 1/30/2016

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 21

Operating System Control Structures

Introduction to Operating System

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

Chapter 3 Process Description and Control

Processes, Execution and State. Process Operations: fork. Variations on Process Creation. Windows Process Creation.

Operating Systems. Lecture 05

PROCESS CONTROL: PROCESS CREATION: UNIT-VI PROCESS CONTROL III-II R

Unix Processes. What is a Process?

Anne Bracy CS 3410 Computer Science Cornell University

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

Lecture 2 - Fundamental Concepts

Preview. The Thread Model Motivation of Threads Benefits of Threads Implementation of Thread

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

CS 167 Final Exam Solutions

Transcription:

Multiprogramming Computers don t really run multiple programs simultaneously; it just appears that way Each process runs to completion, but intermixed with other processes Process 1 6 ticks Process 2 Process 3 CPU Use 6 ticks 6.5 ticks 20 ticks time The exact timing pattern varies for each process Note the idle times Steven M. Bellovin January 25, 2006 1

Process Time What matters is that each process eventually finishes You start reading a book, put it down for a while, pick it back up and resume where you left off As long as you finish soon enough whatever that means the exact time doesn t matter Steven M. Bellovin January 25, 2006 2

Real-Time Scheduling In some environments, processes need to run at the right time Think of process control computers valves must open and close promptly Not suitable for this paradigm Steven M. Bellovin January 25, 2006 3

What s a Process? I keep talking about processes. What are they? No rigorous definition! Precise characteristics differ on different systems Common themes: separately scheduled; some measure of isolation Steven M. Bellovin January 25, 2006 4

Separately Scheduled On all systems, processes can compete for the CPU One process blocking or being pre-empted lets another process run On some systems, a process can be composed of several threads that themselves can compete for the CPU On multiprocessor (multi-cpu) machines, different processes can execute truly simultaneously on different CPUs Steven M. Bellovin January 25, 2006 5

Isolation Termination protection Address space Security context Other system-related state Steven M. Bellovin January 25, 2006 6

Termination Processes are generally isolated from failures of other processes Termination of a process normal or abnormal does affect other processes Often a reason for process creation: let failures happen in an isolated setting, with minimal cleanup needed Steven M. Bellovin January 25, 2006 7

Address Space Processes often have separate address spaces from each other Changes to memory in one process do not affect other processes May or may not use virtual memory to provide overlapped address space on early PDP-11 Unix systems, all processes started at location 0 Steven M. Bellovin January 25, 2006 8

Exceptions... On OS/360, the job was the unit of memory protection; all tasks (the OS word for process ) shared memory On some versions of MVS, all jobs have parts of kernel memory available at the same addresses On Unix systems, program instructions but not data are shared among different processes; this often includes shared libraries Unix processes can arrange to share certain memory areas Files can be mapped to memory areas; on different processes, the same data can thus appear at different addresses Steven M. Bellovin January 25, 2006 9

Security Context Access credentials UID on Unix are process-specific SetUID applies to a process On some systems, process can share credentials Steven M. Bellovin January 25, 2006 10

System State Open files Current working directory Trap-handling state Permissions for newly-created files Often much more Steven M. Bellovin January 25, 2006 11

A Historical Note PDP-11s had a 16-bit address space: 65536 bytes The page size the granularity of memory protection was 4096 bytes Even with tiny programs, that meant at most 16 processes if they shared address space Separate address space per process was a necessity Steven M. Bellovin January 25, 2006 12

Processes and System Calls Suppose a process issues a system call. What happens in the kernel? Interrupt hardware saves old PSW; loads new PSW Software interrupt handler saves registers; branches to system call dispatcher Dispatcher figures out which system call it is, and calls that subroutine That subroutine may call others We need a stack Steven M. Bellovin January 25, 2006 13

The Kernel Stack As discussed previously, cannot trust user-level setup Must have a kernel stack Stack size is limited watch for too-deep recursion! Where is this stack? Steven M. Bellovin January 25, 2006 14

Per-Process Stacks Suppose this system call blocks waiting for I/O Another process can run; what if it issues a system call? It can t share the first process stack, because that one may need to be used while this one is active We need a separate kernel stack per process! Steven M. Bellovin January 25, 2006 15

Per-Process State Actually, we need a lot of state per process The basic per-process structure on Linux (task struct) is 175 lines of C, and it points to other per-process structures What s in them? Two broad classes: fields needed when running and fields needed when deciding whether or not to run the process Steven M. Bellovin January 25, 2006 16

Per-Process State: Always Needed Process state: running, ready, blocked What it s blocked on resource (CPU, RAM, I/O, etc.) usage history Priority Signal status ProcessID, process group Pointers to other fields Memory allocations Steven M. Bellovin January 25, 2006 17

Per-Process State: Needed When Running Kernel stack PSW, program counter Open file descriptors Some state information, such as current directory user credentials Steven M. Bellovin January 25, 2006 18

Scheduling State Transition Running Ready Blocked Note that when making the transition from Blocked to Ready, it may be necessary to copy in some state data from disk. This, of course, is itself a blocking operation. Steven M. Bellovin January 25, 2006 19

Process Creation The first process is created at boot time Any process, including that one, can create new processes Details differ widely between operating systems Steven M. Bellovin January 25, 2006 20

Process Creation on Unix Basic operation: fork() Creates an exact copy of the process, code, data, and state Only difference: parent is passed back processid of child; child is passed back 0 The child process typically manipulates some file descriptors, then exec()s some other program Note: virtually all Unix commands create separate processes. (That had been the intention for Multics, but it was too expensive there.) Steven M. Bellovin January 25, 2006 21

Optimization? Copying all of that data is expensive Instead, use the same pages, marked read-only, and let the virtual memory system copy as needed Manipulating all of those page table entries is remarkably expensive, too it saves less than you might hope Steven M. Bellovin January 25, 2006 22

Inheritance Unix processes inherit copies of file descriptors If you re not careful, output can be intermixed; input consumed by one is not available to the other Since an X11 window is an open file descriptor, windows are inherited as well All of this is very powerful, but easy to get wrong Steven M. Bellovin January 25, 2006 23

Process Creation on Windows The CreateProcess call creates processes on Windows Executing a new program is part of the process creation mechanism 10 parameters control the program to be executed, window creation, priority, security attributes, file inheritance, and much more The Windows call does more for you, but is it simpler? Steven M. Bellovin January 25, 2006 24

Process Relationships in Unix A newly-created process is a child of the parent process When a child process terminates, its resource consumption is passed up to the parent The parent process is notified when a child terminates, and needs to reap it (via the wait() system call) If not, the process remains a zombie Processes whose parent dies become children of process 1 Steven M. Bellovin January 25, 2006 25

Process Groups Related processes say, all the elements of a pipeline form a process group Certain signals interrupts to a process are sent to all members of a process group Thus, if you hit ˆC, all of the processes are killed Steven M. Bellovin January 25, 2006 26

Windows Process Relationships All Windows processes are siblings; there are no other relationships When a process creates another process, it receives a process handle that can be used to control that process The process handle can be passed around to other processes Steven M. Bellovin January 25, 2006 27

Process Termination When a process terminates, its resources must be freed Some of these resources including open files; closing a file can block Termination isn t easy, and may not terminate quickly... Steven M. Bellovin January 25, 2006 28

Creating a Process Overview Parent issues a system call Interrupt handler invokes the kernel Kernel creates the process At some point, it runs Steven M. Bellovin January 25, 2006 29

Issuing a System Call Parent Issues (machine-language) system call instruction Hardware Old PSW and program counter are saved Hardware New PSW and program counter are loaded Assembler Registers are saved in current process kernel data structure Assember System call dispatcher is invoked C Process creation routine invoked Steven M. Bellovin January 25, 2006 30

Process Creation Routine Verify that resources are available Process table entry User s process quota Create new process table entry Copy inherited data to new process Make sure saved registers are correct, including return value to indicate it s a child process Return to system call dispatcher Steven M. Bellovin January 25, 2006 31

Returning From the Kernel When the new process is created, the dispatcher invokes the scheduler The scheduler decides which process will run next the parent, the child, or some other process entirely Assembler code restores registers for whatever process is the next to run The old PSW and program counter are reloaded by return from interrupt instruction Steven M. Bellovin January 25, 2006 32

Note Well... How the new proces behaves is completely determined by what is put into the process structure Registers aren t a C concept, but the contents of the any process registers are determined by what is put into this structure Many subtle details; see You are not expected to understand this at http://cm.bell-labs.com/cm/cs/who/dmr/odd.html Steven M. Bellovin January 25, 2006 33

Summary Processes are fundamental to multiprogramming The details differ widely among different systems Process creation and interrupt-handling are closely linked Steven M. Bellovin January 25, 2006 34