1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

which signal will flush the file buffer in C/C++

Discussion in 'C++' started by jackliang, Nov 11, 2010.

  1. jackliang

    jackliang New Member

    which signal will flush the file buffer and then exit in C/C++ ?
    eg. send a signal to flush all file buffers to files/stdout with out invoking fflush().
    -INT, -TERM?
    How do OS or runtime library handle these signals by default?
    someone help me, thanks in advance!
    waiting online...
     
  2. xpi0t0s

    xpi0t0s Mentor

    Why do you want to do this via a signal? Just flush all your buffers with fflush then exit normally.
     
  3. jackliang

    jackliang New Member

    no, i mean how OS handle a signal by default before killing a process.
    I don't mean I'll write a program like this. What if you have only the executable server file? You run the file, somehow want to stop the process later, and parse the log. If all the file buffers are not flushed before the process is killed. you may lose some important log. Right, so I wander whether the OS's default handler of some signal will do this.
     
  4. xpi0t0s

    xpi0t0s Mentor

    No, it's not possible. A kill will have the effect you want to avoid; you will lose the latest log stuff cos it'll still be buffered. You cannot force a process to quit via a normal exit; any forced quit is by definition an abnormal exit. The only way you can make a process exit normally is to send it commands to exit, which by definition are process-dependent, so you will need the source code, or at least the assistance of the program's developers.
     

Share This Page