سؤال

How do I make sure the current line will be written to file completely with a Ctrl+C break? Most of the time I get a partial last line. I know it's normal, but how can I handle this?

Thank you

هل كانت مفيدة؟

المحلول

If running Linux, You can catch the SIGINT signal and flush all your data into the file in the signal handler. Normally all processes in Linux receive SIGINT with default signal mask. All you have to do is to write signal handler function and then use sigaction() system call.

http://man7.org/linux/man-pages/man2/sigaction.2.html

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top