9

On Ubuntu 10.04, I have a long Python program that prints a bunch of output; I run this under "nohup". However, it waits until the end to put all the text in nohup.out. When I run similar programs under FreeBSD, each line gets sent to nohup.out. Is there a Ubuntu setting I can set to get the output faster?

Paul Hoffman
  • 2,094
  • 4
  • 18
  • 23

2 Answers2

9

Yeh, this is got to do with the way stdout is buffered by default on Linux. You need to explicitly run setbuf() in the code to override this behavior.

My suggestion is to avoid nohup, if you're using the bash shell, it allows you to disassociate the command from your shell

$ ( my_cmd > ~/output.log 2>&1 & ) 

You can also use disown for a similar effect on a currently running job.

Philip Reynolds
  • 9,751
  • 1
  • 32
  • 33
5

Since your program is python, you can run it with python -u. Alternatively you might find the unbuffer program useful.

Zac Thompson
  • 1,023
  • 10
  • 10