The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Hook::Fork - automatically run code after a fork

SYNOPSIS

    use Hook::Fork qw(register_child_fork_hook);
    register_child_fork_hook {
        print "fork\n";
    };

    fork();
    # prints "fork" from the child

DESCRIPTION

Forking can often confuse modules; if a parent opens a socket and sets come code to run at DESTROY to close it, that DESTROY will run in both the parent in the child. This means the child exiting can mess up the parent, or the parent exiting can mess up the child.

This module lets you run some code at fork time, so you can setup a new socket for the child, or something similar.

FUNCTIONS

register_child_fork_hook(&)

This registers another coderef to run in the child after fork.

register_parent_fork_hook(&)

This registers another coderef to run in the parent after fork.

register_before_fork_hook(&)

This registers another coderef to run before all forks.

DETAILS

All three functions work in the same way.

Normally, it pushes another handler onto the list of hooks

If you call it in scalar context, a guard object will be returned that removes the hook when the guard object goes out of scope.

Otherwise, the hook lives forever.

You can register as many hooks as you like. They run in FIFO order.

REPOSITORY

http://github.com/jrockway/hook-fork

To contribute, just click "fork", commit changes with impunity, and then send me a pull request. Thanks in advance!

AUTHOR

Jonathan Rockway <jrockway@cpan.org>

COPYRIGHT

Copyright (c) 2010 Jonathan Rockway

This module is free software. You can redistribute it under the same terms as perl itself.