Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to identify stalled/stuck applications from Terminal?

Hi Folks,

I've had a few cases recently where "sudo reboot" didn't in fact reboot the machine, and I was still able to log back into the same machine remotely. As these were distant/remote machines, and I do tech support, I'd love to save myself a trip to their office a few miles away.

Going to the Apple menu > Force Quit, shows me in red type "stuck" applications, or "application not responding" and I'm able to then force quit them. But that's if you're logged in.

However, in Terminal, I don't know of a way to identify the application and/or daemon, or Launchd program causing the problem. If I did, presumably "sudo kill" could then be used to kill the item in question...

Any ideas/suggestions?

Thanks, Lurch

iMac, Mac OS X (10.6.2)

Posted on Mar 3, 2010 8:13 AM

Reply
11 replies

Mar 3, 2010 10:33 AM in response to Lurch66

You can also try ps and look for a U

ps ax | grep 'U '



state The state is given by a sequence of characters, for example,
``RWNA''. The first character indicates the run state of the
process:
I Marks a process that is idle (sleeping for longer than
about 20 seconds).
R Marks a runnable process.
S Marks a process that is sleeping for less than about 20
seconds.
T Marks a stopped process.
U Marks a process in uninterruptible wait.
Z Marks a dead process (a ``zombie'').
Additional characters after these, if any, indicate additional
state information:

Mar 4, 2010 7:25 AM in response to roam

'U' - uninterruptable does not mean stuck, stalled, nor hung.

It just seems that programs which happen to be stuck, stalled, or hung happen to be in 'U' uninterruptable mode.

'U' uninterruptable just means that at this moment any signals sent to the process will be queued and not delivered until the process transistions from kenel code to user code. If the process never leaves kernel code, the signal will not be delivered.

Kernel code & kernel level drivers can make calls that check for signals and attempt to stop what they are doing and return to user code so that signals can be delivered, but that is generally limited to slow I/O operations (waiting for user typed input, network I/O), as most kernel operations are quick and limited in how long they last.

However, not all kernel things which should complete quickly always do, so they can become stuck in an 'U' uninterruptable state.

Mar 4, 2010 1:04 PM in response to BobHarris

Tony,
Thanks for your response.
I invariably have 1 stuck
eg. Processes: 49 total, 2 running, 1 stuck, 46 sleeping... 232 threads

The '1 stuck' is removed when I close Mail and reappears when I open it.

In 10.3 top shows nothing stuck with Mail open. When I click 'Get mail' it will flash 'stuck' for about a second too as you report with Safari. This seems normal. However on my Leopard it is always on.

BobHarris,
Thanks for your detailed response about kernel states.
Observing '1 stuck' process, I tracked it down to Mail using ps aux
It was the only one in the U state. Closing Mail removes the stuck notice, as mentioned to Tony.
Mail appears to work correctly.
If it is not really stuck I wish Leopard's top would not report it as such.

You are on 10.5.8 as well. Is you Mail reported as stuck or not (erroneously or otherwise)?

Mar 4, 2010 9:47 PM in response to roam

Yes, Mail.app is always in the U-state on my 10.5.8 iMac, but on 10.6.2 it is in the U-state only when it is downloading mails from remote servers.

ps counts a process as uninterruptible (U) if at least one thread of the process is in the U state. You can see this by adding an option "-M" to the ps command line. But having an U thread does not mean the whole process is "stuck".

The "Force Quit" menu, or the Activity Monitor.app, does not mark Mail.app as "not responding", of course. So they are using a different method to identify "stuck" processes. But I don't know whether there is a command line tool which can do the same identification.

Mar 5, 2010 12:37 AM in response to Jun T.

Thanks Jun T.

So it appears to be an idiosyncrasy of 10.5.8 (or Mail 3.6)

I was not very concerned, more wondering really. First seeing it, kind of demanded attention as in 'what's stuck?' When I found it was Mail, I accepted it as a vagary of Mail 3.6 and it was only seeing this topic that prompted me to mention it.

At least I am happy to know it's a 10.5 thing and not particular to my Mail.

Mar 8, 2010 7:48 AM in response to Obj-D

is your stuck process VMWare?

this may be incorrect, but wouldn't a *sudo shutdown -r now* reboot the system even if some processes are stuck?

the shutdown command is supposed to interrupt launchd if I am remembering correctly. Shutdown sends a SIGTERM, then a SIGKILL.

Usually Z status items are trying to set or read their exit status. Zombie processes have completed, so in most cases is should be ok to kill them.

http://en.wikipedia.org/wiki/Zombie_process

Mar 8, 2010 10:04 AM in response to Obj-D

A 'Z' Zombie process is a terminated process that has given up just about all of its resources (which is why it is called a Zombie, as it is just a shell of its former self), except for a small amount of process state containing its exit status that it is try give to its parent process.

As far as I know you cannot kill a Zombie process, as there is nothing to kill and besides a killed process still needs to report is compltion status to its parent process.

It is the responsibility of the parent process to "Reap" the completion status of any child process it creates. There are various programming ways a parent process can do this, but it is still the parent process' responsibility.

As an alternative, you can kill the parent process, then all of the the parent process' children become "Orphans" (including the Zombies), and Orphaned processes are adopted by process PID 1, which on Mac OS X is launchd (it is called 'init' on other flavors of Unix/Linux). launchd will then 'Reap' the Zombie childs completion status and allow the process to go away.

You can use Activity Monitor to in an "All Processes, Hierarchically" display.

How to identify stalled/stuck applications from Terminal?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.