[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: popen2 vs pclose
From: |
Ben Abbott |
Subject: |
Re: popen2 vs pclose |
Date: |
Tue, 25 Aug 2009 16:18:51 -0400 |
On Tuesday, August 25, 2009, at 03:22PM, "John W. Eaton" <address@hidden> wrote:
>Octave's popen2 function will create zombie processes, even if you use
>pclose to close streams returned by popen2. One problem is that
>popen2 does not set the close function for the stream to be pclose.
>But just doing that is not enough since pclose does not know about
>files opened with popen2. It only knows about child processes that
>are created with popen.
>
>The attached diff shows a draft of a solution I came up with that I
>think will fix the popen2 zombie problem. The idea is to keep track
>of the pid for the process created by popen2, then wait for it when
>either the input or output stream is closed. I'm not sure whether
>this is the best thing to do. Maybe there are reasons to close one
>end of the connection to the process but not wait for it to exit? If
>so, then this fix will also cause some trouble.
>
>Also, the two streams returned by popen2 are not associated with
>one another and with this patch, both store the pid. This means that
>waitpid is called once for each stream. That doesn't seem like the
>best thing to do.
>
>Maybe it is just best to expect users of the popen2 function to do
>something like
>
> [in, out, pid] = popen2 (...);
>
> ...
>
> fclose (in);
> fclose (out);
>
> waitpid (pid);
>
>and not try to do this automatically for them. If so, then I think we
>just need to document this behavior and make sure that this is done
>properly for any code in Octave that uses popen2.
>
>Comments or suggestions?
>
>Thanks,
>
>jwe
Adding the "waitpid (pid)" for the gnuplot backend would be fairly simple, so
from that perspective either would work.
Ben