Re: subprocesses lifecycle



On 2008-08-28 21:06, Eric Pozharski <whynot@xxxxxxxxxxxxxx> wrote:
Matthieu Imbert <breafk@xxxxxxxxxxxxxxxxxxxxx> wrote:
Eric Pozharski wrote:
*SKIP*
In your example code, the child process stays alive after the end of
parent process. As there are probably 30 to 40 lines in /etc/passwd
and it sleeps 1 second for each line, it's not surprising that it
takes about half a minute to end and die.

Positive. My fault. I've moved B<sleep> in child before B<while> and
the child exits immediately (with regard to B<sleep> of course). What I
don't understand is why the child succesfully writes in pipe. The pipe
isn't closed if a reader exits? I don't grok pipes obviously.

When the reader exits (or more exactly, then the last reader closes the
pipe) and attempt to write into the pipe will yield a SIGPIPE. Since
your script doesn't catch SIGPIPE, this will cause your child process to
terminate. But since you didn't call $pipe->autoflush the child won't
actually try to write to the pipe until the buffer (4kB on Linux, 8kB on
most other unixes) is full - that will be after about 75 or 150 lines,
respectively.

hp
.



Relevant Pages

  • timeout problems while using select with pipes
    ... a parent process reads data off from a pipe that is ... The child process generates data and writes it to the pipe. ... If I do set a shorter timeout, ...
    (comp.unix.programmer)
  • Re: calling read() in blocks
    ... > I have simple fork/exec C program that passes a pipe file descriptor ... The idea is that the child writes specific ... while the parent process listens on the read ... That's not a makeshift solution - it's one of the right solutions. ...
    (comp.os.linux.development.apps)
  • Re: calling read() in blocks
    ... >I have simple fork/exec C program that passes a pipe file descriptor ... The idea is that the child writes specific ... while the parent process listens on the read ...
    (comp.os.linux.development.apps)
  • calling read() in blocks
    ... I have simple fork/exec C program that passes a pipe file descriptor ... The idea is that the child writes specific ... When the parent process makes its readcall: ... ...I would like to force the parent process to call readtwice to ...
    (comp.os.linux.development.apps)
  • Capturing process output through pipe in a non-atomic fashion
    ... I have a parent process that forksoff a child, ... the parent needs to readthe pipe in a non-blocking ... that using fcntlto put the pipes into non-blocking mode would have ...
    (comp.unix.programmer)