Archive for the ‘linux’ Category

Killing Finder or Dock (or any other mac OS X application)

Wednesday, March 11th, 2009

When an application in OS X is stalling on you and you have given up on regaining control of it, the best thing to do is kill it before it takes down your whole machine. Usually you would right click on the application icon in the Dock and choose the menu item “Quit” or “Force Quit” if available and that should do the trick.

Dock Menu When Right Clicking Application

Dock Menu When Right Clicking Application

Or you could click on the top left corner “apple” icon which will bring up a menu where you will see something called “Force Quit”. Choosing that option will open a small window with a list of the running applications which you can forcibly kill.

Force Quit Applications

Force Quit Applications

Sometimes though a key component of OS X fails on you which you don’t have an option to force quit like the above mentioned methods. I came to such a situation when the Dock froze on me the other day. It just would not come up at all. Today I had a similar situation when I had cover flow switched on in the finder while I was browsing an external hard drive that has 20 gigs of hundreds of subfolders inside hundreds of subfolders that contain thousands of photos. Cover flow could not handle this and it wouldn’t allow me to do antyhing else either. I had an application crunching data for the past 5 hours so restarting the machine was definitely not an option. I needed a way to cleanly kill Finder without destroying any other work going on. In situations like this you need to go beyond the GUI and directly to the terminal. Yes, I know, now that I am writing this article, I noticed that the “Force Quit” application actually has Finder as an option but being someone from a linux background I immediately go to Terminal for anything I need rather than look for GUI solutions.

What you need to do is find the PID (Process ID) of the application you need to kill. To do this, type the following in Terminal:

ps aux | grep Finder

The result of that command will be something like:

sergemadenian   131 97.1 25.9  1213744 542124   ??  R    Fri12PM  54:49.70 /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder -psn_0_40970
sergemadenian  3932   0.1  0.0   590472    192 s000  R+   10:07PM   0:00.00 grep Finder

“ps aux” is the command that prints out all the currently running processes from all users. ” | grep Finder” will restrict the results of the “ps” command to show only the lines that contain the word “Finder”.

From the above result you can tell that the Finder application is question is the first line and I have set the PID in Bold and red “131″. You can also tell that this process is struggling because immediately after the pid we see the CPU and memory usage which in this case is “97.1 25.9″ (those are percentages).

Now that we know the PID (131) all you need to do is run the command:

kill -9 131

“-9″ tells the OS to kill immediately. That took care of the offending Finder window and I noticed that a new Finder process had been kicked off by the OS. If a new process had not automatically been kicked off, I would have had to start it manually by running the command that was running before which I’ve marked in blue and bold ”

Same process applies to any application including the Dock. All you need to do is find the specific PID by changing what you filter with grep. For the Dock as an example, you will need to run:

ps aux | grep Dock

Remember that the PID is not a universal number (that is your Finder application will not have 131, even my computer will have a different PID for Finder when I restart it) so you need to always find the unique PID running at the time.

Using Java 1.6 (java 6) on Mac OSX (Edit: For Development Only)

Thursday, October 16th, 2008

Recently we’ve started using some packages in java that require us to use Java 1.6 (sometimes refered to as Java 6. Which one is it java, 1.6 or 6? We’re at war, pick a side!). If you have Mac OSX leopard then you should have both 1.5 and 1.6 installed on the system but by default 1.5 is used.

To check which version is being used when you log in, open up terminal and type:

java -version
You should see something like:

java version “1.5.0_16″
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)
Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)

To switch this to use 1.6 instead, you need to add the following to your .bashrc:

alias java=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/

Remember to either exit your terminal and start a new session or just run the command:

source ~/.bashrc

for the changes to take effect.

Turn on syntax highlighting in VI on Macbook

Friday, June 15th, 2007

If you installed the developer tools on macbook as I did the moment I started it up, you should have VI on your system. I’m used to the syntax highlighting in VI but macs don’t have that enabled by default. You could just run the command:

:syntax onÂ

And immediately you’ll have syntax highlighting. The issue with this method though is that once you quit VI and open a new file, there will be no syntax highlighting and you will need to run the command again.

To have highlighting always enabled, just create or edit the file $HOME/.vimrc and add the following line to it:

:syntax on

Open a new file in VI to test and you should see your code in color.

Total loss of CTRL

Tuesday, May 22nd, 2007

Using the macbook for the first time you immediately realize the CTRL key doesn’t control much. I use keyboard shortcuts most of the time, it saves me a lot of time that would be wasted moving my right hand to and from the mouse. The most common of those shortcuts are: ctrl-C, ctrl-V, ctrl-D, ctrl-Z, ctrl-Y. Taking out the mac for a test drive your instinct tells you to use CTRL-C to copy something but nothing happens. Next step was to figure out what the shortcuts are. I used the mouse to go to the menu and check out the shortcuts next to each item. I noticed that everything uses that key with the apple logo and a weird symbol on it.

Edit Menu

It’s called the command key and all the windows and linux shortcuts are pretty much the same except you use command instead of CTRL. so copying would be command + C and so on.

I also went digging a little more online to find other shortcuts. In windows you can press Alt+F4 to close windows and when all windows are closed it brings up the “shut down computer” dialog. Command-F4 didn’t do anything. The following page helped me a lot in learning shortcuts:

Mac OS X keyboard shortcuts [Apple]

to bring up the shutdown dialog box you need to hold down Control + Eject for a second or two. What I cannot figure out yet is how to move between the different choices in a dialog box.

Shutdown dialog box
In the image above, shut down is selected and if I press the enter key, the computer will shut down. What if I wanted to restart? on linux and windows you can use the arrow keys or the tab key to switch focus. I haven’t been ablet o figure out how to do that on Mac OS X. If anyone knows, please post a comment.

Why Macbook?

Tuesday, May 22nd, 2007

I think a good first post would be to explain why I chose to get a mac or a macbook at that. My only interaction with a mac before I bought the macbook was a very long time ago and it was not pretty.

A friend of mine had a mac (pre OS X) and was away from his computer and asked me to check something on it. By that time I was already very familiar with windows, had a base working knowledge of linux and a lot of experience with hardware. What my friend asked for was a simple task that should have been easy for even a not so computer savvy person. To my surprise, and eventual frustration, I couldn’t figure anything out and crashed his computer. I had sworn not to touch another mac.

What made me change my mind was a combination of things. First off, I had since then worked with linux a lot more and had much more experience. I have had linux as my desktop machine at work for the past 3 years (windows at home only because of gaming). All my work is linux based and so even on a windows machine all I did was use putty to connect to a linux machine and work. Windows had just become a shell instead of the operating system I do my work in. Apple switched their OS to use Unix since OS X which made it easier for me to understand and get to the root of errors when they arise. This eased my fears of not knowing how to even do the simplest tasks.

The second point was that I needed a laptop to work on. I didn’t want to just have another shell computer where I used it to then connect to a remote server where I did my actual work. With a laptop, I might be somewhere that I have no connection to the internet and want to continue working. My initial though was to buy a laptop and just install linux on but I haven’t had much luck with that in the past. I have a Dell Inspiron 9100 and installing linux to properly work on there (with full audio, video and wireless support) was a major headache. I was still ready to put up with that headache though if it meant I would now be able to work directly on local machine instead of connecting remotely.

While I was researching which laptop would be best suited for linux, a friend/coworker, Geoff (and an avid mac user), pointed out that macs were now based on unix. He brought his powerbook to work every day and with it I was able to get some first hand experience using the new operating system. I was now more at ease with mac OS X. Finally he made the argument that with the latest macbooks running on unix and being Intel based I could easily compile and use most of the open source tools I use on linux (apache, perl, mysql and so on), I also wouldn’t have hardware incompatibility issues and running out trying to find drivers like I would when installing linux on another laptop and finally with all the UI tools on the mac, other than work I could use my laptop for things like watching a movie or listening to music without much hassle.

I was sold. Now I needed to find the model that best suits my needs. I didn’t want to have a big laptop. I had the inspiron 9100 before and that thing is HUGE. You can’t carry it without sustaining a shoulder injury. I wanted a smaller, more portable laptop. macbook pros only come in 15 and 17 inch displays so I opted to go with the macbook.

One last thing I had to wait for was that back then macbooks still used core duo processors while macbook pros had already moved to core 2 duo. I wasn’t in a hurry and waited for core 2 duo to be released on macbooks.
I’ve been using the macbook for a few months now and I can say that I am not disappointed by the move.

More on initial OS shock soon…

Procrastination must end sometime

Monday, May 21st, 2007

I registered this URL when I had just ordered my macbook hoping to have a day to day analysis of my initial OS shock. I had a lot of things that took precedence over this project though and so I have been putting it off. I did keep notes of the issues I was having and how I resolved them so I’ll be posting those along the way.

I won’t be talking only about going from a linux environment to a mac. I’ve been a windows user for a long time and I will try and discuss using a mac from both OS viewpoints. Of course it was a lot easier for me knowing linux, since OS X is based on Unix.