Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Updated this description: I'm looking at a program in which a connection to MySQL is established via the DBI module. Then a wget command is issued that takes a long time. During that time, the database connection times out, and must send a signal to the parent. This causes $? and $! to be set. But in addition to those, the system('wget') call returns -1. I know the wget succeeds, because the file is completely downloaded. But since system() returns -1, it looks like the wget failed!

Update2: I think Tye figured this out while we were chatting in the CB: system calls waitpid, and waitpid is interrupted by the signal. So my child wget command keeps on executing the background, while the perl script resumes execution.

I wrote a sample program that shows the same problem, but I think that it might be causing confusion. I don't want the child to receive the signal, nor am I using this alarm as a timeout to make sure the system call doesn't hang. My use of alarm w/ system here may be wrong, as mr_mischief pointed out to me. I'm leaving it here though, because I *think* it demonstrates the same problem.

#!/usr/bin/env perl use strict; use warnings; $SIG{ALRM} = sub { print( "Alarm triggered, making system call...\n" ); unlink('/doesnt/exist'); # this will definitely fail }; alarm( 2 ); my $retval = system('sleep 4'); if( $retval == -1 ) { print( "system() retval = $retval; " . '$?' . " = $?; " . '$!' . " + = $!\n" ); } elsif( $retval == 0 ) { print( "system() returned 0\n" ); } else { print( "system() return $retval\n" ); }
And so here is a test run:
test$ ./ Alarm triggered, making system call... system() retval = -1; $? = -1; $! = No such file or directory
I searched the archives, and I found an old node that may be related.

I tested this on two different systems, with two different perl version. Some system details:
System 1: $ perl -v This is perl, v5.8.8 built for i386-linux-thread-multi libc=/lib/ $ uname -a Linux hostname.removed 2.6.18-8.1.1.el5 #1 SMP Mon Feb 26 20:38:02 EST + 2007 i686 i686 i386 GNU/Linux System 2: test$ perl -v This is perl, v5.8.6 built for i686-linux-64int libc=/lib/ test$ uname -a Linux hostname.removed 2.6.9-55.0.6.ELsmp #1 SMP Tue Sep 4 21:36:00 ED +T 2007 i686 unknown
I haven't been able to find any documentation about this behavior. Is this intended? If so, how can I trust system's return value?

In reply to System call + signals = bad return code? by swkronenfeld

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2023-01-31 10:25 GMT
Find Nodes?
    Voting Booth?

    No recent polls found