|
From: Benjamin R. <Ben...@ep...> - 2003-09-11 16:49:20
|
Hi Alex, "Alex Vinokur" <al...@co...> writes: > Here is some program which was invocated on two consoles. > > The program behavior is different on > * Cygwin, DJGPP on the one hand > and > * Mingw on the other hand > environments. If I understand you correctly, you see that with MS's runtime (Mingw) a file that is open can not be removed, while with the Cygwin runtime it can. > Which is right/correct/preferable? Both are "right" or "correct". The standard C runtime specification doesn't prescribe any file locking issues, which is what you see here. So this depends on the actual implementation of fopen(). MS is coming from DOS, a single-process system. When they introduced Windows, they have decided to opt for system integrity and disallow access to files while they are open in another process. That way a program that worked in the single-process DOS system, will continue to work in the multi-process Windows system without needing additional protection. For compatibility this implementation has never changed. If you want to use more low-level functions than fopen(), there are APIs for sharing and locking in Windows, to control the sharing of files even while they are open. Note that Mac OS does/did the same thing, up until the introduction of a Unix basis for their OS in Mac OS X. Cygwin OTOH is coming from Unix, which always was a multi-process system and which traditionally doesn't have *any* file locking in place by default. Unix programs are supposed to know that and if they want to share files, they have to implement or use some extra locking scheme. If you want to protect the files of a server process, you can run the process under its own user account and assign its files to that user account. benny |