Killing Zombies, Working, Sleeping, and Spawning Children

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

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

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

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

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

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

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

Chapter 3: Processes

Chapter 3: Processes

Chapter 3: Process Concept

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

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

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

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 2016) Chapter 3: Process. Zhi Wang Florida State University

Chapter 3: Processes

Chapter 4: Processes. Process Concept

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

Chapter 4: Processes

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

Chapter 3: Process Concept

Chapter 3: Process Concept

Processes. Operating System Concepts 8 th Edition

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

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

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

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

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

Part Two - Process Management. Chapter 3: Processes

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

CHAPTER 3 - PROCESS CONCEPT

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

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

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313: Intro to Computer Systems

CS307 Operating Systems Processes

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

CHAPTER 2: PROCESS MANAGEMENT

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 4: Processes. Process Concept

CSC 539: Operating Systems Structure and Design. Spring 2006

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

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

Diagram of Process State Process Control Block (PCB)

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

TDIU25: Operating Systems II. Processes, Threads and Scheduling

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

Processes and Threads

The Big Picture So Far. Chapter 4: Processes

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

Lecture 2 Process Management

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

Chapter 3: Process Concept

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

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.

The Big Picture So Far. Chapter 4: Processes

Chap 4, 5: Process. Dongkun Shin, SKKU

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

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

Chapter 3: Processes. Operating System Concepts 9 th Edition

Operating Systemss and Multicore Programming (1DT089)

Operating Systems. Lecture 05

CSI Module 2: Processes

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

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

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

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

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

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

Chapter 3: Process Concept

CS370 Operating Systems

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

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

Announcements Processes: Part II. Operating Systems. Autumn CS4023

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

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

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

Processes COMPSCI 386

Chapter 4: Processes. Process Concept. Process State

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

Processes. Process Concept

o Reality The CPU switches between each process rapidly (multiprogramming) Only one program is active at a given time

Chapter 4: Processes

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

CS Lecture 2! Processes! George Mason University! Fall 2010!

Processes and Threads

SMD149 - Operating Systems

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Processes. CS3026 Operating Systems Lecture 05

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

Operating System Concepts Ch. 3: Processes

CS510 Operating System Foundations. Jonathan Walpole

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

Transcription:

Killing Zombies, Working, Sleeping, and Spawning Children CS 333 Prof. Karavanic (c) 2015 Karen L. Karavanic 1

The Process Model The OS loads program code and starts each job. Then it cleans up afterwards, freeing memory, clearing data structures, etc." Process an instance of a program during execution" Today we will discuss;" How to setup and start a process" How to stop a process" How to protect processes from each other" How to protect the Operating System from all processes " These questions pertain to The Process Model"

A simple program (part 1) 1 #include <stdio.h> " 2 #include <stdlib.h> " 3 #include <sys/time.h> " 4 #include <assert.h> " 5 #include "common.h" " "

A simple program (part 2) 7 int " 8 main(int argc, char *argv[]) " 9 { " 10 if (argc!= 2) { 11 "fprintf(stderr, "usage: cpu <string>\n"); 12 "exit(1); " 13 } " 14 char *str = argv[1]; " 15 while (1) { " 16 Spin(1); " 17 " printf("%s\n", str); " 18 } " 19 return 0; " 20 } "

The Process Model prompt>./cpu A & ;./cpu B & ;./cpu C & ;./cpu D & [1] 7353 [2] 7354 [3] 7355 " [4] 7356 " A B D " C " A " B " D " C " A " C " B " D " "

The Process Model Let s think: What information do we need to handle processes?" Start" Interrupt / Restart" Schedule"

The Process Abstraction A Process = a program in execution" You may see the terms job and process: process is correct, job is historical" A process includes:" program counter (PC): what instruction to execute next? " Stack: one stack frame per function called" Register values: what values currently held in hardware registers?" Program is passive entity, process is active " Program becomes process when executable file loaded into memory" Operating System Concepts Essentials 8 th Edition! 3.7! Silberschatz, Galvin and Gagne 2011!

The Process Abstraction The Process Address Space includes:" text section: the program code" program counter: next instruction to execute" Values of processor registers: smallest, fastest memory" Stack containing temporary data" Function parameters, return addresses, local variables" Data section containing global variables" Heap containing memory dynamically allocated during run time" 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" Operating System Concepts Essentials 8 th Edition! 3.8! Silberschatz, Galvin and Gagne 2011!

Process States 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" Operating System Concepts Essentials 8 th Edition! 3.9! Silberschatz, Galvin and Gagne 2011!

Process States Operating System Concepts Essentials 8th Edition! 3.10! Silberschatz, Galvin and Gagne 2011!

CPU Switch From Process to Process Operating System Concepts Essentials 8 th Edition! 3.11! Silberschatz, Galvin and Gagne 2011!

process == task Processes key idea: the OS virtualizes the CPU: we can have more than one program executing but each one is written as if it has the CPU to itself unit of execution. in timeshare system, each user had a separate shell. in multiprocessor server or multicore chip, user has > 1 task running concurrently process has context: structures in system that constitute that process (c) 2000 Mario Marchand and (c) 2014 Karen L. Karavanic 12

Process Scheduling Maximize CPU use, quickly switch processes onto CPU for time sharing" Process scheduler selects among available processes for next execution on CPU" Maintains scheduling queues of processes" Job queue set of all processes in the system" Ready queue set of all processes residing in main memory, ready and waiting to execute" Device queues set of processes waiting for an I/O device" Processes migrate among the various queues" Operating System Concepts Essentials 8 th Edition! 3.13! Silberschatz, Galvin and Gagne 2011!

Processes The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential processes Only one program active at any instant (c) 2000 Mario Marchand and (c) 2014 Karen L. Karavanic 14

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 pro */ Operating System Concepts Essentials 8 th Edition! 3.15! Silberschatz, Galvin and Gagne 2011!

Ready Queue And Various I/O Device Queues Operating System Concepts Essentials 8th Edition! 3.16! Silberschatz, Galvin and Gagne 2011!

Representation of Process Scheduling Operating System Concepts Essentials 8 th Edition! 3.17! Silberschatz, Galvin and Gagne 2011!

Schedulers Long-term scheduler (or job scheduler) selects which processes should be brought into the ready queue" Ex: Large Scientific Linux Cluster user may wait days from job submission to job scheduling" Short-term scheduler (or CPU scheduler) selects which process on the Ready Queue should be executed next, and allocates the CPU" Sometimes the only scheduler in a system" Operating System Concepts Essentials 8 th Edition! 3.18! Silberschatz, Galvin and Gagne 2011!

Schedulers (Cont.) Short-term scheduler is invoked very frequently (milliseconds) (must be fast)" Long-term scheduler is invoked very 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" Operating System Concepts Essentials 8 th Edition! 3.19! Silberschatz, Galvin and Gagne 2011!

Addition of Medium Term Scheduling Operating System Concepts Essentials 8th Edition! 3.20! Silberschatz, Galvin and Gagne 2011!

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 -> longer the context switch" Context switch time is dependent on hardware support" Ex: Some hardware provides multiple sets of registers per CPU -> multiple contexts loaded at once" Operating System Concepts Essentials 8 th Edition! 3.21! Silberschatz, Galvin and Gagne 2011!

Process Creation Principal events that cause process creation:" System initialization" Execution of a process creation system " User request to create a new process" Initiation of a batch job" (c) 2000 Mario Marchand and (c) 2014 Karen L. Karavanic 22

Operating System Concepts Essentials 8 th Edition! Process Creation Parent process creates child processes, which, in turn create grandchild processes, forming a tree of processes" Generally, process identified and managed via a process identifier (pid)" Resource sharing different models" Parent and children share all resources" Children share subset of parent s resources" Parent and child share no resources" Execution" " Parent and children execute concurrently" Parent waits until children terminate" 3.23! Silberschatz, Galvin and Gagne 2011!

Process Creation (Cont.) Address space" Child is created as a duplicate of parent:" Same program loaded into text segment" Same values in data segment" Same stack" Same register values" Same PC value" UNIX/Linux examples" fork system call creates new process" exec system call used after a fork to replace the process memory space with a new program" Operating System Concepts Essentials 8 th Edition! 3.24! Silberschatz, Galvin and Gagne 2011!

Process Creation Operating System Concepts Essentials 8 th Edition! 3.25! Silberschatz, Galvin and Gagne 2011!

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! Operating System Concepts Essentials 8 th Edition! 3.26! Silberschatz, Galvin and Gagne 2011!

Process Termination Conditions which terminate processes 1. Normal exit (voluntary) 2. Error exit (voluntary) 3. Fatal error (involuntary) 4. Killed by another process (involuntary) The kill command: kill [pid] can any process kill any other process? (c) 2000 Mario Marchand and (c) 2014 Karen L. Karavanic 27

Unix System Calls for Process Management s: an error code pid: a process ID status: Did the process exit normally? Yes: No: (c) 2000 Mario Marchand and (c) 2014 Karen L. Karavanic 28

What is a zombie process?? (c) 2000 Mario Marchand and (c) 2014 Karen L. Karavanic 29

POSIX signals - simple IPC IPC - interprocess communication Also used for kernel to process communication software interrupts for application you arrange for asynchronous call to a function that will handle the signal signals are events we can t predict what line of code will be executing when they occur can be caught, sent, or ignored (SIG_IGN) use kill(1) and kill(2) to send them (some of them) (c) 2000 Mario Marchand and (c) 2014 Karen L. Karavanic 30

Example Signal Functions SIGINT - catch control-c, exit program SIGSEGV - o.s. (mmu) forces program to exit because of memory violation SIGHUP - signal sent to daemon to tell it to exit system cleanly (shutdown) or to reread control file SIGSTOP, SIGCONT, job control of processes (SIGSTOP goes to background) SIGKILL - go away NOW... % kill -9 <pid> (c) 2000 Mario Marchand and (c) 2014 Karen L. Karavanic 31

POSIX Signals The signals required by POSIX. (c) 2000 Mario Marchand and (c) 2014 Karen L. Karavanic 32

Unix shells Shell is not part of the kernel, but makes heavy use of it User logs in over terminal, network, gets shell command line Each command is executed in a child process Each process at startup has 3 open file descriptors: stdin, stdout, stderr (fd=0, 1, 2) Child inherits these from parent (c) 2000 Mario Marchand and (c) 2014 Karen L. Karavanic 33

shellgame... shells handles redirection and pipes with certain metacharacters (>,<, ) date > file sort < file1 > file2 ls more can execute programs in background too ls & (c) 2000 Mario Marchand and (c) 2014 Karen L. Karavanic 34

Steps in executing ls at the Command line (c) 2000 Mario Marchand and (c) 2014 Karen L. Karavanic 35

Announcements If you missed Lab1 Wed morning: Come half hour early to lab this week to learn the setup and get your lab account Complete takehome version of lab to be graded Everyone should have attended Wed eve and Thurs eve Let me know if not The mailing list is not yet setup First Problem Set will be posted this week 36