Linux Zombie Process Orphan process

Source: Internet
Author: User

Today, someone asked about the zombie process and the orphan process, which has been encountered before, but not much attention, here mark

Zombie Process: The process fork out the subprocess, but the parent process does not call wait or waitpid to get the status information of the child process, the process description of the child process Fuzhengan saved in the system

Find Zombie Processes

Ps-a-ostat,ppid,pid,cmd | Grep-e ' ^[zz] '

Orphan process: The parent process exits, the child process continues, the orphan process will be adopted by Init (1) and the information collected by Init is completed.

Zombie Process Damage: When the process exits, the kernel releases all resources, including open files, memory, but still retains some information

, knowing that the parent process is released by Wait/waitpid, if the parent process does not fish wait waitpid, the reserved information will not be released, its process number will be occupied, the system process number is limited, if a large number of zombie processes, the system will not be able to generate new processes.

Orphan process is a process without a parent process, INIT will be responsible for the aftermath of the work, no harm

Child process (except Init) does not disappear immediately after exit, but instead becomes zombie, waiting for the parent process to handle

Eg: Zombie process

1#include <stdio.h>2#include <unistd.h>3#include <stdlib.h>4#include <errno.h>5 6 7 intMain ()8 {9pid_t PID =fork ();Ten     if(PID <0 )  One     {    Aprintf"fork_error\n"); -Exit1); -     }    the     Else if(PID = =0 )  -     {    -printf"Child \ n"); -Exit0); +     }    -  +  Aprintf"father....\n"); atSleep2); -System"Ps-o Pid,ppid,state,tty,command"); -printf"Father exit ...."); -     return 0; -}

The result of its operation

  

Orphan process

  

#include <stdio.h>#include<unistd.h>#include<stdlib.h>#include<errno.h>intMain () {pid_t PID=Fork (); if(PID <0) {printf ("fork_error\n"); Exit (1); }       Else if(PID = =0) {printf ("Child \ n"); printf ("PID:%d\tppid:%d\n", Getpid (), Getppid ()); printf ("sleep ..."); Sleep (4); printf ("PID:%d\tppid:%d\n", Getpid (), Getppid ()); printf ("Child Exit ..."); Exit (0); } printf ("father....\n"); printf ("Father exit ...."); return 0;}

Operation Result:

   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.