Arijit Das wrote:

> Is there any way to time out a unix command?
>  
> Its something like this... I want my PerlPgm <might_hang.pl> to be
> killed by the shell (sh/bash/csh) if my PerlPgm fails to finish off by
> 300 elapsed seconds.
>  
> Something like
>  
> <timeout_shell_command> -timeout 300 might_hang.pl
>  
> This should execute might_hang.pl normally but if might_hang.pl fails to
> finish off by 300 elapsed secs, it should kill the might_hang.pl process.
>  
> I know that this can be achieved from inside might_hang.pl using alarms,
> but I needed to achieve that through a bourne shell i.e. the invoker of
> the Perl program (might_hang.pl).
>  
> Any thoughts about how this can be achieved...?

You could fork off a second script from inside the first and at the
end of the sleep or alarm (depending of which you use to time it),
you could check if the child is completed (waitpid) and if not, kill
it.
_______________________________________________
Perl-Unix-Users mailing list
Perl-Unix-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to