Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

How to run a 2nd script in background?

by MelaOS (Beadle)
on Jan 03, 2008 at 02:42 UTC ( #660111=perlquestion: print w/replies, xml ) Need Help??
MelaOS has asked for the wisdom of the Perl Monks concerning the following question:

Hi Fellow monks, I seek your wisdom in solving this problem i have, hehe. I'm have a first script running and i want to add on a call to a second script which does heavy processing which takes up a lot of time. But i want the first script to end when it's done and not to wait for the second script. I've googled up for fork and multi threading, but i still don't have any clear idea on how to do this. Can this be done? ~thanks in advance~

Replies are listed 'Best First'.
Re: How to run a 2nd script in background?
by jwkrahn (Monsignor) on Jan 03, 2008 at 03:23 UTC
Re: How to run a 2nd script in background?
by jonnyfolk (Vicar) on Jan 03, 2008 at 05:44 UTC
    Here's one way:
    #run as child process my $pid; my $script = '/myroot/public_html/cgi-bin/'; if ($pid = fork) { #do something } elsif (defined $pid) { close STDOUT; system $script; } else { die "Major error: $!"; }
      Using system creates another process, exec is more appropriate here.

      If you are running on Windows you should be aware that fork creates a new thread, not a new process (fork is UNIX architecture). Also (on Windows) to run a script you should prefix the script name with 'perl', since file extension association is done at application, not OS, level. See also Win32::Process and Win32::FetchCommand.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://660111]
Approved by McDarren
[james28909]: well i have officially wore my brains out on hash refs and array refs and hash of arrays
[james28909]: push @{$hash{$ref}}, $this, $that, $the_other;
[james28909]: for 0 .. 3 {print $hash{$ref}}$_;
[james28909]: or i guess that is a hash ref
[james28909]: hash of array ref <.<
[james28909]: im also about to embark on porting the discord api to perl, without having to have 400 dependencies...
[james28909]: would be nice to link doscord to irc and other services

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2017-05-01 03:36 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (544 votes). Check out past polls.