Newsgroups: comp.unix.shell Date: 2000/11/26
>How can I make it so the command only runs for a specified amount >of time, say 5 seconds, then continues with the script?
my_command & sleep 5; kill $!
> > Useful - how would you make it continue if my_command exited before > > the sleep had finished?
> Put at 'if' statement around the kill as such: > my_command & > sleep 5 > PC=`ps -ef | grep $! | grep -v grep | wc -l ` > if (( PC > 0 )) > then > kill $! > fi
That's a lot of forks just to see if "kill $!" would work. How about:
my_command & sleep 5 kill -0 $! && kill $!
Regards,
Craig