?
Solved

Run 2 perl scripts simultaneously within a perl script

Posted on 2005-02-28
3
Medium Priority
?
387 Views
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?
0
Comment
Question by:jewee
  • 2
3 Comments
 
LVL 48

Assisted Solution

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

#!/usr/bin/perl
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'.
0
 
LVL 16

Accepted Solution

by:
manav_mathur earned 1000 total points
ID: 13427465
#!/usr/bin/perl
system "prog1&prog2&" and die "Failed $!\n";
print "Finished\n";

or
#!/usr/bin/perl
die("$! : Cant fork") unless (defined($pid = fork)) ;
if($pid) {
##parent process
system("prog1") and die("$! : prog1 failed") ;
}else{
##child process
system("prog2") and die("$! : prog2 failed");
}


0
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13448283
??

Manav
0

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