Zombie and orphan processes. Zombie process (from wikipedia) When a process ends, all of the memory and resources associated with it are deallocated.

Slides:



Advertisements
Similar presentations
Recitation 8 (Nov. 1) Outline Process & job control Lab 5 Reminder Lab 5: Due Thursday Minglong Shao Office hours: Thursdays 5-6PM.
Advertisements

Recitation 8: 10/28/02 Outline Processes Signals –Racing Hazard –Reaping Children Annie Luo Office Hours: Thursday 6:00.
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
15-213/ Intro to Computer Systems by btan with reference to Spring 10’s slides.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
Linux+ Guide to Linux Certification, Second Edition
Process Control in Unix Operating Systems Hebrew University Spring 2004.
CMPT 300: Operating Systems I Ch 3: Processes Dr. Mohamed Hefeeda
CSSE Operating Systems
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
UNIX Processes. The UNIX Process A process is an instance of a program in execution. Created by another parent process as its child. One process can be.
UNIX System Administration Handbook Chapter 4. Controlling Processes 3 rd Edition Evi Nemeth et al. Li Song CMSC691X Summer 2002.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes Tarek Abdelzaher Vikram Adve.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process System Process and init.
Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla.
Linux+ Guide to Linux Certification, Third Edition
System V IPC Provides three mechanisms for InterProcess Communication (IPC) : Messages : exchange messages with any process or server. Semaphores : allow.
Creating and Executing Processes
Linux+ Guide to Linux Certification, Second Edition Chapter 10 Managing Linux Processes.
Lecture – Performance Performance management on UNIX.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 3: Processes.
CE Operating Systems Lecture 10 Processes and process management in Linux.
Shell (Addendum). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
Process Control Process identifiers Process creation fork and vfork wait and waitpid Race conditions exec functions system function.
Scis.regis.edu ● CS 468: Advanced UNIX Class 4 Dr. Jesús Borrego Regis University 1.
System calls for Process management
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
Processes Dr. Yingwu Zhu. Process Concept Process – a program in execution – What is not a process? -- program on a disk - a process is an active object,
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes and Threads.
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
Process Management CS3320 Spring Process A process is an instance of a running program. –Not the same as “program” or “processor” Process provides.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
Operating Systems Process Creation
CS4315A. Berrached:CMS:UHD1 Process Management Chapter 6.
What is a Process? u A process is an executable “cradle” in which a program may run u This “cradle” provides an environment in which the program can run,
2.1 Processes  process = abstraction of a running program.
Chapter 3 – Processes (Pgs 101 – 141). Processes  Pretty much identical to a “job”  A task that a computer is performing  Consists of: 1. Text Section.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
Zombie and orphan processes. Zombie process (from wikipedia) When a process ends, all of the memory and resources associated with it are deallocated so.
S -1 Processes. S -2 wait and waitpid (11.2) Recall from a previous slide: pid_t wait( int *status ) wait() can: (a) block; (b) return with status; (c)
Tutorial 3. In this tutorial we’ll see Fork() and Exec() system calls.
System calls for Process management Process creation, termination, waiting.
2.1 Processes  process = abstraction of a running program  multiprogramming = CPU switches from running program to running program  pseudoparallelism.
1 Exceptional Control Flow Ⅱ. 2 Outline Kernel Mode and User Mode Process context switches Three States of Processes Context Switch System Calls and Error.
Unix System Administration Controlling Processes Chapter 5.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
Slide 1 COMP 3438 System Programming UNIX Processes UNIX Processes (Chapters 2 & 3)
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
1 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430.
G.Jyostna.
Section 8: Processes What is a process Creating processes Fork-Exec
Unix Process Management
Processes A process is a running program.
UNIX PROCESSES.
Tarek Abdelzaher Vikram Adve Marco Caccamo
Fork and Exec Unix Model
2.1 Processes process = abstraction of a running program
Process Creation Process Termination
Tutorial 3 Tutorial 3.
CHAPTER 13 Processes.
Processes Prof. Ikjun Yeom TA – Mugyo
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Process Description and Control in Unix
Process Description and Control in Unix
Presentation transcript:

Zombie and orphan processes

Zombie process (from wikipedia) When a process ends, all of the memory and resources associated with it are deallocated so they can be used by other processes. When a process ends, all of the memory and resources associated with it are deallocated so they can be used by other processes.

Zombie process (from wikipedia) However, the process's entry in the process table remains. However, the process's entry in the process table remains. The parent is sent a SIGCHLD signal indicating that a child has died; the handler for this signal will typically execute the wait system call, which reads the exit status and removes the zombie. The parent is sent a SIGCHLD signal indicating that a child has died; the handler for this signal will typically execute the wait system call, which reads the exit status and removes the zombie. The zombie's process ID and entry in the process table can then be reused. The zombie's process ID and entry in the process table can then be reused. However, if a parent ignores the SIGCHLD, the zombie will be left in the process table. However, if a parent ignores the SIGCHLD, the zombie will be left in the process table.

Orphan process (from wikipedia) A zombie process is not the same as an orphan process. A zombie process is not the same as an orphan process. Orphan processes don't become zombie processes; instead, they are adopted by init (process ID 1), which waits on its children. Orphan processes don't become zombie processes; instead, they are adopted by init (process ID 1), which waits on its children.

Example child process code printf( "child: %s running with %d arg(s). \n", argv[0], argc ); puts( "child: sleeping" ); sleep( 15 ); puts( "child: bye" ); return 0;

Parent that creates an orphan. puts( "parent: forking" ); puts( "parent: forking" ); pid_t ret = fork(); //now there’s two of us! pid_t ret = fork(); //now there’s two of us! switch (ret) { //which one? switch (ret) { //which one? case -1: //here when fork failed case -1: //here when fork failed puts( "parent: error: fork failed!" ); puts( "parent: error: fork failed!" ); break; break; case 0: //here when executing in child case 0: //here when executing in child puts( "child: here (before execl)!" ); puts( "child: here (before execl)!" ); if (execl( "./childTest.exe", "./childTest.exe", 0 )==-1) if (execl( "./childTest.exe", "./childTest.exe", 0 )==-1) perror( "child: execl failed:" ); perror( "child: execl failed:" ); puts( "child: here (after execl)!" ); //should never get here puts( "child: here (after execl)!" ); //should never get here break; break; default: //here when executing in parent default: //here when executing in parent printf( "parent: child has pid=%d \n", ret ); printf( "parent: child has pid=%d \n", ret ); puts( "parent: bye" ); puts( "parent: bye" ); break; break; } return 0; return 0;

Parent that creates a zombie (but only for 2 minutes). puts( "parent: forking" ); puts( "parent: forking" ); pid_t ret = fork(); switch (ret) { case -1: //here when fork failed case -1: //here when fork failed puts( "parent: error: fork failed!" ); puts( "parent: error: fork failed!" ); break; break; case 0: //here when executing in child case 0: //here when executing in child puts( "child: here (before execl)!" ); puts( "child: here (before execl)!" ); if (execl( "./childTest.exe", "./childTest.exe", 0 )==-1) if (execl( "./childTest.exe", "./childTest.exe", 0 )==-1) perror( "child: execl failed:" ); perror( "child: execl failed:" ); puts( "child: here (after execl)!" ); //should never get here puts( "child: here (after execl)!" ); //should never get here break; break; default: //here when executing in parent default: //here when executing in parent printf( "parent: child has pid=%d \n", ret ); printf( "parent: child has pid=%d \n", ret ); puts( "parent: sleeping" ); puts( "parent: sleeping" ); sleep( 120 ); sleep( 120 ); puts( "parent: bye" ); puts( "parent: bye" ); break; break;} return 0;

What does a zombie look like? normal (no zombie) normal (no zombie) $ ps PID TTY TIME CMD 1074 pts/2 00:00:00 bash 1280 pts/2 00:00:00 parentTest.exe 1281 pts/2 00:00:00 childTest.exe 1283 pts/2 00:00:00 ps

What does a zombie look like? abnormal (zombie) abnormal (zombie) $ ps PID TTY TIME CMD 1074 pts/2 00:00:00 bash 1280 pts/2 00:00:00 parentTest.exe 1281 pts/2 00:00:00 childTest.exe 1281 pts/2 00:00:00 childTest.exe 1288 pts/2 00:00:00 ps

What does a zombie look like? $ ps -l Warning: /boot/System.map has an incorrect kernel version. F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 000 S a418 pts/2 00:00:00 bash 000 S f22b pts/2 00:00:00 parentTes 004 Z ffb pts/2 00:00:00 childTest 000 R pts/2 00:00:00 ps

Zombie process (from wikipedia) When a process ends, all of the memory and resources associated with it are deallocated so they can be used by other processes. However, the process's entry in the process table remains. When a process ends, all of the memory and resources associated with it are deallocated so they can be used by other processes. However, the process's entry in the process table remains. The parent is sent a SIGCHLD signal indicating that a child has died; the handler for this signal will typically execute the wait system call, which reads the exit status and removes the zombie. The parent is sent a SIGCHLD signal indicating that a child has died; the handler for this signal will typically execute the wait system call, which reads the exit status and removes the zombie. The zombie's process ID and entry in the process table can then be reused. However, if a parent ignores the SIGCHLD, the zombie will be left in the process table. The zombie's process ID and entry in the process table can then be reused. However, if a parent ignores the SIGCHLD, the zombie will be left in the process table.

Avoiding zombies To avoid creating zombie processes, the parent must: To avoid creating zombie processes, the parent must: 1. Handle the SIGCHLD signal. See man signal. See man signal. 2. In this signal handling function, the parent must wait for the child process. See man 2 wait (linux) or man –s 3C wait (solaris). See man 2 wait (linux) or man –s 3C wait (solaris). We will explore signals as an interprocess communications (IPC) mechanism shortly. We will explore signals as an interprocess communications (IPC) mechanism shortly.