the secret life of zombies

J

jsnx

I'd like a program, call it 'pipe-fitter', that connects and
interactive app
to three named pipes. The program will filter out EOF from the input
pipe, to
keep the interactive program alive for multiple commands. When the
interactive
app dies, by receiving 'exit', say, then we are done with it -- pipe-
fitter
bails out.

I've tried writing pipe-fitter in the shell (infinite loop), C (could
not get
off the ground at all with this one) and now Python. After trying a
few
different approaches, I was turned on to the subprocess module by
someone on
IRC. My program is almost right, except for damn zombies. Here is pipe-
fitter:

https://svn.j-s-n.org/public/i-can-has-root/python/pipe-fitter.py

Say we make some fifos in a dir 'pipes'

mkdir pipes
mkfifo pipes/i pipes/o pipes/e

Now we call pipe-fitter thusly:

pipe-fitter.py -d pipes sh -xv

This runs `sh -xv` with stdin, stdout and stderr connected to pipes/i,
pipes/o
and pipes/e respectively. We open three new terminals. In the first
one, we
put:

echo "ls -l" > pipes/i

and in the second:

cat pipes/o

and in the third:

cat pipes/e

Once we enter the final command, the 'echo' returns and the text comes
streaming out in the 2nd and 3rd terminals. Wonderful. Now, let's try
`exit`.

echo 'exit' > pipes/i

As expected, cat will terminate in the 2nd and 3rd terminals, with the
3rd
terminal displayin:

+ exit
exit

However, pipe-fitter.py is still running. Why is that? It did not
'poll' at
the right time, it seems. If I try stuffing more input into pipes/i, I
get

IOError: [Errno 32] Broken pipe

and pipe-fitter.py finally quits. Not exactly what I was hoping for.

Prowling around with PS, I find that the `sh -xv` called from within
pipe-fitter is a zombie for a spell; if pipe-fitter fails to catch it
at the
right time, there is no avoiding the IOError. I'm using
subprocess.Popen.poll() in a loop, to catch the process's termination
-- is
there something else I should be doing?
 
J

jsnx

Oh, by the way -- I apologize for the poor formatting of this post,
I guess my linewrap setting is wrong for nntp.
 
J

jsnx

I fixed it myself -- I had to install a signal handler and use
nested 'try-expect' stuff. The link points to the new version.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top