[Israel.pm] Problem timing-out a system command when script runs in the background

Yuval Yaari yuval at windax.com
Sun Aug 29 01:49:23 PDT 2004


Sorry, I forgot to mention that I /do/ have this line in my code too:
$SIG{ALRM} = sub { die "timeout" };

So I know the question "why would it die in case of alarm?" might pop up,
so here's the answer :)

  --Yuval

Yuval Yaari said:
> Hi,
>
> Sorry if the subject isn't descriptive enough.
> I wrote a script that extracts archives (zip, tar, gz, bz2, etc)
> recursivly. I had a problem with zip files that have a password, so I
> just used the famous alarm trick (read: hack) to time it out.
>
> The code is something like:
> eval {
>   alarm(600);
>   system('unzip', 'flags', $file);
>   alarm(0);
>   # Also check for return code, etc
> };
> if ($@) {
>   # Move the file away
>   alarm(0);
> }
>
> The problem is, that it won't work when I run the script in the
> background (using nohup or just adding an & in the end of the command
> line).
>
> I'm not sure why it might happen, but your ideas are more than welcome
> :)
>
> Also, if anyone has a solution for checking if a zip file is password
> protected, and/or timing it out better - let me know.
>
>
>   Thanks,
>   --Yuval
>
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl






More information about the Perl mailing list