Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I've launched a job into the background how can I redirect its output to /dev/null or in some way silence its output?

I didn't start the job like:

CMD >& /dev/null &

I started it like:


Now that CMD is already running, can I silence its output?

share|improve this question
Similar question here:… – dogbane Jan 3 '10 at 13:50
up vote 2 down vote accepted

Taken from the link "redirecting output from a running process" given in this StackOverflow answer to a similar question. You might compare these directions with this answer that discusses the same trick for other purposes.

Here's the basic process, assuming the command is already running. This works well for regular STDOUT output. The original writeup uses cat > foo1 as an example long-running output program.

Depending on the particulars of the process you want to silence, you may need to perform this process on STDERR (or other ouput streams) instead of, or in addition to, STDOUT.

  1. Find the process PID.

    $ ps aux | grep cat
    user 6760 0.0 0.0 1580 376 pts/5 S+ 15:31 0:00 cat
  2. Connect to the process with GDB.

    $ gdb -p 6760 /bin/cat
    GNU gdb 6.4.90-debian
    Copyright (C) 2006 Free Software Foundation, Inc
    [lots more license stuff snipped]
    Attaching to program: /bin/cat, process 6760
    [snip other stuff that's not interesting now]
  3. In GDB, close the process STDOUT. ("(gdb)" is the GDB prompt; type in what you see on those lines. The other lines are example output.)

    (gdb) p close(1)
    $1 = 0
  4. In GDB, open a new file. Notes: the return value "1" indicates the new file was opened as STDOUT; "0600" is the mode (file permissions) of the new file (meaning "readable-and-writable to owner, not to anyone else").

    (gdb) p creat(“/tmp/foo3″, 0600)
    $2 = 1
  5. Quit GDB; leave the process running.

    (gdb) q
    The program is running. Quit anyway (and detach it)? (y or n) y
    Detaching from program: /bin/cat, process 6760


share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .