When a running process gives lots of stdout output throughout its lengthy running process, you don't want to kill it and rerun it. How can you not show the output? Thanks.
- Take a look at groups.google.com/forum/#!topic/alt.hackers/0ZMsMc5DvUwjimmij– jimmij2015-02-24 22:35:56 +00:00Commented Feb 24, 2015 at 22:35
- @jimmij i have read through material you provided . i think the script mentioned is almost good but there is a portion i do not agree with . anyway let me write an answer here .越鸟巢南枝– 越鸟巢南枝2015-02-25 08:59:15 +00:00Commented Feb 25, 2015 at 8:59
3 Answers
One approach could be to attach a debugger to the process and make it open stdout on /dev/null:
gdb --batch -ex 'call close(1)' -ex 'call open("/dev/null",2)' -p "$pid" - Interesting. (1) first Ctrl-z to suspend it before running
gdb? (2) Iscalla command in gdb? Arecloseandopenalso?Tim– Tim2015-02-24 22:30:52 +00:00Commented Feb 24, 2015 at 22:30 -
- Does the
2in the call toopensignifyO_RDWR?user001– user0012020-01-10 00:29:28 +00:00Commented Jan 10, 2020 at 0:29
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(stdout)) $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(stdout) 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 - Shouldn't this be stdout and not stdin?Sami Kuhmonen– Sami Kuhmonen2015-02-25 09:39:22 +00:00Commented Feb 25, 2015 at 9:39
-
The following will prevent normal returns as well as error messages
2&>1 >/dev/null - The OP asks about an already running process.Matteo– Matteo2015-02-25 06:35:24 +00:00Commented Feb 25, 2015 at 6:35