Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To make locking reliable you need an atomic operation. Many of the above proposals are not atomic. The proposed lockfile(1) utility looks promising as the man-page mentioned, that its "NFS-resistant". If your OS does not support lockfile(1) and your solution has to work on NFS, you have not many options....</p> <p>NFSv2 has two atomic operations:</p> <ul> <li>symlink</li> <li>rename</li> </ul> <p>With NFSv3 the create call is also atomic.</p> <p>Directory operations are NOT atomic under NFSv2 and NFSv3 (please refer to the book 'NFS Illustrated' by Brent Callaghan, ISBN 0-201-32570-5; Brent is a NFS-veteran at Sun).</p> <p>Knowing this, you can implement spin-locks for files and directories (in shell, not PHP):</p> <p>lock current dir:</p> <pre><code>while ! ln -s . lock; do :; done </code></pre> <p>lock a file:</p> <pre><code>while ! ln -s ${f} ${f}.lock; do :; done </code></pre> <p>unlock current dir (assumption, the running process really acquired the lock):</p> <pre><code>mv lock deleteme &amp;&amp; rm deleteme </code></pre> <p>unlock a file (assumption, the running process really acquired the lock):</p> <pre><code>mv ${f}.lock ${f}.deleteme &amp;&amp; rm ${f}.deleteme </code></pre> <p>Remove is also not atomic, therefore first the rename (which is atomic) and then the remove.</p> <p>For the symlink and rename calls, both filenames have to reside on the same filesystem. My proposal: use only simple filenames (no paths) and put file and lock into the same directory.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload