Why my disk and CPU are busy without me

I'm off at the beach this weekend with the family so I brought the trusty MacBook along. Overnight I closed the lid, putting the MacBook to sleep, and not long after I opened it this morning iStat menu was showing a lot of CPU activity and I could hear the disk thrashing a bit. I wasn't running anything other than Safari at the time so I became curious; what was causing the machine to work all of a sudden?

When I looked at iStat it was showing that the find process was using 75% of my CPU activity. But what was find and why was it working now?

After a little research I found that according to Apple's site find is a file system maintenance utility and that it is run as part of a daily, weekly and monthly schedule. Since I had put the MacBook into sleep mode overnight and the daily and weekly scheduled tasks had not run OS X decided to run it not long after I took it out of sleep mode. Normally these maintenance tasks are scheduled to run at 03:15 everyday, 04:30 on Saturdays, and 05:30 on the first day of each month.

All told it ran for about 15 minutes or so with varying periods of activity. I also found that I could see what was inside these tasks by examining the results of the daily, weekly and monthly logs. If you want to see what your Mac has been up to while you were sleeping just pop open one of the following files:

/var/log/daily.out
/var/log/weekly.out
/var/log/monthly.out

Inside of these files are the details of what the scheduled maintenance tasks were up to.

Comments

Paul Thompson said…
It's little things like this that make me love my Mac.

I noticed in Removing old log files:

- Removing old temporary files:

- Removing scratch and junk files:

In Windows, I've seen temporary folders reach ridiculous sizes. It's great that my Mac sorts all this kind of thing out in the background. More importantly, it's great that this is sorted out for the non-tech savvie.

Also, have you noticed that many of the logs (best way to see them is by opening 'Console') are automatically archived and compressed each period? Great stuff!
Welles said…
There's a little utility called Macaroni which is an excellent addition for people who turn their computers off at night so the chron scripts aren't run. It also repairs permissions once a week, can eliminate unneeded language resources potentially saving gigabytes of room on hard drives, and can be used as a 'timer' to run user scripts all in the background when CPU activity allows.

I help a fair number of non-technical people get used to Macs and always have them purchase the modestly prices pref pane as it eliminates having to think about basic maintenance, performing the routines automatically.

http://www.atomicbird.com/macaroni
Unknown said…
This is the Unix part of OS/X. Crack open a Linux/BSD/Solaris box and you'll see exactly the same stuff: rolling and compressing of logs, cleaning out temp directories, etc. Almost all of the system level functionality of OS/X is straight Unix. It's why Unix people are always so uncomfortable in Windows - they're used to the system offering all of these capabilities and making them extensible by the user.
David Alison said…
@Charles: I've never been a big Unix guy, though I'm learning as I go. While I've had several flavors of Linux before and finally found one I've kept with Ubuntu, I rarely went deep on them. The reason I like Ubuntu is that I didn't HAVE to drop into a terminal window for most tasks - people generally fear what they don't know and since I wasn't a Bash shell guy and didn't understand the significance of how directories are set up in Unix I just avoided them, fearing that I might do some damage.

Now that my primary operating system (Mac) is built on top of BSD I'm finding myself with a reason to explore more and am enjoying it.
Hendrik said…
I think the biggest culprit for the disk activity is the task that updates the 'locate' database. locate is a Unix command for quickly finding files using a database. Like Spotlight, but more old school. While Spotlight is constantly kept up to date, locate does a weekly sweep of the whole file system to update its database. If you never use the locate command then I think (no guarantees) it is safe to disable the updating of the locate DB by moving the file /etc/periodic/weekly/310.locate to a backup directory elsewhere. You'll need to use the sudo command to do this. As in

sudo mv /etc/periodic/weekly/310.locate ~/backup
Anonymous said…
Wells,

Just FYI, it's "cron", not chron. cron stands form "Command Run On", which lets you run any unix command at any recurring date/time.

Steve
David Alison said…
While we're on the subject, can anyone recommend a good book to pick up the Unix side of the Mac? Either a Mac centered book on BSD (Bash, management, crons, directory models, etc.) or even a good general purpose book that is consistent with the way Apple has implemented BSD? I have several older books about Linux that I've counted on for my reference but would like to get something specific to Mac.

I found a book on Unix for Tiger that looks promising - I assume that little has changed from Tiger to Leopard on the Unix side. Any feedback there is appreciated!
Anonymous said…
@Welles, et al

After the introduction of launchd in 10.4 and 10.5, the periodic functions were no longer initiaed by cron, but by launchd. Launchd has a "calendar"-style function which exists strictly to make sure that the operative software is run at the next time after the "calendar interval". As such, it is very likely that periodic will be run at the nearest approximation of weekly on any system with Leopard (and I believe this is true for Tiger as well).

For more details, the man pages for launchd.plist and /System/Library/LaunchDaemons/*periodic* are informative.

Cheers,
-Gaige
Pecos Bill said…
@David: No, actually quite a lot has changed from Tiger to Leo. The latter has removed al of the NetInfo stuff. NI used to manage the configurations. It's been rolled into LDAP, so I've read. You'd be better served by a book that is Leo focused. The rest of the unix side is probably similar though.
David Alison said…
@Pecos Bill: Thanks man - I decided to go with A Practical Guide to UNIX for Mac OS X Users. It had some excellent reviews and seemed like the class of book I was looking for. I'll probably write about it at some point in the future. I also picked up a couple of well regarded books on Cocoa and Objective C; I have an idea for a little Freeware utility that I'd like to write.
Paul Thompson said…
As a convert of just 1 year, it'd be great to see some practical applications of Unix commands. I was fairly fluent with Dos in my Windows days, and haven't yet found a reason to become motivated enough to learn about the underpinnings of OS X.
Unknown said…
@Paul: I got my start with Mac centric Unix stuff from macosxhints.com. They have a Unix topic page. Then I went back and learned the bash basics from The Linux Phrasebook.

Popular posts from this blog

Finding Davey: A Father's Search for His Son in the Afterlife

Keyboard vs. Mouse

A hardcore Windows guy gets a Mac