How to write to stdin of another process?

From: Paul (pg_x_at_yahoo.com)
Date: 03/27/05


Date: Sun, 27 Mar 2005 14:25:37 +0300

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?

> There are ways to do it if you can control how the process starts,
> though. For example, you could create a FIFO and make the process take
> input from it, then write data to the FIFO. Using "screen" might also
> do what you want, depending on what your requirements are.
>
>
>> I managed to send data to the stdin file of the process and it was
>> displayed in the console where the process was running but it wasn't
>> actually read by the process :(
>
> Correction: you managed to send data to the terminal which was
> stdin and stdout of the process. That's not the same thing as sending
> it to the stdin of the process, as you discovered.
>
> Xposted and f'ups set, since this is not really an admin-type question.
>
> JDW

sorry for multiposting. didn't know i shouldn't. won't do it again

-- 
There are 10 types of people - those who understand binary and those that
don't


Relevant Pages

  • Re: How to write to stdin of another process?
    ... > if I have the PID of another already running process is it possible to write ... > I managed to send data to the stdin file of the process and it was displayed ... appropriate to multiple newsgroups, then cross-post. ...
    (comp.unix.misc)
  • Re: How to write to stdin of another process?
    ... > if I have the PID of another already running process is it possible to write ... you could create a FIFO and make the process take ... stdin and stdout of the process. ... since this is not really an admin-type question. ...
    (comp.unix.admin)
  • Re: How to write to stdin of another process?
    ... > if I have the PID of another already running process is it possible to write ... you could create a FIFO and make the process take ... stdin and stdout of the process. ... since this is not really an admin-type question. ...
    (comp.unix.questions)
  • How to write to stdin of another process?
    ... if I have the PID of another already running process is it possible to write ... I managed to send data to the stdin file of the process and it was displayed ... in the console where the process was running but it wasn't actually read by ...
    (comp.unix.misc)
  • How to write to stdin of another process?
    ... if I have the PID of another already running process is it possible to write ... I managed to send data to the stdin file of the process and it was displayed ... in the console where the process was running but it wasn't actually read by ...
    (comp.unix.admin)