PDA

View Full Version : about redirection using exec



jsanza@terra.es
2nd May 2006, 04:26 PM
Hello,
I am learning to use exec and redirections and i am having problems. My system:

-Linux 2.6.16-1.2096_FC5 #1 Wed Apr 19 05:14:36 EDT 2006 i686 athlon i386 GNU/Linux
bash --version
-GNU bash, version 3.1.7(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

Ok,I am trying to redirect the standard out from a RUNNING process. ...
using exec? how can i do that?

The first problem is that using FC5 i can't redirect, because bash hang up,
If i do:
[admin@darkstar ~]$ /usr/sbin/lsof -p $$ -a -d0,1,2
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
bash 2734 admin 0u CHR 136,1 3 /dev/pts/1
bash 2734 admin 1u CHR 136,1 3 /dev/pts/1
bash 2734 admin 2u CHR 136,1 3 /dev/pts/1
[admin@darkstar ~]$ 2>/dev/null
[admin@darkstar ~]$ /usr/sbin/lsof -p $$ -a -d0,1,2
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
bash 2734 admin 0u CHR 136,1 3 /dev/pts/1
bash 2734 admin 1u CHR 136,1 3 /dev/pts/1
bash 2734 admin 2u CHR 136,1 3 /dev/pts/1

why don't /dev/null shows?

but i do :
[admin@darkstar ~]$ exec 2>/dev/null

bash hang up!
what am i doing wrong ?

Ok, let go back to my work ...

I want to redirect some io descriptor another ... the process is running in my system...
for example, i am running a C program and i forget to redirect error messages
to a file, if my program fails these errors messages will be printed into console ...

if i get the process number, how can i redirect stdout, stderr from a running process
to a diferrent descriptor, by examle, /dev/null ??

thank you

brunson
2nd May 2006, 07:41 PM
I want to redirect some io descriptor another ... the process is running in my system...
for example, i am running a C program and i forget to redirect error messages
to a file, if my program fails these errors messages will be printed into console ...
You're not going to be able to do that. The process is already spawned in a subprocess, it has duped its stdin/out/err and (mostly) disassociated itself from the parent shell. You'll have to remember to do your redirection when you start the process, or perhaps you can do something with /proc/<pid>/fd/[012], but I wouldn't count on it.