I'm storing a program's output like so: ./programOutputtingTextToStandartOut > program.log

If the disk fills up, the output stops being written, even if the program still keeps running. Is there a way to set this up so that when free disk space appears, the writing to the file gets automatically restored - without having to restart the program?


Adding a sample programOutputtingTextToStandartOut.

#include <string>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
    string textLine = "Some text";
    ostream* out = &cout;
    while (true) {
        (*out) << textLine << endl << flush;
  • What happens when free disk space appears if “the program still keeps running” when the disk fills up? If it doesn’t automatically resume writing to the file, there may be an error in the program. // Do you have the source code of the program? Can you modify it and recompile it, and are you interested in answers that require you to do that? – Scott Apr 3 '13 at 19:40
  • @Scott I added the essence of the outputting process in the program to the question. Yes, I would consider also modifying that code. – Jānis Elmeris Apr 4 '13 at 12:48

Rather than redirecting the output at console level, I suggest,Use the program itself to manage log.So in that case, you can check disk space at every N operations. If disk space is less than minimum subscribed value - stop logging. Once it drops below the lower threshold - recreate the log file and continue logging. Though some degree of code is required, it would be of the best possible way to control logging.

  • Thanks, this will probably be the way to go if no better solution exists. Only I would probably try to create another program (say, logManager) that manages writing to log and redirect the program's output to that logManager (in this way enabling reusing this method for any other program as well). – Jānis Elmeris Apr 2 '13 at 12:54
  • Yes, a much more modular approach than what I suggested. you would be directly/indirectly using the IPC for these. Only suggestion is - instead of redirecting you can try other IPC methods. – kumar_m_kiran Apr 2 '13 at 13:14
  • Would this be all right? Or am I missing something? ./programOutputtingTextToStandartOut | logger > program.log where logger is this: #!/bin/bash while read line; do echo $line; done – Jānis Elmeris Apr 3 '13 at 8:50
  • No nothing, if you need a more elaborate mechanism, where multiple process output the log then you can have named pipes (or any other IPC) and collect the information through them. Since it was mentioned as logManager, it generally collects information from multiple process and outputs to a file. Else this would be perfectly fine. – kumar_m_kiran Apr 3 '13 at 11:10
  • Still, echo may be too slow if there is a lot of text being output... – Jānis Elmeris Apr 4 '13 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.