'how to redirect /dev/null to stdout/stderr in running process
Test cmd
$ ping localhost > /dev/null & disown
# [3] 20757
$ ls -l /proc/20757/fd
total 0
lrwx------ 1 root root 64 3월 23 14:28 0 -> /dev/pts/5
l-wx------ 1 root root 64 3월 23 14:28 1 -> /dev/null
lrwx------ 1 root root 64 3월 23 14:28 2 -> /dev/pts/5
lrwx------ 1 root root 64 3월 23 14:28 3 -> 'socket:[251223]'
lrwx------ 1 root root 64 3월 23 14:28 4 -> 'socket:[251225]'
current stdout is /dev/null
and i want to redirect /dev/pts/5
so i tried to
$ gdb -p 20757
...
(gdb) p dup2(open("/dev/pts/5", 1089, 0777), 1) # try 1, return false
# $1 = -1
(gdb) p dup2(open("/dev/pts/5", 0), 1) # try 2 return false
# $2 = -1
(gdb) p dup2(open("/dev/null", 0), 1)
# $3 = 1
but i fail to redirect /dev/pts/5
what can i do?
I found one solution
(gdb) p dup2(0, 1)
but it just duplicate stdin to stdout
there tis in status
$ ls -l /proc/20757/fd
total 0
lrwx------ 1 root root 64 3월 23 14:28 0 -> /dev/null
l-wx------ 1 root root 64 3월 23 14:28 1 -> /dev/null
lrwx------ 1 root root 64 3월 23 14:28 2 -> /dev/null
lrwx------ 1 root root 64 3월 23 14:28 3 -> 'socket:[251223]'
lrwx------ 1 root root 64 3월 23 14:28 4 -> 'socket:[251225]'
how can i change /dev/null to /dev/pts/5
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|