Xref: news2.mv.net comp.os.msdos.djgpp:7246 From: Thomas Demmer Newsgroups: comp.os.msdos.djgpp Subject: Re: interrupting with ctrl-C Date: Mon, 12 Aug 1996 18:11:18 +0100 Organization: Lehrstuhl fuer Stroemungsmechanik Lines: 57 Message-ID: <320F65B6.15FB@LSTM.Ruhr-UNI-Bochum.De> References: <4ungbb$bqa AT news DOT uni-paderborn DOT de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Jens Jedamzik DJ-Gateway: from newsgroup comp.os.msdos.djgpp Jens Jedamzik wrote: > > jacobsen AT kjemi DOT unit DOT no (Elling Jacobsen) schreibt: > > Hello, > > I have a program in which I write data records to a > > number of files. My problem is that when I interrupt > > the program using ctrl-C, the files are left empty. I guess > > the reason is that the data are kept in memory and are > > not dumped to file at interrupt? Is there any way to > > ensure that all data records are written to file at > > interrupt? > > No matter, how many data you write in a file, MS-DOS > recognizese it's actual size only after closing it via a > system call. > > The simplest way to help your problem could be, to close the > files after each write access and re-open it in append mode > before the next write access. (That's the way I used for my > data logger.) > > Another possible solution is/might be (?) to reditrect the > interrupt to an exit routine that closes all your files. Doesn't do the exit() routine a fcloseall() anyway? > > I hope, that will help you... > > Jens Maybe it is better to fflush() after every write? I think closing and reopening has a bit too much overhead for that. I am not sure if fflush() also flushes the DOS buffers or only the djgpp internal buffers, but from a short glance I saw it just calls DOS21/4000. If you write more than 16kB (i.e the default xfer buffer size for djgpp) you _should_ see something on disk. If not, the problem is somewhere else. -- Ciao Tom ************************************************************* * Thomas Demmer * * Lehrstuhl fuer Stroemungsmechanik * * Ruhr-Uni-Bochum * * Universitaetsstr. 150 * * D-44780 Bochum * * Tel: +49 234 700 6434 * * Fax: +49 234 709 4162 * * Voice/Fax Box: +49 2561 91371 2056 * * http://www.lstm.ruhr-uni-bochum.de/~demmer * *************************************************************