How do I kill processes older than "t"?

Solution 1:

GNU Killall can kill processes older than a given age, using their processname.

if [[ "$(uname)" = "Linux" ]];then killall --older-than 1h page.py;fi

Solution 2:

find doesnt always work, not every system has etimes available, and it might be my regex newb status, but I dont think you need anything more than this:

ps -eo pid,etimes,comm,user,tty | awk '{if ($4 ~ /builder/ && $5 ~ /pts/ && $2>600) print $1}'
  • list all processes and provide columns PID,ELAPSED(etimes = seconds), COMMAND, USER, TT (thanks @ahoffman)
  • with awk print the PID where the 4th column ($4, USER) contains text 'builder', and 5th column ($5, TT) contains text 'pts' and the ELAPSED column has a value larger than 600 sec (thanks @amtd)

you can then pipe that to kill or whatever your need may be.