Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   which signal will flush the file buffer in C/C++ (http://www.go4expert.com/forums/signal-flush-file-buffer-c-cpp-t23846/)

jackliang 11Nov2010 16:46

which signal will flush the file buffer in C/C++
 
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 12Nov2010 22:18

Re: which signal will flush the file buffer in C/C++
 
Why do you want to do this via a signal? Just flush all your buffers with fflush then exit normally.

jackliang 13Nov2010 09:54

Re: which signal will flush the file buffer in C/C++
 
Quote:

Originally Posted by xpi0t0s (Post 74671)
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 13Nov2010 13:13

Re: which signal will flush the file buffer in C/C++
 
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.


All times are GMT +5.5. The time now is 12:45.