What to do when an app hangs in OS X

When an application hangs in OS X you might resort to forcing it to quit, but there are some other approaches you can try before doing this.

When an application hangs in OS X, you will most likely see the mouse cursor turn into a spinning color wheel or "beach ball" when hovered over the application's window. If this happens, though you will be able to move the application's window around on the screen, the program will not accept any input or respond to commands such as quitting or saving a document.

This happens because events in the application's event queue are not used in a timely manner. When an application is launched, the system sets it up with an event queue, which is a buffer that accepts input from the system (such as user input from the keyboard or mouse, or messages from other programs). If the system detects that queued events are not being used, then it assumes the program is hanging.

Application event queue
In an application loop, the event queue accepts input from the system and passes it to the application. Apple

As an example, if you click a button in an application window, the system will place that click event into the queue for that program, allowing you to continue interacting with other programs in the meantime. The program's main loop will then be given up to 5 seconds to pull the event off the queue and use it according to its instructions (i.e., as a click event for a specific button).

If the program is stuck in a routine that prevents it from accessing its main event queue in a timely manner, then the system will consider it as being hung and show the indications of it by displaying the spinning beach ball when the cursor is placed over the program, and will show the program in red text in Activity Monitor and the Force Quit window. Should the application clear itself, then the event queue will be processed and the program will continue to function normally.

Even though a program is hung up, you can still interact with it to some degree. For instance, since the system's window manager is likely working fine, you should be able to move the program's window around and hide it.

How to clear a hang
When hangs occur you can address them by forcing the program to quit and then relaunching it. This option is even more convenient in Lion given its autosave and resume features that usually allow you to restore the program to its last working state; however, this is not always a desired approach, especially when you have unsaved changes to documents or settings.

Just because the system has flagged a program as not responding does not mean that it is completely hung up. Therefore, before simply forcing a program to quit, there are several things you can try:

  1. Wait it out
    Try giving the program a few minutes to see if it will clear the problem on its own. Many times programs may be waiting for a drive, network volume, or other hardware resource to become available, so give it a few minutes to do this.

  2. Activate resources
    If you are connected to various devices such as hard drives, network drives, printers, scanners, and other peripherals, try accessing them through the Finder or through other applications. Sometimes a program may hang if it attempts to activate a device and fails to properly do so, in which case activating it by other means will allow the hung program to continue its functions. You can activate storage devices by browsing through them in the Finder, and can do the same for printers and scanners by using other programs that support their functions.

  3. Unmount and disconnect peripherals
    If you are having trouble accessing a specific peripheral device, or if upon activating them the problem still does not go away, then try unmounting and disconnnecting them from your system. Many times simply doing this will spur the hung program to throw an error instead of staying in its hung state. In addition to devices try disconnecting network connections, and disabling system sharing services in the Sharing system preferences, since these, like physical devices, can interact with programs and be the root of a hang.

  4. Force-quit the Finder and Dock
    OS X has several persistent programs that may interact with your applications and possibly contribute to a hang. Many of these are essential background services such as the window manager, but a couple, such as the Finder and Dock, are more independent and can be forced to relaunch without affecting your program's functions. Try forcing the Finder to quit by using the Force-quit window (in the Apple menu), but you can also relaunch the Dock by running the command "killall Dock" in a Terminal window.

  5. Force sleep mode and wake the system
    A last option for hopefully clearing a hung program is to force the system into sleep mode. While you can try clearing a hang by targeting the direct service or resource the program is having difficulty with, often this is not so clear. However, by sending the system into sleep mode, you can force many of these background processes to change their states (go dormant) and therefore release a program that is hung on them. Therefore, try sleep-moding the system (you can use the keyboard command Option-Command-Eject to do this) and then leaving it in sleep mode for a few minutes to allow network services and peripherals to time out and also change their active states. Then wake the computer again and see if the program responds differently.

If none of these approaches helps the situation, then force-quitting the program using the Force-quit menu or Activity Monitor may be your only option.



Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.

Tags:
Computers
About the author

    Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.

     

    Join the discussion

    Conversation powered by Livefyre

    Don't Miss
    Hot Products
    Trending on CNET

    HOT ON CNET

    Find Your Tech Type

    Take our tech personality quiz and enter for a chance to win* high-tech specs!