Path: utzoo!utgpu!news-server.csri.toronto.edu!csri.toronto.edu!wayne Newsgroups: comp.os.minix From: wayne@csri.toronto.edu (Wayne Hayes) Subject: Re: File locking in MINIX and UNIX Message-ID: <1991Feb16.013731.18087@jarvis.csri.toronto.edu> Organization: CSRI, University of Toronto References: <39313@cup.portal.com> Date: 16 Feb 91 06:37:31 GMT Lines: 33 Well, some Unixes support *voluntary* file locking, that is, the OS will tell you if a file is locked only if you ask, but it's not enforced. Also, the first process has to explicitly lock the file, and the second process has to explicitly ask if the file is locked. Regardless of whether the file is locked, the second (any any other) process(es) may open the file and do with it as they please. This can usually be construed as a feature, and is *very* useful under many circumstances. It is in fact quite rare that two processes will access the same file for writing at the same time without each other's knowledge. It requires that either the file is writable by more than one user ID, or that one person is silly enough to start two different programs that write to the same file when they're not supposed to. The only time I have ever encountered the former is with an older Unix system that had the /usr/spool/mail/gripes file world-writable so you could put gripes there. Occasionally someone would put a gripe there via mail (as they should), but later want to edit the message. This is why the file was world-writable. Then under the extraordinary circumstance that this very same urge befalls two people at the same time, the first poor fellow to save his changes looses those changes when the second guy saves *his* changes. This happened only once that I know of. Anyway, it's very useful to be able to have one process write while another reads, for instance when you have a log file being created in the background and you want to read the log file with "tail -f" (which BTW doesn't yet work in Minix, but I'll be posting some diffs for tail in the near future to support this.) -- "Dad, what should I be when I grow up?" "Honest." -- Robert M. Pirsig, _Zen and the Art of Motorcycle Maintenence_. Wayne Hayes INTERNET: wayne@csri.utoronto.ca CompuServe: 72401,3525