15
ProductName:    Mac OS X
ProductVersion: 10.11.6
BuildVersion:   15G31

$ sudo cron restart
cron: cron already running, pid: 257`

None of the answers in here https://stackoverflow.com/questions/10193788/restarting-cron-after-changing-crontab-file seem to apply to OSX. Well the one above is the closest one but it appears to be just telling me that cron is running so I don't have to worry about restarting it. Which isn't the point of restarting something.

How do I stop and restart the cron service on a Mac?

2
  • 2
    What are you trying to achieve by restarting cron?
    – mmmmmm
    Commented Dec 30, 2016 at 18:16
  • 2
    I'm trying to achieve the restarting of cron; I see no harm in confirming that the service has absolutely positively seen the new crontab files
    – jcollum
    Commented Dec 30, 2016 at 18:59

3 Answers 3

11

The cron daemon is managed with launchctl.

If you insist on restarting it, you have to unload and load the respective launch daemon:

sudo launchctl unload /System/Library/LaunchDaemons/com.vix.cron.plist
sudo launchctl load /System/Library/LaunchDaemons/com.vix.cron.plist

But: adding or removing arbitrary crontabs shouldn't require a reload of the daemon to enable or disable them.

The above launch daemon plist contains a Watch Directory directive which detects (crontab) file creation and deletion or modified dates and "instructs" cron respectively.

2
  • 6
    /System/Library/LaunchDaemons/com.vix.cron.plist: Operation not permitted while System Integrity Protection is engaged Commented Nov 30, 2019 at 10:40
  • would cron show up in launchctl list? when I load cron as you showed it says its already loaded. and when I do launchctl list | grep cron its empty. Commented Jan 25 at 21:11
5
sudo pkill -f cron

The LaunchDaemon has a keepalive section in it that will immediately restart it.

3
  • 1
    Please use code formatting for, well, code and shell commands. It makes it easier to read/recognize and also helps people with screen readers.
    – nohillside
    Commented Dec 25, 2019 at 11:46
  • Programmers use screen readers? Ummm, OK Commented Dec 26, 2019 at 20:47
  • You might be surprised. Anyway, most visitors here ain‘t programmers.
    – nohillside
    Commented Dec 26, 2019 at 21:01
2

From the cron man page:

The cron utility is launched by launchd(8) when it sees the existence of /etc/crontab or files in /usr/lib/cron/tabs. There should be no need to start it manually. See /System/Library/LaunchDaemons/com.vix.cron.plist for details.

So, interstingly enough, cron is launched by launchd. However, according to man crontab

(Darwin note: Although cron(8) and crontab(5) are officially supported under Darwin, their functionality has been absorbed into launchd(8), which provides a more flexible way of automatically executing commands. See launchctl(1) for more information.)

So, cron which is launched by launchd, has been deprecated for launchd. Using cron is like wrapping bacon in bacon because you want bacon flavored bacon.

As far as restarting cron, there is no need. Once it sees a crontab file, it will automatically launch the job.

However, it's highly advisable that you start scheduling jobs using launchd.

3
  • 2
    I don't trust computers to see changes to files all the time so I'd like to confirm that it has the new files loaded by restarting
    – jcollum
    Commented Dec 30, 2016 at 19:00
  • 2
    -1, answers the question by saying "don't worry about it"
    – jcollum
    Commented Dec 30, 2016 at 19:02
  • 1
    If you type crontab -l; whatever is there is loaded.
    – Allan
    Commented Dec 30, 2016 at 19:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .