When using "nohup", the print function won't print until the entire program is finished

Viewed 335

Example in Julia: let's say I have a file "test.jl" with the following code:

for i in 1:3
    sleep(2)
    print("i = ", i, "\n") 
end

Then if I run

nohup julia test.jl &

I won't get each print result every 2 seconds. Instead, I will get all three print results at the end, which is useless for monitoring the progress of a loop that takes forever to complete.

Any suggestions?

2 Answers

It's likely that output buffering is occurring. Try manually flushing standard output:

for i in 1:3
    sleep(2)
    print("i = ", i, "\n") 
    flush(stdout)
end

nohup redirects standard output to $HOME/nohup.out until the process is completed then the results are printed onto screen all at once.

https://linux.die.net/man/1/nohup you can still redirect it live I think, something like tee might work or >&1. Not sure would have to check.

Related