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

Similar documents
Process Description and Control. Chapter 3

Process Description and Control. Major Requirements of an Operating System

Major Requirements of an Operating System Process Description and Control

Process Description and Control. Chapter 3

Process Description and Control

Process Description and Control

Process Description and Control. Chapter 3

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

Major Requirements of an OS

Operating System Control Structures

IT 540 Operating Systems ECE519 Advanced Operating Systems

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

Operating Systems. Lecture 3- Process Description and Control. Masood Niazi Torshiz

Chapter 3 Process Description and Control

Process. Discussion session 3 1/30/2016

Wednesday, September 14, Chapter 3: Processes

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

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

Process Description and Control

OPERATING SYSTEM. The Process. Introduction Process creation & termination Process state diagram Process scheduling & its criteria

Processes, PCB, Context Switch

Chap 4, 5: Process. Dongkun Shin, SKKU

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

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

Today s class. Finish review of C Process description and control. Informationsteknologi. Tuesday, September 18, 2007

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch-3 Process Description and Control

CSCE Introduction to Computer Systems Spring 2019

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Why use an Operating System? Operating System Definition

Processes. CS3026 Operating Systems Lecture 05

Operating Systems. Computer Science & Information Technology (CS) Rank under AIR 100

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

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

Process Description and Control

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

Processes and Non-Preemptive Scheduling. Otto J. Anshus

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

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

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Process Scheduling Queues

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

Operating Systems. Lecture 05

Noorul Islam College Of Engineering, Kumaracoil MCA Degree Model Examination (October 2007) 5 th Semester MC1642 UNIX Internals 2 mark Questions

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

Computer Systems II. First Two Major Computer System Evolution Steps

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

Operating System. Chapter 3. Process. Lynn Choi School of Electrical Engineering

CSC 539: Operating Systems Structure and Design. Spring 2006

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

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Processes. Dr. Yingwu Zhu

Process! Process Creation / Termination! Process Transitions in" the Two-State Process Model! A Two-State Process Model!

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

PROCESS DESCRIPTION AND CONTROL

CSCE 313: Intro to Computer Systems

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

Introduction to Processes in Computer Systems SEEM

Multiprogramming. Evolution of OS. Today. Comp 104: Operating Systems Concepts 28/01/2013. Processes Management Scheduling & Resource Allocation

SMD149 - Operating Systems

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

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

CS 322 Operating Systems Practice Midterm Questions

Course: Operating Systems Instructor: M Umair. M Umair

Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management

Mon Sep 17, 2007 Lecture 3: Process Management

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

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

3.1 Introduction. Computers perform operations concurrently

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

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

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

Processes and Threads

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

Lecture 4: Process Management

PROCESS CONCEPTS. Process Concept Relationship to a Program What is a Process? Process Lifecycle Process Management Inter-Process Communication 2.

Operating Systems Process description and control

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

UNIX Memory Management Interview Questions and Answers

OS Main Goals. 10/24/2013 Operating Systems, Beykent University 1

Lecture Topics. Announcements. Today: Operating System Overview (Stallings, chapter , ) Next: Processes (Stallings, chapter

Chapter 3 Process Description and Control

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Creating Threads COMP755

UNIX Processes. by Armin R. Mikler. 1: Introduction

Processes COMPSCI 386

Operating Systems Comprehensive Exam. Spring Student ID # 3/20/2013

Operating System Structure

W4118 Operating Systems. Junfeng Yang

Introduction to Process in Computing Systems SEEM

CS510 Operating System Foundations. Jonathan Walpole

The Kernel Abstraction. Chapter 2 OSPP Part I

Chapter 3: Process Concept

Chapter 3: Process Concept

Lecture 5: Process Description and Control Multithreading Basics in Interprocess communication Introduction to multiprocessors

3. Process Management in xv6

CS 537 Lecture 2 - Processes

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

PROCESS STATES AND TRANSITIONS:

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

Chapter 3: Process Concept

Transcription:

Processes Process Management Chapter 3 1 A process is a program in a state of execution (created but not terminated) Program is a passive entity one on your disk (survivor.class, kelly.out, ) Process is an active entity in memory. A unit to which OS allocates resources OS interleaves the execution of several processes. OS allocates resources to processes For example, memory, CPU time, # of socket connections etc OS allows users to create processes and processes to spawn other processes OS supports communication among processes Also known as IPC (inter-process communication) 2 When does a process gets created? Submission of a batch job User logs on Created by OS to provide a service to a user (ex: printing a file) Spawned by an existing process a user program can dictate the creation of a number of processes When does a process gets terminated? Batch job issues Halt instruction User logs off Process executes a service request to terminate Error and fault conditions 3 4 1

Reasons for Process Termination Reasons for Process Termination Normal completion Time limit exceeded Memory unavailable Memory bounds violation Protection error example: write to read-only file Arithmetic error Time overrun process waited longer than a specified maximum for an event 5 I/O failure Invalid instruction happens when try to execute data Privileged instruction Operating system intervention such as when deadlock occurs Parent request to terminate one offspring Parent terminates so child processes terminate 6 Process States Other Useful States Let us start with these states: The Running state The process that gets executed (single CPU) The Ready state any process that is ready to be executed The Blocked state when a process cannot execute until some event occurs (ex: the completion of an I/O) The New state OS has performed the necessary actions to create the process has created a process identifier has created tables needed to manage the process but has not yet committed to execute the process (not yet admitted) because resources are limited 7 8 2

Other Useful States Process Transitions The Exit state Termination moves the process to this state It is no longer eligible for execution Tables and other info are temporarily preserved for auxiliary program Ex: accounting program that cumulates resource usage for billing the users The process (and its tables) gets deleted when the data is no more needed Ready --> Running When it is time, the dispatcher selects a new process to run Running --> Ready the running process has expired his time slot the running process gets interrupted because a higher priority process is in the ready state 9 10 Process Transitions A Five-state Process Model Running --> Blocked When a process requests something for which it must wait a service that the OS is not ready to perform an access to a resource not yet available initiates I/O and must wait for the result waiting for a process to provide input (IPC) Blocked --> Ready When the event for which it was waiting occurs Ready to exit: A parent may terminate a child process 11 12 3

A Queuing Discipline Operating System Control Structures An OS maintains the following tables for managing processes and resources: Memory tables (see later) I/O tables (see later) File tables (see later) Process tables (this chapter) Ready queue without priorities (ex: FIFO) When event n occurs, the corresponding queue is moved into the ready queue 13 14 Process Image (process constituents) Process images in memory User program User data Stack(s) for procedure calls and parameter passing Process Control Block (execution context) Data needed (process attributes) by the OS to control the process. This includes: Process identification information Processor state information Process control information 15 16 4

Location of the Process Image Process Identification (in the PCB) Each process image is in memory may not occupy a contiguous range of addresses (depends on the memory management scheme used) both a private and shared memory address space is used The location if each process image is pointed to by an entry in the Process Table For the OS to manage the process, at least part of its image must be brought into main memory 17 A few numeric identifiers may be used Unique process identifier (always) indexes (directly or indirectly) into the primary process table User identifier the user who is responsible for the job Identifier of the process that created this process 18 Processor State Information (in PCB) Process Control Information (in PCB) Contents of processor registers User-visible registers Control and status registers Stack pointers Program status word (PSW) contains status information Example: the EFLAGS register on Pentium machines scheduling and state information Process state (ie: running, ready, blocked...) Priority of the process Event for which the process is waiting (if blocked) data structuring information may hold pointers to other PCBs for process queues, parent-child relationships and other structures 19 20 5

Queues as linked lists of PCBs Process Control Information (in PCB) Running Ready Blocked Process Control Block 21 Inter-process communication may hold flags and signals for IPC process privileges Ex: access to certain memory locations... memory management pointers to segment/page tables assigned to this process resource ownership and utilization resource in use: open files, I/O devices... history of usage (of CPU time, I/O...) 22 Context Switching Steps in Process (Context) Switching Kernel switches among processes When a process finishes its time slice or blocks or terminates Kernel schedules the next ready process This activity is called context switching Each process has state (or context) that needs to be saved before switching to another process -- Why 23 Save context of processor including program counter and other registers Update the PCB of the running process with its new state and other associate info Move PCB to appropriate queue - ready, blocked Select another process for execution Update PCB of the selected process Restore CPU context from that of the selected process 24 6

Executing OS code Crossing user mode to kernel mode Application programs cannot directly access I/O devices, other resources etc Still, applications must request OS to access them How does the user/application execute instructions Application uses system calls System calls are traps (special instructions) After a trap, CPU executes in a special mode called kernel mode OS Code can only be executed when CPU is in kernel mode User-mode program calls kernel procedure using system call System call causes CPU to switch to kernel mode Once the system call is executed, the CPU reverts back to user mode USER Mode Kernel Mode Applications Code for System calls Trap Trap handler Interrupt Routines 25 26 Modes of Execution Execution within User Processes To provide protection to PCBs (and other OS data) most processors support at least 2 execution modes: Privileged mode (a.k.a. system mode, kernel mode, supervisor mode, control mode ) manipulating control registers, primitive I/O instructions, memory management... User mode For this the CPU provides a (or a few) mode bit which may only be set by an interrupt or trap or OS call 27 Virtually all OS code gets executed within the context of a user process On Interrupts, Traps, System calls: the CPU switch to kernel mode to execute OS routine within the context of user process (mode switch) Control passes to process switching functions (outside processes) only when needed 28 7

Execution within User Processes UNIX Process Creation OS code and data are in the shared address space and are shared by all user processes Separate kernel stack for calls/returns when the process is in kernel mode Within a user process, both user and OS programs may execute (more than once) 29 Every process, except process 0, is created by the fork() system call fork() allocates entry in process table and assigns a unique PID to the child process child gets a copy of process image of parent: both child and parent are executing the same code following fork() but fork() returns the PID of the child to the parent process and returns 0 to the child process 30 UNIX System Processes Examples of fork Process 0 is created at boot time and becomes the swapper after forking process 1 (the INIT process) When a user logs in: process 1 creates a process for that user Example1 Child process Prints a statement Example 2 Parent process prints a statement Example 3 Parent and child print statements Example 4 Parent and child prints with wait system call 31 32 8

Wait /exit system call Semantics of exec system call int wait(int *statusp) Wait() system call delays its caller until one of its child terminates Return 1 if no child process exists exit system call exit(int status) This system call terminates the calling process exec system call replaces the current image Process ID remains the same execlp(file,arg0,arg1, argv) 33 34 UNIX Process Image User-level context Process Text (ie: code: read-only) Process Data User Stack (calls/returns in user mode) Register context UNIX Process Image System-level context Process table entry the actual entry concerning this process in the Process Table maintained by OS Process state, UID, PID, priority, event awaiting, signals sent, pointers to memory holding text, data... U (user) area additional process info needed by the kernel when executing in the context of this process effective UID, timers, limit fields, files in use... Kernel stack (calls/returns in kernel mode) Per Process Region Table (used by memory manager) 35 36 9