1 / 11

Zombie and orphan processes

Zombie and orphan processes. Zombie process (from wikipedia).

misha
Download Presentation

Zombie and orphan processes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Zombie and orphan processes

  2. 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. 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.

  3. Orphan process (from wikipedia) 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.

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

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

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

  7. What does a zombie look like? • normal $ 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

  8. What does a zombie look like? • abnormal $ 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 <defunct> 1288 pts/2 00:00:00 ps

  9. 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 000 S 561 1074 1073 0 76 0 - 628 11a418 pts/2 00:00:00 bash 000 S 561 1301 1074 0 70 0 - 436 11f22b pts/2 00:00:00 parentTes 004 Z 561 1302 1301 0 70 0 - 0 119ffb pts/2 00:00:00 childTest 000 R 561 1320 1074 0 77 0 - 646 - pts/2 00:00:00 ps

  10. 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. 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.

  11. Avoiding zombies • To avoid creating zombie processes, the parent must: • Handle the SIGCHLD signal. • See man signal. • In this signal handling function, the parent must wait for the child process. • See man 2 wait.

More Related