I have a question concerning how to regain control after issueing a
system command to start another program. The other program, called MEVS, both must run 24/7. The perl program is a bandaid that looks to see if MEVS is running and, if not, then it starts it up. The bandaid is a perl module while MEVS is a large system written in C++.
My problem is that control never comes back. I looked at the process ids and the new program was running okay, however, MEVs had the parent pid which belonged to the bandaid module that issued the system command to start it. Cancelling the bandaid.pl program also cancels the MEVS program. It looks like the bandaid module was waiting for a response or for the new process to finish before control would return.
Do I need to create a fork and then an exec? I thought that was what the system command was for? The two commands following the
system command never get executed.
$version = "test";
$pid = get_pid($version);
if ( $pid eq "" ) # if null, MEVS not running - issue comma
+nd to start MEVS
{
@command = ("/mevs/$version/bin/mevs", "/mevs/$version/data/con
+fig_data/mevs2.cfg", "online", "&");
system(@command); # restart MEVS
$pid = get_pid($version); # Get the new pid
print "new pid: [$pid]\n"; # print pid
.
.
.
######################################################################
+######
sub get_pid
######################################################################
+######
{
my $version = $_[0]; # passed version, prod/test/qa
my $command = sprintf q(ps -ef | grep %s | grep online | awk '{pri
+nt $2}'), $version; # create get pid command
my @output = `$command`; # get the pid(s)
return $output[0]; # return new pid
+
}
Thanks for all your help.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.