Skip to content

Instantly share code, notes, and snippets.

@wehappyfew
Created March 24, 2016 10:10
Show Gist options
  • Save wehappyfew/720cd12798bb066f7c87 to your computer and use it in GitHub Desktop.
Save wehappyfew/720cd12798bb066f7c87 to your computer and use it in GitHub Desktop.
Bash script to kill any firefox instance that runs for more than 10 minutes [runs every 1 minute]
# Notice: to run it, create a cronjob with the line below
# */1 * * * * root sh /path/to/file/kill_stuck_firefox.sh
#!/bin/bash
# This script will kill process which running more than 10 minutes
# egrep: the selected process; grep: hours
PIDS="`ps eaxo etime,pid,comm | egrep "firefox" | grep " [1-5][0-9]:" | awk '{print $2}'`"
# Kill the process
echo "Killing firefox processes running more than 10 minutes..."
for i in ${PIDS}; do { echo "Killing $i"; sudo kill -9 $i; }; done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment