books
Free Books / Computers / Practical mod_perl /

previous page: 10.2.2. Freeing the Parent Process
  
page up: Practical mod_perl | by Stas Bekman and Eric Cholet
  
next page: 10.2.4. Avoiding Zombie Processes

10.2.3. Detaching the Forked Process




Description

This section is from the "Practical mod_perl" book, by Stas Bekman and Eric Cholet. Also available from Amazon: Practical mod_perl

Now what happens if the forked process is running and we decide that we need to restart the web server? This forked process will be aborted, because when the parent process dies during the restart, it will kill its child processes as well. In order to avoid this, we need to detach the process from its parent session by opening a new session with help of a setsid( ) system call (provided by the POSIX module). This is demonstrated in Example 10-15.

Example 10-15. fork3.pl

use POSIX 'setsid';

defined (my $kid = fork) or die "Cannot fork: $!\n";
if ($kid) {
    # Parent runs this block
}
else {
    # Child runs this block
    setsid or die "Can't start a new session: $!";
    # ...
}

Now the spawned child process has a life of its own, and it doesn't depend on the parent any more.

 

Continue to:

  • prev: 10.2.2. Freeing the Parent Process
  • Table of Contents
  • next: 10.2.4. Avoiding Zombie Processes

Books by Stas Bekman:















TOP
previous page: 10.2.2. Freeing the Parent Process
  
page up: Practical mod_perl | by Stas Bekman and Eric Cholet
  
next page: 10.2.4. Avoiding Zombie Processes

Topics

  • Animals
  • Architecture
  • Arts
  • Business
  • Computers
  • Crafts
  • Fairy Tales
  • Finance
  • Flora and Plants
  • Cooking
  • Gardening
  • Health and Healing
  • History
  • Home Improvements
  • Languages
  • New Age
  • Novels
  • Real Estate
  • Reference
  • Religion
  • Science
  • Society
  • Sports
  • Travel
  • Outdoors


Search

My Books

Headaches Begone! A Systemic Approach To Healing Your Headaches
Don't Let Your Bike Seat Ruin Your Sex Life Book

Discover

  • Answers FAQ

[ Privacy Policy | Terms of Use | About Us | Search ]

© 2007-2021 StasoSphere.com