[SLUG] sending data to STDIN of an arbitrary process

From: draeath (draeath@gmail.com)
Date: Thu Oct 01 2009 - 06:54:44 EDT


Hey all,

This problem had come up for me, and someone on IRC helped me find
this interesting functionality.

It's possible to send data to STDIN of arbitrary processes!

In my example, the Debian installer was hanging as the aptitude child
process was awaiting a "Yes" confirmation to continue. Since aptitude
was run by the installer scripts, there was seemingly no way to
provide this response....

I used 'ps' to find the aptitude process ID, which for this example we
will assume is "1337"

I needed to send the text "Yes" followed by a return. I was root,
which you would probably need to be (or be the user who 'owns' the
process).

Code:
echo Yes > /proc/1337/fd/0

If you don't want to send the return (newline) use "echo -n" as such:
echo -n Yes > /proc/1337/fd/0

Now, there are lots of other file descriptors under /proc/<PID>/fd and
there's also a /proc/<PID>/fdinfo/ tree, but I do not know the
function of these.

Anyways, this is a neat, apparently not-well-known functionality! Enjoy!
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:44:56 EDT