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

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

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

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

Operating Systems & Concurrency: Process Concepts

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

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

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Announcements Processes: Part II. Operating Systems. Autumn CS4023

CSCE 313: Intro to Computer Systems

Processes. Process Concept

Chapter 3: Processes. Chapter 3: Processes. Process in Memory. Process Concept. Process State. Diagram of Process State

Chap 4, 5: Process. Dongkun Shin, SKKU

CHAPTER 2: PROCESS MANAGEMENT

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

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

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

csci3411: Operating Systems

Operating Systems. Lecture 05

Fall 2015 COMP Operating Systems. Lab #3

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

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

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

Lecture 2 Process Management

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

Processes. CS3026 Operating Systems Lecture 05

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

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

COP 4610: Introduction to Operating Systems (Spring 2014) Chapter 3: Process. Zhi Wang Florida State University

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

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

Chapter 3: Process Concept

Chapter 3: Process Concept

Processes and Threads

Part Two - Process Management. Chapter 3: Processes

Chapter 3: Process Concept

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

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

CPU/Process Management : Objectives & Challenges. Data Structures for CPU Management

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

Operating Systems. II. Processes

Chapter 3: Processes

Process. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

518 Lecture Notes Week 3

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

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

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

Chapter 3: Processes. Operating System Concepts 8th Edition

CSC 1600 Unix Processes. Goals of This Lecture

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

CS 322 Operating Systems Practice Midterm Questions

Chapter 3: Process Concept

Operating System Design

Chapter 4: Processes. Process Concept

CS307 Operating Systems Processes

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

The Process Model (1)

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

Operating System Structure

Chapter 4: Processes

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Processes. Dr. Yingwu Zhu

ECE 598 Advanced Operating Systems Lecture 10

Processes. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & Apps 1

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

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

Processes and Threads

Chapter 3: Processes. Operating System Concepts Essentials 2 nd Edition

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

Process Concepts 8/21/2014. CS341: Operating System. Scheduling: Theoretical Analysis

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

Chapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

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

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

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

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Killing Zombies, Working, Sleeping, and Spawning Children

CS 537 Lecture 2 - Processes

CSE 153 Design of Operating Systems Fall 2018

Chapter 3: Processes

Process. Program Vs. process. During execution, the process may be in one of the following states

Processes. Operating System Concepts with Java. 4.1 Sana a University, Dr aimen

Chapter 3 Process Description and Control

CSC 539: Operating Systems Structure and Design. Spring 2006

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

Process Description and Control

Parameter Passing in C. Pointer Arithmetic. Parameter Passing in C. Pointer Arithmetic. Pointer Arithmetic. Tevfik Ko!ar

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

W4118 Operating Systems. Junfeng Yang

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

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

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

Chapter 4: Processes. Process Concept. Process State

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

Process Concept. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

COS 318: Operating Systems

CHAPTER 3 - PROCESS CONCEPT

Transcription:

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

Last class: Operating system structure and basics Today: Process Management

Why Processes? We have programs, so why do we need processes?

Binary to Process Dynamic State Multiple Processes Context Switch Identify a Process Processes Distinct versions, communication

Overview Questions that we explore How are processes created? How is a process represented and managed? Process creation, process control block How does the OS manage multiple processes? Process state, ownership, scheduling How can processes communicate? Interprocess communication, concurrency, deadlock

Processes

Process Address space + threads + resources Address space contains code and data of a process Threads are individual execution contexts Resources are physical support necessary to run the process (memory, disk, ) Text Data

Process Address Space Program (Text) Global Data (Data) Dynamic Data (Heap) Thread-local Data (Stack) Each thread has its own stack

Process Address Space int value = 5; Global int main() { int *p; Stack p = (int *)malloc(sizeof(int)); Heap if (p == 0) { printf("error: Out of memory\n ); return 1; } } *p = value; printf("%d\n", *p); free(p); return 0;

Program Address Space Text: Immutable code Global Data: Variables allocated with the program Lifetime is entire program Heap: Variables that are dynamically allocated Lifetime is between allocation (malloc) and deallocation (free) Stack: Variables allocated dynamically on the stack Lifetime is function lifetime

Program Address Space Where in a database process s address space would you allocate? Database Record Query specification

Process Loading

Program to Process Program is stored in a binary format Executable and Linkable Format (ELF) a.out Binary format describes Program sections Text, Data, (many types of sections) Program segments What to load at execution time One or more sections

ELF Files Source code test.c Compile into an ELF relocatable file test.o (object file) Compile into an ELF shared object file gcc -shared >> test.so (from.o files) Compile into an ELF executable file gcc -o test test.c

ELF Files ELF executable file contains segments Describes how to load them in memory ELF executable file also references any shared object files used Dynamically linked

Load and Run ELF Binaries Program Interpreter is loaded first Guides the loading process by interpreting ELF binaries Segment type PT_INTERP Run by exec Interpreter loads Loadable Segments Contains the program contents: text, global data Segment type PT_LOAD Mapped into the process address space at loadtime (you see these for libraries only) Others are loaded on demand, Dynamic Segment Libraries Segment type PT_DYNAMIC Load of separate library files when needed (you see these in opening of lib files)

Commands Linux: readelf Solaris: elfdump ELF Binary View Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align PHDR 0x000034 0x08048034 0x08048034 0x000e0 0x000e0 R E 0x4 INTERP 0x000114 0x08048114 0x08048114 0x00013 0x00013 R 0x1 [Requesting program interpreter: /lib/ld-linux.so.2] LOAD 0x000000 0x08048000 0x08048000 0x016b8 0x016b8 R E 0x1000 LOAD 0x0016b8 0x0804a6b8 0x0804a6b8 0x00120 0x00160 RW 0x1000 DYNAMIC 0x0016cc 0x0804a6cc 0x0804a6cc 0x000d0 0x000d0 RW 0x4 NOTE 0x000128 0x08048128 0x08048128 0x00020 0x00020 R 0x4 GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4. Dynamic section at offset 0x16cc contains 21 entries: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libm.so.6] 0x00000001 (NEEDED) Shared library: [libc.so.6]

Dynamic Linking Global Offset Table (GOT) Access to symbol in GOT results in dynamic loading and linking of associated library Program calls printf in libc Symbol points to dynamic linker at loadtime Loads libc library Fixes GOT pointer for printf to actual libc function Results in a level of indirection for calling library functions Slight performance cost

Executing a Process What to execute? Program status word Register that stores the program counter Next instruction to be executed Registers store state of execution in CPU Stack pointer Data registers Thread of execution Has its own stack

Executing a Proccess Thread executes over the process s address space Usually the text segment Until Time slice expires (timer interrupt) Another event (e.g., interrupt from other device) Exception (oops) System call (switch to kernel mode)

Process Creation

Program Creation Parent process create children processes, which, in turn create other processes, forming a tree of processes Resource sharing options Parent and children share all resources Children share subset of parent s resources Parent and child share no resources Execution options Parent and children execute concurrently Parent waits until children terminate

Address space Program Creation Child duplicate of parent Child has a program loaded into it UNIX examples fork system call creates new process exec system call used after a fork to replace the process s memory space with a new program

RAM OS Id=2000 State=ready PCB of parent Id=2001 State=ready PCB of child 1. PCB with new id created 2. Memory allocated for child Process calls fork Initialized by copying over from the parent 3. If parent had called wait, it is moved to a waiting queue Processes Parent s memory Child s memory 4. If child had called exec, its memory overwritten with new code & data 5. Child added to ready queue, all set to go now!

Program Creation What happens? New process object in kernel Build process data structures Allocate address space (abstract resource) Later, allocate memory (physical resource) Add to execution queue Runnable?

Process Creation (contd.)

C Program Forking Separate Process int main( ) { pid_t pid; /* fork another process */ pid = fork( ); if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); exit(-1); } else if (pid == 0) { /* child process */ execlp("/bin/ls", "ls", NULL); } else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL); printf ("Child Complete"); exit(0); } }

Design Choices Program Creation Resource Sharing What resources of parent should the child share? What about after exec? Execution Should parent wait for child? What is the relationship between parent and child? Hierarchical or grouped or?

Program Creation fork -- copy address space and all threads forkl -- copy address space and only calling thread vfork -- do not copy address space; shared between parent and child exec -- load new program; replace address space Some resources may be transferred (open file descriptors) Specified by arguments

A tree of processes on a typical system

Process Termination Process executes last statement and asks the operating system to delete it (exit) Output data from child to parent (via wait) Process resources are deallocated by operating system Parent may terminate execution of children processes (abort) Child has exceeded allocated resources Task assigned to child is no longer required If parent is exiting Some operating system do not allow child to continue if its parent terminates All children terminated - cascading termination

Process Execution state of a program Process Structure Address Space Process Creation From binary representation Dynamic Linking Process Creation From other processes Issues Process Groups Summary

Next time: More Processes