Random   •   Archives   •   RSS   •   About   •   Contact

Prevent a certain program from running too long in bash

Update - I opensourced this script here: bash kira

I came up this this script to kill certain programs after they run for too long. This works like similar to a timeout. Warning this script is pretty harsh and kills the program.

#!/bin/bash
PROGRAM=replace-with-program-name
PIDSFILE=/tmp/kill-these.pids

for pid in `pidof $PROGRAM`
  do
    if grep -q $pid $PIDSFILE
      then
        kill $pid
    fi
  done

> $PIDSFILE

for pid in `pidof $PROGRAM`
  do
    echo $pid >> $PIDSFILE
  done

Then I wrote a cronjob to kill hung programs:

* * * * * /usr/local/sbin/killprogs.sh



Want comments on your site?

Remarkbox — is a free SaaS comment service which embeds into your pages to keep the conversation in the same place as your contentr. It works everywhere, even static HTML sites like this one!

Remarks: Prevent a certain program from running too long in bash

© Russell Ballestrini.