Re: How to write to stdin of another process?

From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 03/27/05


Date: Sun, 27 Mar 2005 15:22:47 -0500

In article <d2658f$7sg$1@news.sap-ag.de>, Paul <pg_x@yahoo.com> wrote:

> Jeremiah DeWitt Weiner wrote:
>
> > Paul <pg_x@yahoo.com> wrote:
> >> if I have the PID of another already running process is it possible to
> >> write to its stdin? I guess it is possible so the question is HOW?
> >
> > To an arbitrary process, which was not started in any special way?
> > No.
>
> Are you sure? Those processes still have stdin. Foreground processes read
> from the terminal. Background processes have their stdin connected to some
> created especially for them internal pipes:
>
> # ls /proc/31905/fd/
> lr-x------ 1 p p 64 2005-03-27 14:04 0 -> pipe:[126663]
>
> It should be possible to somehow get the pipe and write to it?

Unless it's a named pipe, you can't get at the other end. It's just an
anonymous endpoint within another process.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


Relevant Pages

  • Re: How does one effect O_NONBLOCK?!
    ... once I've created 3 pipes (for stdout, stderr and stdin) ... child and parent processes and then dup2the 3 descriptors into the ... corresponding ends of the pipes in the child before execve-ing. ... end side of the pipe that's connected to stdin of the child process. ...
    (comp.unix.programmer)
  • Re: man-in-the-middle translation of input
    ... program that spawns the game, forwards its output to stdout, reads my input ... replaces my input by a series of valid game commands. ... write to stdout, I couldn't find a way to read from stdin, preprocess the ... input and feed it through a pipe to the child. ...
    (comp.unix.programmer)
  • Re: Fifo program.
    ... >> Can anyone point me to a simple fifo program? ... >> blocking on stdin. ... If you just put a pipe between them, then it can be 10-20% slower than ...
    (comp.unix.questions)
  • Re: Pipe buffers limit of 16 * 4K
    ... we have a cgi which uses a lib. ... content to the cgi via stdin which, in this case, is a pipe. ... the pipe buffer), take some decisions and then call the lib. ...
    (Linux-Kernel)
  • Re: [patch 3/4] split usermodehelper setup from execution
    ... + * Returns either NULL on allocation failure, ... * exec the process and free the structure. ... * with a pipe as stdin. ...
    (Linux-Kernel)