It seems to me that one can get the same effect by:
- Always using
WNOWAIT first.
- Remove the PID from systemd's own data structures. Keep the (valid) pidfd. If any data needs to be obtained from the zombie process, get it.
- Finally, wait without
WNOWAIT.
This is admittedly more complex, but it should do the job.