On macOS, ps
is roughly based on the libtop.c
library whose source contains the following function (white-space truncated):
/* Return a pointer to a string representation of a process state. */
const char * 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
};
assert(LIBTOP_NSTATES == sizeof(strings) / sizeof(char *));
assert(state <= LIBTOP_STATE_MAX);
assert(LIBTOP_STATE_MAXLEN >= 8); /* "sleeping" */
return strings[state];
}
As correctly pointed out in another answer, ps
's print.c
takes process state symbols from tasks.c
where they directly coincide with the state offsets found in libtop.c
as shown above.
The last one is unknown, meaning the process state does not fall into any particular category. And the last symbol is a question mark, thus in rare cases you may see it in the STAT
column.
ps
here??
states, see github.com/aiidateam/aiida-core/issues/3107