pwait(1) should have feature to avoid its own ptree
pwait(1) can sometimes accidentally get its own PID or the PID of one of its ancestral processes as an argument, which will in effect cause pwait to never exit. (Using output of `pgrep -f` can sometimes cause this.) Avoiding this situation is possible, but because of the overhead involved, it should be optional. Perhaps the -P (for Paranoid) flag could be employed?
Basically, if specified, pwait would call getpid() for itself, and then use ptree(1)-like ppid chasing until there are no more ppids. Then each argument would be compared against the list of ppids, and any matches would be ignored (and perhaps reported if -v were engaged).
IMHO: This would be a good nontrivial first bugfix for a motivated new-to-illumos-contributions person.
Updated by Joshua M. Clulow over 2 years ago
The overhead of
getpid() is negligible, and the semantics of
pwait waiting on itself will never work out, so I don't think I'd make that optional.
With respect to
pwait acting on parents, I can imagine a -- perhaps contrived! -- scenario where you're watching some ancestor process which will terminate prior to the thing waiting for
ptree. I think that regardless of the overhead (which I don't think would actually be that large) we have to make that behaviour optional either way.