Say I have called firefox from the terminal with firefox
, and I got back to the terminal. I can now suspend the process with ctrl-z, and resume it in the background with bg
. However it will continue to produce output in the terminal. Is there a way to redirect that at this point? That is, to get the result of having written firefox &>/dev/null &
to begin with?
Asked
Active
Viewed 171 times
4

Toothrot
- 3,435
1 Answers
5
You can do this with gdb
. You'll need to find the process ID (PID) for firefox, which may be included in the suspend message if you've paused the process with Ctrl + Z.
If that message doesn't contain the PID in your terminal, you can find it using something like:
ps aux | grep firefox
With that, you can use this command to launch gdb
:
sudo gdb -p PID
Within the program, these commands will then redirect stdout and stderr to /dev/null
.
p dup2(open("/dev/null",0),1)
p dup2(open("/dev/null",0),2)
detach
quit

clk
- 2,146
gdb
won't to attach to a process without sudo, even if I own the process. I'll check this on a CentOS install later and possibly update my answer. – clk Jul 18 '16 at 04:41