Server Fault is a question and answer site for system and network administrators. 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

Is it possible to let a process started with nohup, write to stdout instead of in a file? or maybe in the file and on the screen?

nohup python &

writes to nohup.out, but I'd like it to output to the screen, nohup is only meant as a hedge when the connection breaks.

share|improve this question
But what happens when your program outputs after the connection breaks? – womble Aug 4 '12 at 23:22

From man nohup:

If standard input is a terminal, redirect it from /dev/null. If standard output is a terminal, append output to nohup.out if possible, $HOME/nohup.out otherwise. If standard error is a terminal, redirect it to standard output. To save output to FILE, use nohup COMMAND > FILE.

(completely revised based on comments )
When exiting a shell or closing a terminal, the child processes will be sent SIGHUP (hangup, the name originates from the time when terminals would dial in to the UNIX computer) to tell them that the terminal is no longer connected. Additionally, when the shell process ends, the child process's stdin, stdout, and stderr streams will be closed. Usually this causes the child process to die. Usually this is a good thing because it avoids leaving processes running with no user.

The purpose of the nohup program is to keep the process running even after the shell terminates and the terminal disconnects. As such, directing its output to the terminal completely defeats the purpose. My original answer (nohup COMMAND | cat) was not helpful because: when the terminal is closed, cat's output is closed and so cat dies which breaks the pipe and sends a SIGPIPE to the nohup process causing it to die. I had answered the question without thinking of the purpose.

To achieve your purpose, run nohup COMMAND > FILE to select the name of the file to direct output to. Then use tail -f FILE to watch the output on a terminal.

Similarly, one could use the following shell construct: COMMAND >FILE 2>&1 </dev/null & to run a command whose stdio streams are not connected to the terminal and can continue running after the terminal is closed. Additionally, in zsh, run the shell-builtin disown to tell zsh to leave the process instead of killing it when the shell ends.

share|improve this answer
One nice addition: If the nohup command was already started with a file name, then you can use tail -f filename to see what is written to the file. – Hennes Aug 4 '12 at 22:16
Doesn't work, once the connection stops the file is not written anymore – Davoud Taghawi-Nejad Aug 5 '12 at 11:32
You're right: I answered the question (send output to terminal) but defeated the purpose. I rewrote my answer accordingly. – dsh Aug 5 '12 at 16:57
  1. nohup python & tail -f nohup.out The tail -f can be killed and restarted at will.

  2. screen python and dis-/re-connect at will.

share|improve this answer

Your Answer


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.