Pages

Friday, February 5, 2010

Bash script- Kill a process if it runs too long

#!/bin/bash

# Can hang (google actually doesn't respond to ab useragent)
ab -c20 -n100 http://www.google.com

# get pid from previous command
pid=$!

# Wait for 10 seconds then send an interrupt
# apachebench will produce output if ctrl-c (or kill -2)
sleep 10 && kill -2 $pid > /dev/null 2>&1&

wait $pid

No comments:

Post a Comment