This question already has an answer here:

I am on Ubuntu GNOME 15.10 with GNOME 3.18, but I don't like the normal applications launcher so I have installed Docky, however often Docky suddenly closes and I am forced to manually restart it, so I was wondering how I could make a daemon which runs all the time in the background that would check at regular intervals if Docky is running, and if it is not, run it?

marked as duplicate by Jacob Vlijm, Sergiy Kolodyazhnyy, Community Apr 1 '16 at 9:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Do you not want to run a script kicked off by a cron job every 10-15 minutes to check it? – Terrance Mar 31 '16 at 23:18
  • @Terrance: That would probably be good. – user364819 Mar 31 '16 at 23:50
  • OK, let me throw something together for you here. :) – Terrance Mar 31 '16 at 23:54
  • Simple task, not too difficult to implement. What are requirements ? – Sergiy Kolodyazhnyy Apr 1 '16 at 0:10
  • I knew, because I answered this one: askubuntu.com/questions/751465/… – Jacob Vlijm Apr 1 '16 at 3:11

Create a script anywhere you want it to be, preferably in your home directory. I like to call mine, check_docky.bsh. In your script, do the following lines:


ps -ef | grep -i docky.exe | grep -v grep >/dev/null

case $? in
1) sh -c "mono /usr/lib/docky/Docky.exe";;
0) exit 0;;

In the above script, the ps -ef | grep will look to see if Docky is running. If it is not running the exit code that gets returned is 1, so then the case statement would relaunch Docky automatically. Else, the script would exit normally with a code 0.

Make sure the script is executable:

chmod +x check_docky.bsh

Then create a cron job for the script.

First, run crontab as you:

$ crontab -e

Then as a new entry add the following so that it will check every 10 minutes starting at :00 of the hour:

# m h  dom mon dow   command
*/10 * * * * /home/<username>/check_docky.bsh

To show that this command works:

~$ ps -ef | grep wookie | grep -v grep
~$ echo $?
~$ ps -ef | grep wookie
terrance  20978  6976  0 13:53 pts/17   00:00:00 grep --color=auto wookie
~$ echo $?

Hope this helps!

  • This answer is flawed as the exit code use will always be 0 due to grep -v grep always matching. You need to move that statement after ps -ef | grep -v grep or something like that. – 13m5 May 10 '18 at 18:57
  • @13m5 Check edit. Please test before you comment. – Terrance May 10 '18 at 19:55
  • @13m5 There is nothing wrong with that statement. I don't write answers that I don't test. grep -v grep makes it so that grep doesn't find itself as a process because technically it is a process at the moment. I know that there are other ways to do this, but this method works fine. – Terrance May 11 '18 at 14:25