Run 2 perl scripts simultaneously within a perl script

Posted on 2005-02-28
Medium Priority
Last Modified: 2008-03-17
I am write a perl script which will run 2 other perl scripts.  In these 2 perl scripts, they do some processing, but I need them to run simultaneously without having to wait for the 1st one to finish.

How do I go about doing this?
Question by:jewee
  • 2
LVL 48

Assisted Solution

Tintin earned 1000 total points
ID: 13424857
On a Unix system, you can do:

system "prog1 &" and die "Can not run prog1 $!\n";
system "prog2 &" and die "Can not run prog2 $!\n";
print "Finished\n";

However, if you want more portability and flexibility, you should use 'fork'.
LVL 16

Accepted Solution

manav_mathur earned 1000 total points
ID: 13427465
system "prog1&prog2&" and die "Failed $!\n";
print "Finished\n";

die("$! : Cant fork") unless (defined($pid = fork)) ;
if($pid) {
##parent process
system("prog1") and die("$! : prog1 failed") ;
##child process
system("prog2") and die("$! : prog2 failed");

LVL 16

Expert Comment

ID: 13448283


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question