Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

process leak in process substitution

21 views
Skip to first unread message

Jon Baccash

unread,
Jan 30, 2012, 11:57:20 AM1/30/12
to
I tried a nifty snippet of code from here:

http://stackoverflow.com/questions/1643347/is-there-a-good-way-to-detect-a-stale-nfs-mount

Essentially, I do this:

read -t1 < <(stat -t "$mount") || echo "$mount timeout";

If my NFS mount is hung, the read times out, and I get a warning
message. However, if the NFS mount is hung, bash also leaks the bash
proc that runs stat, as well as the stat proc. Since my script runs
within a daemon, when the script ends the child bash proc ends up
being child of the init proc, and essentially it's two leaked
processes that remain until the NFS server comes back up (which may be
never).

To work around this, in the case that the mount is hung, I can do
this:

pkill -P $(pgrep -P $$)

That kills the stat proc, and the bash proc will die as well. My
concern is that my solution will basically kill any grandchild of the
current proc, which is less than ideal. Is my version of bash buggy,
or is that how it's supposed to behave? Is there a better (more
robust, more precise) way to kill the stat proc? I.e. is there any way
to determine the pid of a process forked by process substitution?

Jon.
0 new messages