Apple provides a great application called Activity Monitor. If you have never used it, it's located in the utilities folder. It will show you all of your open applications and running process, how much CPU they are using, the amount of RAM being consumed, energy used as well as disk and network activity.
In my case I found that a process called "storeassetd" was using 99% of my CPU. A lot of digging around the Internet finally revealed that this process is associated with the Apple Mac App store. looking at it, I guess the name makes sense. Somehow, when I was updating my Mac applications, the App store process didn't stop when I quit the software update.
To fix the problem and stop the runaway activity you just highlight the application and click on the stop sign icon in the upper left.
The second instance of runaway CPU was a little more nefarious. I was being attacked by a hacker.
Again I was investigating why my Mac was running slowly and discovered that this time the responsible process was "opendirectoryd" Being a UNIX admin I knew this was the LDAP login authentication process UNIX uses...WTF? This is where Apple's Console application comes in handy.
Console is the application that allows you to look at all of the log files the Mac keeps. I fired up Console, did a little digging and found this:
Page after page of someone trying to log into my Mac as root. Hundreds of attempts per second!! No wonder my poor Mac was having trouble.
I realized what had happened almost immediately. The previous week I had needed to access my Mac while away from home and had allowed remote login in the System Preferences Sharing configuration menu. Since I have multiple Macs I had also set up my Airport router to forward all ssh requests to my iMac so I could log in to the correct Mac. The fix was just as easy. Shut down the ssh port on my Mac and remove the Airport Port forward using Airport Utility.
The moral of this story is to be vigilant. If you have a problem, if your Mac is running slowly and you don't know why, do a little investigation. It could just be a hung application (like my App Store process) or it could be something much much worse.