Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to make a crontab job for killing any firefox processes running, if there is more than a max number of processes running, starting with the oldest process.

So let's say 5 processes is running and I only wan't to allow a maximum of 2, then kill the 3 oldest automatically.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Here goes bash script:

#!/bin/bash

let COUNT=$(pgrep firefox | wc -l)
for (( i=1; i<=$COUNT-2; i++ ))
do
  PID=$(pgrep -o firefox)
  pkill $PID
# sleep 3
done
share|improve this answer
    
You can uncomment sleep line to add a timeout if this script is too fast and not killing processes as intended. –  whtyger Jan 18 '13 at 14:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.