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

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

  1. jackliang

    jackliang New Member

    Joined:
    Nov 11, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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

    Joined:
    Nov 11, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice