Skip to content

Instantly share code, notes, and snippets.

@stephen-soltesz
Last active November 14, 2016 22:03
Show Gist options
  • Save stephen-soltesz/1526c9ad4b370823da10 to your computer and use it in GitHub Desktop.
Save stephen-soltesz/1526c9ad4b370823da10 to your computer and use it in GitHub Desktop.
Run with: ./fetch.py --user iupui_ndt --nodelist ../plsync/good.ndt.txt --threadcount=40 --timeout 300 --script kill_ndt
(
parent=$( pstree -a -A -p | grep ndtd | grep -v grep | head -1 | tr ',' ' ' | awk '{print $2}' )
ps ax -opid,args \
| grep ndtd \
| grep -v grep \
| awk 'BEGIN {
start_time_index = 22 ;
utime_index = 14 ;
stime_index = 15 ;
# All older processes will have an earlier (smaller) start_time.
"cat /proc/self/stat" |& getline result ; split(result, proc) ;
awk_start = proc[start_time_index] ;
}
{
# Read the start_time of each NDT process.
sprintf("cat /proc/%d/stat", $1) |& getline result ; split(result, proc) ;
cpu_time = proc[utime_index] + proc[stime_index] ;
t_diff = awk_start - proc[start_time_index] ;
# NDT should not last longer than 5 minutes (300 sec, 30000 ticks).
if ('$parent' != $1) {
if (t_diff > 30000 ) {
print "killed_child_of", '$parent', "cpu", cpu_time, "tdiff", t_diff, result ;
system(sprintf("sudo kill %d", $1)) ;
}
}
}'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment