shayak has asked for the wisdom of the Perl Monks concerning the following question:

i have a script which installs application from a file. Now if the script is not able to install an application or taking too long it just waits. What i want is it to wait for some time and then go back to the list and goto the next application on the list and break the previous operation. I just dont want the script to keep on waiting for the application to install. How to do this..

Replies are listed 'Best First'.
Re: Dont wait too long for an operation
by moritz (Cardinal) on May 03, 2011 at 11:53 UTC
Re: Dont wait too long for an operation
by cdarke (Prior) on May 03, 2011 at 13:15 UTC
    See Proc::Background which has timeout features. It also has the addition advantage of running on UNIX syatmes and Windows.
Re: Dont wait too long for an operation
by locked_user sundialsvc4 (Abbot) on May 03, 2011 at 12:26 UTC

    Ignoring for a moment my general discomfort with the idea of a script installing an application ... I think that this is a good place to use a child-process.   The application forks, then the child execs the installer.   (Or it forks its own child to do so.)   The parent process(es), meanwhile, wait a while.

    If they conclude that something is wrong, very careful means must be taken to notify the installer that it must back out, and to wait for it to do so.   You cannot merely kill it, because this might well leave the entire system in an inconsistent state.

    Your strategy would “fall dead” if the update required a system restart, as most Windows changes do.

    Before pursuing this project very far at all, I would strongly suggest that you do some very diligent research to explore what existing programs might be available that already do this.   Many companies have to “push” system changes out to hundreds of workstations overnight, and there are already many well-developed architectures in place for doing this very thing.   (And if those tools cost money, even a lot of money, “big deal ... do it anyway.”   A trustworthy tool that can actually push mass changes, and can more-or-less guarantee either “clean success” or “no-change failure,” is worth a lot of money.)   This is a high-risk undertaking, and not a trivial one.

      Ya im doing it thru a parent and child process only. And regarding system failures and all this is a part of a testing process and the process is being done on vmwares. So not to worry about it. I just need a method in perl to do it..
Re: Dont wait too long for an operation
by anonymized user 468275 (Curate) on May 03, 2011 at 13:11 UTC
    my $pid; my $enough = 120; if ( $pid = fork ) { # parent sleep $enough; unless ( system( "ps -p $pid >/dev/null" ) ) { # 0 exit code means + found warn "feeling filicidal (plus item description)\n"; system "kill -9 $pid >/dev/null 2>&1"; } } else { # child ... install item ... exit; }
    Updated

    One world, one people