halfthelaw has asked for the wisdom of the Perl Monks concerning the following question:

Hey-
I need help figuring out how to fork processes. I've done plenty of searching, but all the docs I've been able to find relate to forking threads, not processes. All I really need to is start a seperate process without waiting for it to return.
How can I do this?
Thanks.

Replies are listed 'Best First'.
Re: Forking seperate processes?
by Errto (Vicar) on Feb 19, 2006 at 03:47 UTC

    See fork. If you need to run a separate program in this separate process, you can also look at exec. If you want to fork an external program and have a pipe to either its standard input or output, then open can take care of this for you (see perlopentut for a tutorial on that).

      I don't need access to it's standard input or input, and exec won't work because I still want the main program to be able to continue doing other stuff.
        Then you probably want to use fork and exec together like this:
        # we're in the "main program"... my $child = fork(); die "fork failed: $!" unless ( defined( $child )); if ( $child == 0 ) { # the child process does this: exec( 'other_program', @args ); } # the parent now goes on to do whatever follows, while the child is ru +nning...
Re: Forking seperate processes?
by ambrus (Abbot) on Feb 19, 2006 at 13:41 UTC

    Som good documentations are perldoc perlipc and the info documentation of gnu libc.

Re: Forking seperate processes?
by leighsharpe (Monk) on Feb 19, 2006 at 22:19 UTC
    $SIG{CHLD}='IGNORE'; #Make sure there are no zombies after children + die. my $pid=fork; print "Failed to fork: $!\n" unless(defined($pid)); unless ($pid) { #Child process here. } #Parent process continues.