avoiding deadlock processing child's stdin/out/err

avoiding deadlock processing child's stdin/out/err

Post by John Wiers » Wed, 22 May 2002 02:21:09



How do programs like telnet and rlogin (and their daemons) avoid
deadlock when dealing with stdin/stdout/stderr of a child process?  I
assume they turn off write buffering.  Is it sufficient to use
non-blocking IO or is there some other trick?

What I'd like to do is write a wrapper program, sort of like a
bi-directional tee, which I could wrap around any other arbitrary
process to capture all the stdin/out/err traffic of a child process
without affecting its operation.  Is there a program which already
does that?

Thanks!
-- John Wiersba

 
 
 

avoiding deadlock processing child's stdin/out/err

Post by Johnny Mnemoni » Wed, 22 May 2002 03:16:07



> How do programs like telnet and rlogin (and their daemons) avoid
> deadlock when dealing with stdin/stdout/stderr of a child process?  I
> assume they turn off write buffering.  Is it sufficient to use
> non-blocking IO or is there some other trick?

> What I'd like to do is write a wrapper program, sort of like a
> bi-directional tee, which I could wrap around any other arbitrary
> process to capture all the stdin/out/err traffic of a child process
> without affecting its operation.  Is there a program which already does
> that?

You failed to explain..
Are you sure that any shell can't do the job?
check out the "| < > << >> n>" bash operators

--
Johnny

 
 
 

avoiding deadlock processing child's stdin/out/err

Post by those who know me have no need of my nam » Wed, 22 May 2002 07:40:11



Quote:>How do programs like telnet and rlogin (and their daemons) avoid
>deadlock when dealing with stdin/stdout/stderr of a child process?  

daemons often do, more or less:

- read from their side of their child's stdout and stderr until they
receive an eof indication, writing the data to the network socket.  some
daemons will shutdown the socket when either is closed, some only if stdout
is closed, and others only if both are closed.  if writing the network
socket results in an fatal error they tend to close their side of the
child's stdout and stderr, so the child receives an error trying to write
to them.

- read from the network socket until an eof indication, writing the data to
their side of the chlid's stdin, closing it on eof.  if writing to the
child results in an error they usually shutdown the receive side of the
network socket, so that the peer receives an error trying to send.

typically written using non-blocking i/o, using select or poll to monitor
the fd's for activity.

Quote:>What I'd like to do is write a wrapper program, sort of like a
>bi-directional tee, which I could wrap around any other arbitrary
>process to capture all the stdin/out/err traffic of a child process
>without affecting its operation.  Is there a program which already
>does that?

expect.

--
bringing you boring signatures for 17 years

 
 
 

avoiding deadlock processing child's stdin/out/err

Post by rohi » Wed, 22 May 2002 13:51:15




> > How do programs like telnet and rlogin (and their daemons) avoid
> > deadlock when dealing with stdin/stdout/stderr of a child process?  I
> > assume they turn off write buffering.  Is it sufficient to use
> > non-blocking IO or is there some other trick?

> > What I'd like to do is write a wrapper program, sort of like a
> > bi-directional tee, which I could wrap around any other arbitrary
> > process to capture all the stdin/out/err traffic of a child process
> > without affecting its operation.  Is there a program which already does
> > that?

> You failed to explain..
> Are you sure that any shell can't do the job?
> check out the "| < > << >> n>" bash operators

you can use ptrace to inspect the traffic (just examine all the read
write callls to the 0 1 and 2 descriptors )
 
 
 

avoiding deadlock processing child's stdin/out/err

Post by John Wiers » Wed, 22 May 2002 23:44:05




> >How do programs like telnet and rlogin (and their daemons) avoid
> >deadlock when dealing with stdin/stdout/stderr of a child process?  

> daemons often do, more or less:

> - read from their side of their child's stdout and stderr until they
> receive an eof indication, writing the data to the network socket.  some
> daemons will shutdown the socket when either is closed, some only if stdout
> is closed, and others only if both are closed.  if writing the network
> socket results in an fatal error they tend to close their side of the
> child's stdout and stderr, so the child receives an error trying to write
> to them.

> - read from the network socket until an eof indication, writing the data to
> their side of the chlid's stdin, closing it on eof.  if writing to the
> child results in an error they usually shutdown the receive side of the
> network socket, so that the peer receives an error trying to send.

> typically written using non-blocking i/o, using select or poll to monitor
> the fd's for activity.

Thanks for the details.  That helps.

Quote:> >What I'd like to do is write a wrapper program, sort of like a
> >bi-directional tee, which I could wrap around any other arbitrary
> >process to capture all the stdin/out/err traffic of a child process
> >without affecting its operation.  Is there a program which already
> >does that?

> expect.

I'll bite.  How can expect handle this?  Is it described in the expect
book or in the expect documentation?  (Where?)  Or in some previous
discussion on the tcl newsgroup?  (What keyword(s) to search for?)

Thanks!
-- John Wiersba

 
 
 

1. Getting a child and child's child process-id

 Why not just have the parent fork twice ??? Saves a lot of trouble ...
--


#  Have you read your Book In Basic Life Education today ? You should !!  #
#  Any views I express are not necessarily those of Brighton Polytechnic  #
###################### "surivorter erutangis a ma I" ######################

2. Patching kernel: which ORIGFILE is used?

3. Server answering more than 1 IP Address

4. Taking over a child process's stdin/stdout

5. Btrieve for LINUX?

6. Can a parent process place input as stdin of child process?

7. IP tracing

8. smail failed to reap child process: No child processes

9. how to kill a child process that runs other children processes

10. Using separate window child process for stdin/stdout

11. Running stdin/out through a pipe to a child process

12. How to redirect stdin/out for child process