Possible problem of input / output synchronization with Ruby script under nohup?

Had a weird issue with Ruby script output running under nohup. Basically, there is a serious output delay when writing to a log file or using stdout on nohup.out. You can see the original post here, which was answered on this use case:

stack overflow

It has been suggested that I use something like file_object.sync = true which works, however, I am interested in the specifics of why this happens only when the script is under nohup. I assume that there is a deeper complexity to how nohup buffers its own shell output. That way I can implement a more elegant solution if I have a more detailed output.

Any additional resources are appreciated.

Specifications: Ruby 1.8.7 Linux: looks on CentOS 5.4, 5.6 and Amazon Linux AMI version 2012.03 (a bit similar to CentOS 6.2) Nohup: 8.4

+2
source share
1 answer

This is because your STDOUT not connected to tty, but block-size buffering is used on the file; if it is connected to tty, row-based buffering is used.

If you run your command without NOHUP, the output (both stdout and stderr) will still be connected to the same tty, and it will be buffered line by line. The default behavior of NOHUP is to write to the nohup.out file. Since buffers are usually much larger than lines, it will take much longer to β€œdisplay” the results.

+2
source

All Articles