Re: Invoking external processes in threaded program
- From: Barry Margolin <barmar@xxxxxxxxxxxx>
- Date: Sat, 21 Jun 2008 22:50:09 -0400
In article
<afcfa511-0d53-4ea8-a7c8-954e5b3d8d16@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Edd <edd@xxxxxxxxxxxxxxxx> wrote:
Hi folks,
I'm trying to write a high level library to invoke and communicate
with an external process. On UNIX, this implies a fork-and-exec with
some pipes (or pseudo-terminals as I learned in another thread [1]).
Now, ideally I would like to be able to start multiple processes in
different threads, but the general advice with respect to fork()ing in
a multithreaded program seems to be that one shouldn't do anything in
the child other than exec*() immediately. I can see why after thinking
about it, but I didn't see this particular trap coming... :)
So now I can't see a way to set up my communication channels in the
child e.g. calling dup2() for the standard stream descriptors and
close()ing the un-used ends of the pipes.
I don't think there's any problem with doing these things in the child
process.
When you fork, only the thread that called fork() is duplicated, so you
don't have to worry about other threads continuing to do things before
the exec().
--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.
- Follow-Ups:
- References:
- Prev by Date: Re: What's the difference pipe vs redirection is the following case case.
- Next by Date: Re: What's the difference pipe vs redirection is the following case case.
- Previous by thread: Invoking external processes in threaded program
- Next by thread: Re: Invoking external processes in threaded program
- Index(es):
Relevant Pages
|