Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

CMD &

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

share|improve this question
1  
Similar question here: stackoverflow.com/questions/1323956/… –  dogbane Jan 3 '10 at 13:50
add comment

1 Answer

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
    

Source

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.