mute: silence a running command
I frequently start interactive programs from a terminal---often using
the handy xdg-open
script, sometimes
explicitly. I sometimes remember to redirect stdout and stderr to
/dev/null
, but not always. Hell, half the time I forget to run the
command asynchronously with &
. It's easy to put a command into the
background---a quick ^Z
and bg
and disown
and you're off to the
races. But it's a little harder to silence a command after the fact!
"A happy life must be to a great extent a quiet life, for it is only in an atmosphere of quiet that true joy can live." ---Bertrand Russell
I wrote a tool I call mute
that
uses gdb
to intervene on a
running program and try to redirect various file descriptors to
/dev/null
(or, failing that, close them). mute
is pretty flexible,
with the ability to specify particular file descriptors or auto-detect
any file descriptor open on a tty (-t
):
Usage: mute [-tfandv] [-o TARGET] PID [FD ...]
-t only close FDs if they are ttys (if no FDs specified, will close all tty FDs)
-f close FDs unconditionally
-a append to TARGET rather than truncating
-n dry run; shows the GDB script to be used, but does not run it
-d debug mode (shows debugging output on stdout; repeat to increase output)
-v show version information and exit
-o TARGET redirect FDs to TARGET [default: /dev/null]
relative paths are relative to `mute`'s current directory, not PID's
FD can be a decimal number or one of stdout, stderr, or stdin
Running `mute PID` is the same as `mute -t PID stdout stderr`: FDs 1 and 2 will be
closed if they are tty FDs.
I've only tested on Linux, but most of the features should work
anywhere gdb
works. (mute -t
relies on /proc
to find open file
descriptors, though.)
mute
is licensed under GPLv3; you can download it from https://github.com/mgree/mute/releases.