Search code examples
bashjulianohup

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


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?


Solution

  • 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