Skip to content

Instantly share code, notes, and snippets.

@Dmitry-Kucher
Last active February 23, 2020 19:08
Show Gist options
  • Save Dmitry-Kucher/f670283487db6f6526cc938db7317be5 to your computer and use it in GitHub Desktop.
Save Dmitry-Kucher/f670283487db6f6526cc938db7317be5 to your computer and use it in GitHub Desktop.
Kill program after timeout reached

To use timeout killer functionality use the following instructions:

  • Download timeout-killer.sh
  • Replace PROGRAM_REGEXP and TIMEOUT to your own values
  • Add executable rights chmod +x timeout-killer.sh
  • Run timeout killer ./timeout-killer.sh
#!/bin/bash
PROGRAM_REGEXP=HERE_YOUR_PROGRAM_NAME
TIMEOUT=300
kill -9 $(ps -eo comm,pid,etimes | awk -v TIMEOUT=$TIMEOUT -v PROGRAM_REGEXP=$PROGRAM_REGEXP '$0 ~ PROGRAM_REGEXP {if ($3 > TIMEOUT) { print $2}}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment