Stuck process: is it a bad sign

osxprocess

Sometimes a few process are in a stuck state. For example:

PID    COMMAND          %CPU TIME     #TH  #WQ  #POR #MREGS RPRVT  RSHRD  RSIZE  VPRVT  VSIZE  PGRP  PPID  STATE
99357  plugin-container 0.1  12:07.07 10   1    224  2097   40M    84M    66M    82M    2757M  91688 99346 sleeping
99346  firefox          0.4  48:54.20 29   1    265  16250  467M   172M   799M   538M   4210M  91688 1     sleeping 
88029- Aquamacs       1.2  31:24.12 4    3    126  268    19M    49M    32M    36M    777M   88029 152   stuck

Is it part of the normal life cycle of process ? Why this process in particular ?

What does it mean exactly ?

Best Answer

It is not necessarily a bad sign, but let me answer your last question first:

What does it mean exactly?

In the top source code (from http://www.opensource.apple.com/release/mac-os-x-1082/) the stuck state is referred to as identifier LIBTOP_STATE_STUCK (from libtop.c):

libtop_state_str(uint32_t state)
{
        const char *strings[] = {
                "zombie",
#define LIBTOP_STATE_ZOMBIE     0
                "running",
#define LIBTOP_STATE_RUN        1
                "stuck",
#define LIBTOP_STATE_STUCK      2
                "sleeping",
#define LIBTOP_STATE_SLEEP      3
                "idle",
#define LIBTOP_STATE_IDLE       4
                "stopped",
#define LIBTOP_STATE_STOP       5
                "halted",
#define LIBTOP_STATE_HALT       6
                "unknown"
#define LIBTOP_STATE_UNKNOWN    7
        };
(...)
}

Later in the same file, LIBTOP_STATE_STUCK is mapped to kernel state TH_STATE_UNINTERRUPTIBLE:

/* Translate a mach state to a state in the state breakdown array. */
static int
libtop_p_mach_state_order(int state, long sleeptime)
{
        switch (state) {
                case TH_STATE_RUNNING:
                        return LIBTOP_STATE_RUN;
                case TH_STATE_UNINTERRUPTIBLE:
                        return LIBTOP_STATE_STUCK;
(...)
}

So a process in stuck state means that the process/thread is in an uninterruptible wait state, which is how TH_STATE_UNINTERRUPTIBLE is defined in the kernel struct thread_basic_info (see http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/thread_basic_info.html):

struct thread_basic_info
{
(...)
       integer_t        run_state;
(...)
};

where run_state is:

run_state: The thread's run state. Possible values are:

(...)

  • TH_STATE_UNINTERRUPTIBLE: The thread is in an un-interruptible wait state.

(...)

This is usually caused by a process waiting on I/O, that is, the process has requested to read or write to/from disk or the network and waits for the system call to return (see http://en.wikipedia.org/wiki/Sleep_%28operating_system%29#Uninterruptible_sleep or http://www.novell.com/support/kb/doc.php?id=7002725 for more information).

(When not using BSD options, as it is usually the case in Linux, ps shows uninterruptible sleep as D state.)

Is it part of the normal life cycle of process?

Yes, it is. What is not normal is that a process stays in this state for a long time. That's a bad sign.

Why this process in particular?

Difficult to say. It is usually caused by I/O bottlenecks with heavy disk activity or degraded connectivity when using network filesystems (the most usual scenario, in my experience).

(This is a related question in Ask Different: https://apple.stackexchange.com/questions/58697/how-does-stuck-in-results-of-top-relate-to-not-responding-in-activity-m.)

Related Question