How to list only non-<defunct> processes?
In your comment you clarify:
I'm actually looking for a single step option to ps or pgrep (or similar) which only outputs "active" processes...
I'm afraid you're out of luck with current ps/pgrep implementations.
Post filtering like this relies on a full understanding of the intial output, which I don't have...
But you can get that understanding and, better yet, control that output as desired. Try something like this:
function pgrep_live {
pids=$(pgrep "$1");
[ "$pids" ] || return;
ps -o s= -o pid= $pids | sed -n 's/^[^ZT][[:space:]]\+//p';
}
That will return the pids for any pgrep'd processes matching your input string, which processes are "available for normal use," that is, neither dead+unreaped (Z) nor stopped (T).