Clear questions and runnable code
get the best and fastest answer
system() does not waitby cbolcato (Novice)
|on Nov 30, 2005 at 20:33 UTC||Need Help??|
cbolcato has asked for the wisdom of the Perl Monks concerning the following question:
I have a script "SCRIPT1" use a system() function call to another perl script "SCRIPT2" that uses DBI. It appears that SCRIPT1 finishes prior to SCRIPT2. HOW COULD THIS BE???\n
I haven't been able to re-create the failure with test code, and I cannot post production code, but $? >> 8 = 16777215 for SCRIPT1 while SCRIPT2 is still running.
The following line of code were executed immediately after the system() and produced the out put below:
Oh, did I mention that it does not fail everytime!!
The following code was added and return the results stated below:
failed to execute: Illegal seek
The suggestion made by bluto that SCRIPT1 may be getting signaled got me thinking and testing along that path.
What I found is that SCRIPT2 wasn't sending a signal, but SCRIPT1 had an alarm set that would trigger the updating of a timestamp in a logfile.
If that alarm tripped while SCRIPT1 was waiting for a return from the system() call, control would come back to SCRIPT1 prior to SCRIPT2 completing, thus causing our failure condition.
Once, I identified the problem I have been able to re-create this senario in test.
The resolution was to turn the alarm off "alarm(0);" prior to performing the system() call.
Thanks, to all who responded. cbolcato