Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Say I start a process in the terminal and it sends output to standard error while it runs. I want to move the process into the background and also silence it at the same time.

Is there a way to do this without stopping the process and starting it again using & and > /dev/null 2>&1 ? I'm wondering if there is some command that performs bg and can change the output descriptors of the target process too.

share|improve this question

4 Answers 4

up vote 6 down vote accepted

Too late. After a process is started, shell has no more control on process file descriptors so you can not silence it by a shell command.

You can only try to kill a SIGHUP to the process. If your process handles it correctly, It should detach from controlling tty. Unluckily, many software do not handle it correctly and simply die.

share|improve this answer
    
can't you do CTRL+Z to put the process in background? it doesn't silence the process, and if you log out, i think it kills the process too. –  Roy Rico Oct 14 '11 at 18:52
1  
@RoyRico, killing a SIGSTOP to a process (or as you say doing CTRL+Z) does not silence a process. It stops a process! –  andcoz Oct 14 '11 at 22:38

The process that is run from a terminal has its stdin, stdout and stderr bound to the terminal and you cannot do anything about it without re-gaining control over that terminal... Normally. But there are some tricky tools that actually let you do it. Have a look at this example. And other programs like retty mentioned there.

share|improve this answer

I disagree with andcoz that it is too late to silence the output.

Assuming the process is running in the foreground, use Ctrl-Z to suspend the process. Doing so will report the job number and the process ID. You can go ahead and move the process to the background using bg %1 (for job #1). Although this moves the process to the background, it doesn't silence the output. To silence the output you can use gdb to redirect all output to /dev/null.

This has been very nicely described previously at http://stackoverflow.com/questions/593724/redirect-stderr-stdout-of-a-process-after-its-been-started-using-command-lin/593764#593764.

share|improve this answer

Yet another command-line tool is detach. The latest version supports writing pidfiles, using files for stdin, stdout and stderr, and running in the foreground. (The website of detach also discusses similar tools.)

http://inglorion.net/software/detach/

share|improve this answer

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.