#!/usr/bin/perl -w # Wait for a certain process to finish, then proceed. use strict; if ($ARGV[0] eq "-h") { print " =head1 Usage waitfor [process-id] [command] Waits until the specified process (get id from *nix 'ps' commant) goes away (completes or dies), then proceeds with the command. Does *not* do the command if the process is not found to begin with. "; exit; } if ($ARGV[0] + 1 <= 1) { die "Don't recognize process id '$ARGV[0]'\n"; } my $pid = $ARGV[0]; shift; my $done = 0; while (!$done) { my $cmd = "ps -p $pid | grep -v 'TIME'"; print "$cmd\n"; my $p = `$cmd`; if ($p eq "") { last; } sleep 5; } print "Process $pid finished.\n"; my $args = join(" ",@ARGV); print "$args\n"; my $rc = `$args`; exit $rc;