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

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

Fall 2017 :: CSE 306. Process Abstraction. Nima Honarmand

Last time: introduction. Networks and Operating Systems ( ) Chapter 2: Processes. This time. General OS structure. The kernel is a program!

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

W4118 Operating Systems. Junfeng Yang

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

Operating Systems. Processes. Eno Thereska

Kernel and processes

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

Operating System Structure

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

Processes. CS3026 Operating Systems Lecture 05

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

CSE 153 Design of Operating Systems Fall 2018

Processes COMPSCI 386

Administrivia. Section scheduled at 12:30pm in Skilling. Lab 1 is ready. Ask cs140-staff for extension if you can t finish

Computer Systems II. First Two Major Computer System Evolution Steps

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Administrivia. Section scheduled at 2:15pm in Gates B03 (next door)

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

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

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

Unix Processes. What is a Process?

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

Creating Threads COMP755

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

Lecture 4: Process Management

Process Management! Goals of this Lecture!

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

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

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

Process Time. Steven M. Bellovin January 25,

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

ENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS

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

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Process Management 1

CS510 Operating System Foundations. Jonathan Walpole

COMP 3430 Robert Guderian

Processes. Non-examples (implemented as one process): Why processes? - emacs text editor - firefox web browser

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

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

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

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

CS 326: Operating Systems. Process Execution. Lecture 5

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

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

1/13/2019 Operating Systems. file:///volumes/users/rasit/desktop/comp3430/coursematerial/slides/03_processes/index.html?

Lecture 4: Memory Management & The Programming Interface

Processes and Non-Preemptive Scheduling. Otto J. Anshus

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

The Big Picture So Far. Today: Process Management

csci3411: Operating Systems

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20

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

Introduction to Processes

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

fork System-Level Function

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

CS 355 Operating Systems. Keeping Track of Processes. When are processes created? Process States 1/26/18. Processes, Unix Processes and System Calls

Fork() System Call and Processes. CS449 Fall 2017

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

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

Operating System Labs. Yuanbin Wu

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

Review. CSCI 6730/ 4730 Operating Systems. Chapter 3: Processes: Outline. What is a Process? What are Processes? Our Process Definition.

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Arvind Krishnamurthy Spring Threads, synchronization, scheduling Virtual memory File systems Networking

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

Processes and Threads

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

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

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

OPERATING SYSTEMS OVERVIEW. Operating Systems 2015 Spring by Euiseong Seo

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

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

Mon Sep 17, 2007 Lecture 3: Process Management

Processes. Process Concept


Processes, Threads, SMP, and Microkernels

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

3.1 Introduction. Computers perform operations concurrently

Princeton University Computer Science 217: Introduction to Programming Systems. Process Management

- gcc file_a.c compiler running on file A - gcc file_b.c compiler running on file B - emacs text editor - firefox web browser

CS 111. Operating Systems Peter Reiher

Processes. Dr. Yingwu Zhu

Inter-Process Communication and Synchronization of Processes, Threads and Tasks: Lesson-1: PROCESS

Kernel and processes

Sistemi in Tempo Reale

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

Princeton University. Computer Science 217: Introduction to Programming Systems. Process Management

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

Operating System Design

CS 111. Operating Systems Peter Reiher

Operating System Review

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

- gcc file A.c compiler running on file A - gcc file B.c compiler running on file B - emacs text editor - firefox web browser

Transcription:

What is a Process Process: An execution stream and its associated state Processes Execution Stream Set of instructions Thread of control Process State Hardware state Privilege level, segments, page tables OS State Priority, I/O Buffers, Heap, memory map Resource state I/O requests An abstraction to make it easier to program both OS and applications Encapsulate state into manageable unit Programs and Processes A process is not a program Program: Static code and static data Program Process OS can host multiple processes of same program E.g. many users can run ls at the same time One program can invoke multiple processes E.g. make runs many processes to compile code Heap Registers No one-to-one mapping between programs and processes System Classification Uniprogramming: Only one process at a time Examples: Original systems and older PC Oses DOS Advantages: Easier for OS designer Disadvantages: Terrible utilization, poor usability Multiprogramming: Multiple processes at a time Examples: Every modern OS you use Note: Multiprogramming is different from multiprocessing Multiprocessing: Systems with multiple processors Advantages: Better utilization and usability Disadvantages: Complex OS design 1

PIDs Each system must track running processes Needs some way to identify them Process IDs OS level handle to uniquely identify each process Unsigned integer Used every time the system needs to operate on a process Just like file descriptors Managing processes (Unix) Finding processes ps Monitoring Processes top Stopping processes kill <pid> Background/Foreground ctrl-z followed by bg / fg./hello & Process State Q: Is this all a process is? A: No, additional state inside the OS What is it s name? Who is the owner? What permissions does it have? How long has it been running? Process Heap Registers OS tracks the state of each process in the system Stored in a process list, not a table (why?) Process ID (PID) used to look up process entry from list OS state of a process referred to as the Process Control Block (PCB) /proc File system based export of process information Contains information on every process on the system Organized by PID /proc/self exports information for the running process Information available Resources in use Resources allowed to use Memory map Entire memory image Cmdline Etc 2

Context Switching Context Switch implementation OS provides the illusion of a dedicated machine per process Process OS s abstraction of a running program Context switch Saving context of one process, restoring that of another one Distorted notion of time Time shell process hello process OS code OS code Context switch Context switch Machine dependent code (Assembly!) Different for MIPS, ARM, x86, etc. Save process state Registers, PCB, etc Tricky: OS must save state without changing state Requires special hardware support Save process state on each trap/interrupt Very nasty 9 Dispatch Mechanism How does dispatcher gain control? OS maintains list of all processes (PCBs) Each process has a mode Running: Executing on the CPU Ready: Waiting to execute on CPU Blocked: Waiting for I/O or synchronization with another thread Dispatch Loop while (1) { run process for a while; stop process and save its state; load state of another process; Must change from user to system mode Problem: Only one CPU, and CPU can only do one thing at a time A user process running means the dispatcher isn t Two ways OS gains control Traps: Events caused by process execution System calls, page faults, Exceptions (segfault, etc) Hardware interrupts: Events external to process Typing at keyboard, network packet arrivals Control switch to OS via Interrupt Service Routine (ISR) How does OS guarantee it will regain control? 3

Two ways to create a process Build one from scratch Clone an existing one Process Creation Option 1: From scratch (Windows CreateProcess( )) Load specified code and data into memory Create empty call stack Create and initialize PCB (make it look like a context switch) Add process to ready list Creating a process (Windows and UNIX) Windows BOOL WINAPI CreateProcess( _In_opt_ LPCTSTR lpapplicationname, _Inout_opt_ LPTSTR lpcommandline, _In_opt_ LPSECURITY_ATTRIBUTES lpprocessattributes, _In_opt_ LPSECURITY_ATTRIBUTES lpthreadattributes, _In_ BOOL binherithandles, _In_ DWORD dwcreationflags, _In_opt_ LPVOID lpenvironment, _In_opt_ LPCTSTR lpcurrentdirectory, _In_ LPSTARTUPINFO lpstartupinfo, _Out_ LPPROCESS_INFORMATION lpprocessinformation ); Option 2: Cloning (UNIX fork()) Stop current process and save its state Copy code, data, stack and PCB Add new Process to ready list int fork(); UNIX Do we really need to copy everything? Creating processes in UNIX Combination of fork() and exec( ) fork(): Clone current process exec( ): copy new program on top of current process int pid; char * cmd = /bin/sh ; pid = fork(); if (pid == ) { // child process exec(cmd); // exec does not return, WE NEVER GET HERE else { // parent process wait for child to finish wait(pid); Advantage: Flexible, clean, simple Before fork() x7fffffff Parent (original state) Child (copy of state) After fork() x7fffffff x7fffffff Data Data (Heap) (Heap) 4

Parent-child relationship Parent/child processes are always connected Parent creates processes Parent must also reap children Reaping Waiting for a process to die What is the point? int main() returns a value Where does that value go? waiting wait(int * ret_val); Takes a pointer to an int variable Sets that value to whatever the child s main() returns waitpid(int pid, int * ret_val, int options) Waits for a specific process to exit 5