Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I often run long calculations on my computer and I would like to shut it down when this are terminated.

Is there some option to shutdown the computer when a specific process termanates? Thanks for the help!

share|improve this question
up vote 2 down vote accepted

This should do the trick:

share|improve this answer
Thanks this seem would do the trick.. is it in the repos? – lucacerone Aug 11 '12 at 7:51
Not that I knew. According to the tutorial you have to add a ppa. Reply back if you need help with it. – Mrokii Aug 14 '12 at 20:48
Cuttlefish is now also in the extras repository of Ubuntu. So you should be able to install it through the Software Center without adding the PPA. – Alex Sep 20 '12 at 10:58

I don't know any out-of-the-box solution for this, but you could make cron check if the process is still there every hour or so. You could put something like this in a suitable place chmod it executable by root and symlink to it from /etc/cron.hourly :

PROCESSNUM = `ps x | grep -c "calculationthingy"` 
if [ "$PROCESSNUM" -lt 1 ] 
    # Make sure this in inactivated! 
    rm symlink_in_etc_hourly
    shutdown -h now 
share|improve this answer
thanks for the answer, but I can't entirely understand what the script does.. it gets the process number.. ok.. but what is that rm etc line? and which line I have to be sure it is inactive??? – lucacerone Aug 11 '12 at 7:49
It counts the number of running processes of what ever it is you are running. If this gets less than one it will shutdown the computer. But when you boot again, the script will still be run every hour (assuming you run it by linking to it in /etc/cron.hourly). If you don't have any processes of your calculating software running, the system will shutdown in your face the next time cron does its hourly job. To avoid that it might be a good idea to make the script inactivate itself by deleting the link to itself in cron.hourly. A bit crude, admittedly, but should do the job. – Hinz Aug 11 '12 at 20:42

Your Answer


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.