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

jackliang's Avatar, Join Date: Nov 2010
Newbie 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...
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Why do you want to do this via a signal? Just flush all your buffers with fflush then exit normally.
jackliang's Avatar, Join Date: Nov 2010
Newbie Member
Quote:
Originally Posted by xpi0t0s View Post
Why do you want to do this via a signal? Just flush all your buffers with fflush then exit normally.
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.
xpi0t0s's Avatar, Join Date: Aug 2004
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.