So I have some processes that run background jobs (resque) on servers and some of those jobs start a child process that occasionally gets stuck. I've found if I kill that child process everything goes back to normal. We have another script that can kill a binary process if it goes to long but it doesn't seem to work here. Usually I can do this:killall --older-than 20m <process>But these workers seem to be a little more tricky. Here is how they look in ps:jbsmith@server:~$ ps aux | grep resquewww-data 17652  0.0  1.8 794148 145940 ?       Sl   11:03   0:05 resque-1.26.0: Processing email since 1494525823 [Email]www-data  1026  0.0  1.9 787712 157080 ?       Sl   10:47   0:13 resque-1.26.0: Forked 17652 at 1494525823The Forked x at x is the child process and the one I need to kill. Is there a one liner command I can use to find processes maybe matching Forked and older than 20 minutes and kill them?
Kill child jobs that are running longer than 20 minutes
bash;shell script;process;background process
A one-liner, split onto two lines for less scrolling:ps aux | awk -v cutoff=$(( $(date +%s) - 20 * 60 ))  \  '/resque.*Forked [0-9]+ at [0-9]+/ { if ($NF < cutoff) system(kill  $2) }'It could be made tighter by using an output specifier for ps to limit the output to just the PID and COMM and ARG fields, then specifically matching COMM and ARGS, but the risks of a false-positive match seem low to me, here.