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 167 times
4
Toothrot
- 3,255
- 3
- 24
- 47
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,116
- 1
- 17
- 25
-
As long as the process is yours, you shouldn't need the sudo. Repeat this mantra "sudo only when absolutely necessary." – MAP Jul 18 '16 at 04:12
-
@MAP Good point. Using Mint, `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
-
OK, the machines I have open windows on now don't include any mints, and the only linux doesn't even seem to *have* gdb. So I can only confirm that on NetBSD it works fine without the sudo. – MAP Jul 18 '16 at 04:46