I have a background process to sync and index email. The two function calls in there, (mail-sync) and (mail-index) are calls with start-process. I then run the mail-background function periodically with run-with-timer.

The relevant code is:

(defun mail-background ()
    (lambda (p e)
      (when (= 0 (process-exit-status p))

(run-with-timer 0 (* 5 60) 'mail-background)

There are two issues I have with this setup:

  1. I don't know how to monitor the timer, so I can see failures, when it stopped running, etc.
  2. When my computer (macOS) goes to sleep, sometimes the timer continues when I come back, and sometimes it has stopped, which brings me to the first point.

I'm sure there is a better way to do what I am doing, so any pointer on that appreciated. Or, I'd just like to know how I can monitor and restart the background processes that are being run with run-with-timer as a first step.

  • Why does your background process have to be running all the time? If you create a simple recurring timer function that displays a message of "hello-world", are you able to see it resume when your computer wakes up after a long-sleep? How about just running a new process each time your computer runs the timer function, which can also be on an idle-timer so as not to interrupt your workflow? [I don't use mu4e specifically because it has a background mu process running 24/7 and I refused to subject myself to that type of abuse ... :)]
    – lawlist
    Sep 9 '17 at 21:35
  • In addition to the previous comment about avoiding the dilemma of a killed process, you may be interested in get-process to test for a running process: gnu.org/software/emacs/manual/html_node/elisp/… If it does not exist, then start a new one.
    – lawlist
    Sep 9 '17 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.