How to detail just non - <defunct> procedures?

Exists a mix of command - line alternatives for ps or pgrep or a few other reasonably straight means to establish if a certain process name is in fact running (readily available for regular usage).

By "running", I suggest to especially exclude procedures which are <defunct> or any kind of various other non - running procedures (eg. zombies ...

This example manuscript reveals an instance of <defunct> things :

#!/bin/bash   ubuntu 10.04

  pgrep ^gnuserv$
# 25591
# 25599
# 27330

  ps $(pgrep ^gnuserv$)  # command ammended as per pilcrow's good suggestion
#   PID TTY      STAT   TIME COMMAND
# 25591 ?        Zs     0:00 [gnuserv] <defunct>
# 25599 ?        Zs     0:00 [gnuserv] <defunct>
# 27330 pts/2    S+     0:00 gnuserv

I can better sed the output, yet I think/hope there is an extra straight means ...

0
2019-12-02 03:09:21
Source Share
Answers: 2

you can attempt with the - v alternative of grep which negate the regex similar to this :

for p in $(pgrep ^gnuserv$) ;do ps x |grep "^$p" | grep -v \<defunct\> ;done
0
2019-12-03 05:06:17
Source

In your comment you make clear :

I'm in fact seeking a solitary action alternative to ps or pgrep (or comparable) which just outputs "active" procedures ...

I'm worried you run out good luck with existing ps/pgrep executions.

Blog post filtering system similar to this relies upon a complete understanding of the intial result, which I do not have ...

But you can get that understanding and also, even better, control that result as wanted. Attempt something similar to this :

function pgrep_live {
  pids=$(pgrep "$1");
  [ "$pids" ] || return;
  ps -o s= -o pid= $pids | sed -n 's/^[^ZT][[:space:]]\+//p';
}

That will certainly return the pids for any kind of pgrep would certainly procedures matching your input string, which procedures are "available for regular usage, " that is, neither dead+unreaped ( Z ) neither quit ( T ).

0
2019-12-03 05:01:34
Source