Re: newbie question about fork/pipe/stdin/stdout
- From: "Alex Fraser" <me@xxxxxxxxxxx>
- Date: Fri, 26 Oct 2007 21:49:58 +0100
<vladimir.plotnikov@xxxxxxxxx> wrote in message
news:1193405143.360453.36370@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm writing small C++ under Linux application with will be transfer
email from some IMAP server and put it to local database.
I have one problem:
I need to pass message to anti virus filter and spam filer.
When mail exceeded some limit, I my program is stopped on "waitpid()"
and wait when spamc script ends. but this script never ends. From
other side, another filter (anti virus) working fine on same code.
If the child consumes all input before producing any output, the parent
should write all the input, read the output until EOF, and only then call
wait(). Using the code you provided, if there is "too much" output, the
child will block in write() before it can exit, and the parent is waiting
for it to exit before calling read(): this is a deadlock.
If the child may produce output before consuming all input, you will have to
do something different (more complicated). You could use non-blocking IO and
select()/poll() or equivalent in the parent to move data between the
processes whenever possible (again, calling wait() only after you have read
EOF from the child). Or you could use a third process with some more
"plumbing" to create something like a shell pipeline. That is, after
creating the first child process (in which you exec), fork() again in the
parent to create another child which will read the output from the first
child.
HTH,
Alex
.
- Follow-Ups:
- Re: newbie question about fork/pipe/stdin/stdout
- From: vladimir . plotnikov
- Re: newbie question about fork/pipe/stdin/stdout
- Prev by Date: Re: thread id
- Next by Date: Re: newbie question about fork/pipe/stdin/stdout
- Previous by thread: Re: newbie question about fork/pipe/stdin/stdout
- Next by thread: Re: newbie question about fork/pipe/stdin/stdout
- Index(es):
Relevant Pages
|