let me yank here the solution @jimmij pointed to , with minor modification .
(gdb) attach <pid>
...
(gdb) call open("/dev/null",O_WRONLY)
$1 = 3
(gdb) call dup2($1,fileno(stdinstdout))
$2 = 1
(gdb) call close($1)
...
(gdb) detach
...
for those not familiar with gdb , "attach" "call" "detach" are gdb commands . get information with "help attach" inside a gdb prompt . and "open" "dup2" "close" are library functions . get information with "man 2 open" .
here O_WRONLY equals 1 and fileno(stdinstdout) equals 1 . use literal values or gdb may complain lack of symbols .
and if we want to find a file descriptor already opened , we can .
$ cd /proc/<pid>/fd
$ for i in * ; do
if [[ `readlink $i` == "/dev/null" ]]
fd=$i ; break
fi
done