Suppose you have been running one deamon for very long time, and unfortunately the log it generated exausted the disk. But you don't want to stop the program cause it has been running for a long time, you don't want to run it from scratch.
The following are the steps that you can prevent the program from generating more logs to disk
without stopping the binary.
without stopping the binary.
Run as root, suppose the binary name is test_deamon
#pgrep test_deamon
21332 21336 21340 21450
#ls –l /proc/21332/fd
#ls -l /proc/21332/fd/
total 3
lrwx—— 1 root root 64 2013-02-27 15:32 0 -> /dev/pts/1
l-wx—— 1 root root 64 2013-02-27 15:32 1 -> /var/log/test_deamon.log <==== means right now log goto this file.
lrwx—— 1 root root 64 2013-02-27 15:32 2 -> /dev/pts/1
#gdb 21332 /FULL/PATH/TO/test_deamon
(gdb) p close(1)
0
(gdb) p creat(“/dev/null″, 0600)
$2 = 1
(gdb) q
#ls -l /proc/PID/fd/
total 3
lrwx—— 1 root root 64 2013-02-27 15:32 0 -> /dev/pts/1
l-wx—— 1 root root 64 2013-02-27 15:34 1 -> /dev/null <==== means previous cmd is succeed.
lrwx—— 1 root root 64 2013-02-27 15:32 2 -> /dev/pts/1
total 3
lrwx—— 1 root root 64 2013-02-27 15:32 0 -> /dev/pts/1
l-wx—— 1 root root 64 2013-02-27 15:34 1 -> /dev/null <==== means previous cmd is succeed.
lrwx—— 1 root root 64 2013-02-27 15:32 2 -> /dev/pts/1
Do the previous steps for each PID you got from “pgrep test_deamon”.