4

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.

2
  • Take a look at groups.google.com/forum/#!topic/alt.hackers/0ZMsMc5DvUw Commented 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 . Commented Feb 25, 2015 at 8:59

3 Answers 3

4

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" 
3
  • Interesting. (1) first Ctrl-z to suspend it before running gdb? (2) Is call a command in gdb? Are close and open also? Commented Feb 24, 2015 at 22:30
  • @Tim please see my answer . Commented Feb 25, 2015 at 5:30
  • Does the 2 in the call to open signify O_RDWR? Commented Jan 10, 2020 at 0:29
1

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 
2
  • Shouldn't this be stdout and not stdin? Commented Feb 25, 2015 at 9:39
  • @SamiKuhmonen fixed . Commented Feb 25, 2015 at 10:49
-1

The following will prevent normal returns as well as error messages

2&>1 >/dev/null 
1
  • The OP asks about an already running process. Commented Feb 25, 2015 at 6:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.