PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Similar documents
PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Chapter 3: Processes

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

Chapter 3: Processes

CHAPTER 3 - PROCESS CONCEPT

Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 3: Processes. Operating System Concepts 9 th Edition

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 3 Processes. Process Concept. Process Concept. Process Concept (Cont.) Process Concept (Cont.) Process Concept (Cont.)

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

Chapter 3: Processes

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

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

Chapter 3: Process Concept

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

CS370 Operating Systems

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

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

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

Processes. Operating System Concepts 8 th Edition

The Big Picture So Far. Chapter 4: Processes

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

The Big Picture So Far. Chapter 4: Processes

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

Killing Zombies, Working, Sleeping, and Spawning Children

Diagram of Process State Process Control Block (PCB)

Process Concept. Chapter 4: Processes. Diagram of Process State. Process State. Process Control Block (PCB) Process Control Block (PCB)

Chapter 4: Processes

Chapter 3: Processes. Operating System Concepts 8th Edition

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

Chapter 4: Processes. Process Concept

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

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

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

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

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

Part Two - Process Management. Chapter 3: Processes

Processes and Threads

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

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

Chapter 4: Processes. Process Concept

CHAPTER 2: PROCESS MANAGEMENT

Chapter 4: Processes

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

CSC 539: Operating Systems Structure and Design. Spring 2006

CSE 153 Design of Operating Systems Fall 2018

Lecture 2 Process Management

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

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

Part V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection

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

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

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

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

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

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

Chap 4, 5: Process. Dongkun Shin, SKKU

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

CS307 Operating Systems Processes

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

TDIU25: Operating Systems II. Processes, Threads and Scheduling

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

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

Operating Systems. Lecture 05

Chapter 3: Process Concept

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

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

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

Processes COMPSCI 386

! The Process Control Block (PCB) " is included in the context,

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

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

2/14/2012. Using a layered approach, the operating system is divided into N levels or layers. Also view as a stack of services

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Lecture 3: Processes. CMPUT 379, Section A1, Winter 2014 January 13, 15 and 17

CSI Module 2: Processes

Chapter 4: Processes

Operating System Design

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

Chapter 4: Processes. Process Concept. Process State

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

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

2. PROCESS. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

Course: Operating Systems Instructor: M Umair. M Umair

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

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

Process and Its Image An operating system executes a variety of programs: A program that browses the Web A program that serves Web requests

Processes. Dr. Yingwu Zhu

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

Lecture 4: Process Management

csci3411: Operating Systems

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

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

Operating Systemss and Multicore Programming (1DT089)

Transcription:

PROCESS MANAGEMENT Operating Systems 2015 Spring by Euiseong Seo

Today s Topics Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication in Client-Server Systems

Process Concept An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks Textbook uses the terms job and process almost interchangeably Process a program in execution; process execution must progress in sequential fashion Multiple parts The program code, also called text section Current activity including program counter, processor registers Stack containing temporary data n Function parameters, return addresses, local variables Data section containing global variables Heap containing memory dynamically allocated during run time

Process Concept Program is passive entity stored on disk (executable file), process is active Program becomes process when executable file loaded into memory Execution of program started via GUI mouse clicks, command line entry of its name, etc One program can be several processes Consider multiple users executing the same program

Process in Memory 0 unused read- only segment (.init,.text,.rodata) read/write segment (.data,.bss) brk run- 8me heap (managed by malloc) code data stack pointer 0xffffffff user stack (created at run8me) kernel virtual memory (code, data, heap, stack) memory invisible to user code program

Process State As a process executes, it changes state new: The process is being created running: Instructions are being executed waiting: The process is waiting for some event to occur ready: The process is waiting to be assigned to a processor terminated: The process has finished execution

Diagram of Process State

Process State - Linux Example Linux example R: S: T: D: Z: <: N: s: +: l: Runnable Sleeping Traced or Stopped Uninterrup4ble Sleep Zombie High- priority task Low- priority task Session leader In the foreground process group Mul4- threaded

Process Control Block (PCB) Information associated with each process (also called task control block) Process state running, waiting, etc Program counter location of instruction to next execute CPU registers contents of all process-centric registers CPU scheduling information- priorities, scheduling queue pointers Memory-management information memory allocated to the process Accounting information CPU used, clock time elapsed since start, time limits I/O status information I/O devices allocated to process, list of open files

Process Control Block (PCB)

Process Representation in Linux Represented by the C structure task_struct pid t_pid; /* process identifier */ long state; /* state of the process */ unsigned int time_slice /* scheduling information */ struct task_struct *parent; /* this process s parent */ struct list_head children; /* this process s children */ struct files_struct *files; /* list of open files */ struct mm_struct *mm; /* address space of this process */

PCBs and Hardware State When a process is running Its hardware state is inside the CPU n PC, SP, registers When the OS stops running a process 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

CPU Switch From Process to Process

Threads So far, process has a single thread of execution Consider having multiple program counters per process Multiple locations can execute at once n Multiple threads of control -> threads Must then have storage for thread details, multiple program counters in PCB

Ready Queue And Various I/O Device Queues

Representation of Process Scheduling Queueing diagram represents queues, resources, flows

Schedulers Short-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU Sometimes the only scheduler in a system Short-term scheduler is invoked frequently (milliseconds) (must be fast) Long-term scheduler (or job scheduler) selects which processes should be brought into the ready queue Long-term scheduler is invoked infrequently (seconds, minutes) (may be slow) The long-term scheduler controls the degree of multiprogramming Processes can be described as either: I/O-bound process spends more time doing I/O than computations, many short CPU bursts CPU-bound process spends more time doing computations; few very long CPU bursts Long-term scheduler strives for good process mix

Addition of Medium Term Scheduling Medium-term scheduler can be added if degree of multiple programming needs to decrease Remove process from memory, store on disk, bring back in from disk to continue execution: swapping

Multitasking in Mobile Systems Some mobile systems (e.g., early version of ios) allow only one process to run, others suspended Due to screen real estate, user interface limits ios provides for a Single foreground process- controlled via user interface Multiple background processes in memory, running, but not on the display, and with limits Limits include single, short task, receiving notification of events, specific long-running tasks like audio playback Android runs foreground and background, with fewer limits Background process uses a service to perform tasks Service can keep running even if background process is suspended Service has no user interface, small memory use

Context Switch When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process via a context switch Context of a process represented in the PCB Context-switch time is overhead; the system does no useful work while switching The more complex the OS and the PCB è the longer the context switch Time dependent on hardware support Some hardware provides multiple sets of registers per CPU è multiple contexts loaded at once

Context Switch Context switch (or process switch) The act of switching the CPU from one process to another Administrative overhead n saving and loading registers and memory maps n flushing and reloading the memory cache n updating various tables and lists, etc. Context switch overhead is dependent on hardware support n Multiple register sets in UltraSPARC n Advanced memory management techniques may require extra data to be switched with each context 100s or 1000s of switches/s typically

Context Switch Linux Example Linux example Total 125,484 user ticks = 1,255 sec. Total 96,478,693 context switches

Operations on Processes System must provide mechanisms for: process creation, process termination, and so on as detailed next

Process Creation Process hierarchy One process can create another process: parentchild relationship UNIX calls the hierarchy a process group Windows has no concept of process hierarchy Browsing a list of processes: n ps in UNIX n taskmgr (Task Manager) in Windows $ cat file1 wc sh cat wc

Process Creation Process creation events Calling a system call n fork() in POSIX, CreateProcess() in Win32 n Shells or GUIs use this system call internally. System initialization n init process Background processes Do not interact with users Daemons

Process Creation Resource sharing Parent may inherit all or a part of resources and privileges for its children n UNIX: User ID, open files, etc. Execution Parent may either wait for it to finish, or it may continue in parallel Address space Child duplicates the parent s address space or has a program loaded into it

Process Creation (Cont.) fork() system call creates new process exec() system call used after a fork() to replace the process memory space with a new program

Process Termination Process termination events Normal exit (voluntary) Error exit (voluntary) Fatal error (involuntary) n Exceed allocated resources n Segmentation fault n Protection fault, etc. Killed by another process (involuntary) n By receiving a signal The parent process may wait for termination of a child process by using the wait()system call pid = wait(&status); If no parent waiting (did not invoke wait()) process is a zombie If parent terminated without invoking wait, process is an orphan

fork() #include <sys/types.h> #include <unistd.h> int main() { int pid; } if ((pid = fork()) == 0) /* child */ printf ( Child of %d is %d\n, getppid(), getpid()); else /* parent */ printf ( I am %d. My child is %d\n, getpid(), pid);

fork(): Example Output %./a.out I am 31098. My child is 31099. Child of 31098 is 31099. %./a.out Child of 31100 is 31101. I am 31100. My child is 31101.

Simplified UNIX Shell int main() { while (1) { char *cmd = read_command(); int pid; if ((pid = fork()) == 0) { /* Manipulate stdin/stdout/stderr for pipes and redirections, etc. */ exec(cmd); panic( exec failed! ); } else { wait (pid); } } }

Interprocess Communication Processes within a system may be independent or cooperating Cooperating process can affect or be affected by other processes, including sharing data Reasons for cooperating processes Information sharing Computation speedup Modularity Convenience Cooperating processes need interprocess communication (IPC) Two models of IPC Shared memory Message passing

Communications Models (a) Message passing. (b) shared memory. process A process B process A shared memory process B message queue m 0 m 1 m 2... m 3 kernel (a) m n kernel (b)

Producer-Consumer Problem Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process unbounded-buffer places no practical limit on the size of the buffer bounded-buffer assumes that there is a fixed buffer size

Inter-Process Communications Inside a machine Pipe FIFO Shared memory Sockets Across machines Sockets RPCs (Remote Procedure Calls) Java RMI (Remote Method Invocation)