[Gllug] Changing destination of shell output

Paul Roberts sakar at stelo.uklinux.net
Wed Oct 23 12:29:38 UTC 2002


Rhys Hopkins <rhys.hopkins at culver-tec.com> writes:

> Does anyone know if it is possible to change redirected output from a
> background or stopped job to another file descriptor ?

I think The /proc filesystem is your friend here. I haven't done this
personally, so my main aim is to point you in the right direction.

Basically, the proc filesystem contains (among other things) all of
the file descriptors of the running processes which can be accessed as
ordinary files. So, if I run this process in the background:

$ cat </dev/zero >/dev/null &
[1] 1424

and I get a PID of 1424, I can access its file descriptors like this:

$ cd /proc/1424/fd
$ ls -l
total 0
lr-x------    1 sakar    sakar          64 Oct 23 13:27 0 -> /dev/zero
l-wx------    1 sakar    sakar          64 Oct 23 13:27 1 -> /dev/null
lrwx------    1 sakar    sakar          64 Oct 23 13:27 2 -> /dev/pts/1

As you can see, these are symlinks to the files I gave it as input /
output. File descriptor 0 is STDIN, 1 is STDOUT, and 2 is STDERR. Any
other files my process opens will be here too.

Hope this helps, - Paul

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list