I used to maintain a script that did reads/writes to a file (not a real database file, but similar use). Because of file locking issues across NFS, and the need to allow multiple readers and multiple writers, I grew my own file lock system.
Each script instance wanting to read or write the "database" file would touch a file in a directory based on the name of the DB file. Touched filenames were chosen to sort lexicographically by timestamp, including the hostname and process number of the script, and whether it was requesting read or write access. For example, the touch filename template might be YYYYMMDDHHMMSS_read_hostname_ppppp. Any process wishing to read or write would first touch a filename appropriately, then read in and sort the existing filenames. If requesting a read lock, and all processes scheduled ahead of it are also reads, then start reading. If it's a write lock, wait until it is the oldest lock request. To release a lock, delete the file. This is a FIFO lock request queue.
You may want some mechanism for timeouts, abnormal terminations, etc.
There are also some subtle considerations for any locking system, so do some research before deploying a critical system.
-QM
--
Quantum Mechanics: The dreams stuff is made of
In reply to Re: Reading and writting data in a text file with several scripts simultaneously time synchronization problem
by QM
in thread Reading and writting data in a text file with several scripts simultaneously time synchronization problem
by thanos1983
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |