Created
April 18, 2016 07:15
-
-
Save tkuchiki/6a4fe3615edcda514877fcc332d91033 to your computer and use it in GitHub Desktop.
指定秒数経過したプロセスを kill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
epoch=$(sed -n 's/^btime //p' /proc/stat) | |
clk_tck=$(getconf CLK_TCK) | |
now=$(date +%s) | |
seconds=300 | |
for pid in $(ps aux | grep jav[a] | awk '{print $2}'); do | |
start_time=$(awk '{print $22}' /proc/${pid}/stat) | |
ps_uptime=$(($now - ( $epoch + ($start_time / $clk_tck) ) )) | |
if [ ${ps_uptime} -ge ${seconds} ]; then | |
kill -TERM ${pid} | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment