Opened files remaining busy

Hi,

I have a little problem that I wish you could help.
I have a data acquisition system implemented in Neutrino 6.3.0 SP2. The system can be turned off instantly without notice.
The problem is: when the system is again turned on the files that were opened before the power off stays in a ‘busy state’ and is impossible to access them via an open() call. Only after a chkfsys is possible again to gain access to these files.
Is this something I’m doing wrong? Maybe something about flags in open() call.

Thanks for your help!

Rafael

Rafael,

This is expected behavior.

Why would you expect an option in the open() call could over ride a sudden power loss where the O/S doesn’t have time to properly close a file?

Since your system can suffer sudden power losses, you’ll have to run chkfsys at boot time to ensure the file system is in a known state.

Tim

Tim,

In fact I forgot to mention that we have some time before the system turns off. We have time to kill the process that opened files (aprox. 200 ms) and that is what we do through a watchdog process that inspects if the power source is going to a state of power loss. The point is: apparently, only killing the processes didn’t seem to close properly the files inside the filesystem.
Is there an open mode that flushes files to filesystem leaving it in a “non-corrupted state”? I mean, in my case, a mode that leaves me with “not busy” files after a sudden system power down.

Thank you for your answer,

Rafael

Make sure the hard disk driver is set to commit=high and if that’s not enough you can also use fs-qnx4.so unbusy flag

200ms may not be enough time. One strategy is to always pre-allocate files. This can create some design issues.

Rafael,

One more thing to add to what’s posted above.

When you say you have 200 ms to kill the process, does this mean your dropping a signal on it to kill it?

If so, you could install a signal handler and close the files there to make sure they are closed (instead of left open when you kill the process). It’s technically not safe to close the files from there but since your about to die anyway, I’m not sure there’s much to lose.

Tim

When a process is killed the file descriptor are close anyway, should not make any difference if you call close or not.