views:

33

answers:

2

I am running a background process on Mac and have a problem with log update. If I run

someprog > mylog &

then mylog is updated not immediately, but with some intervals - I guess it's due to buffering. Same thing with at now. If I kill the program before output is written to mylog, then I loose the data. There was no such problem with the same program on Linux machines, so I hope I can make it run-time-updated on Mac as well. Any idea how?

someprog is a F77 program, which was not written by me.

I tried to ask this question at SuperUser, but no one can help me there.

EDIT1: I don't feel like changing the source, but keep it in mind. Logging works fine on Linux machines, so it should work on Macs as well. It must be a system setting, e.g. buffer size? It would be fine for me to limit the buffer size to a smaller value - now I have to wait hours to see something in the log.

+2  A: 

If you have access to the source code, you can probably just add calls to fflush(stdout) after every printf. If you don't, you could try something tricky with LD_PRELOAD... Basically, make your own version of printf() that calls libc's printf... AND does a flush... Then LD_PRELOAD that library when you run... The app will use yours instead... Kinda risky tho...

dicroce
+1  A: 

That's the usual behaviour of POSIX C programs that are writing to a non-tty stream - I guess F77 shares the same behaviour, or is written in terms of the stdio routines.

I don't know what the right answer is - I guess you'll need to pipe the output through something that pretends to be a tty, but offhand I don't know what (if any) utility provides that option.

Mike G.