title: How do I use the linux flock command to prevent another root process from deleting a file?
body: <p>I would like to prevent one of my root processes from deleting a certain file. So I came across the flock command, it seems to fit my need, but I didn't get its syntax. </p>
  
  <p>If I only indicate a shared lock, it doesn't work: </p>
  
  <pre><code>flock -s "./file.xml"
  </code></pre>
  
  <p>If I add a timeout parameter, it still doesn't work:</p>
  
  <pre><code>flock -s -w5 "./file.xml"
  </code></pre>
  
  <p>It seems that way, it fits in <code>flock [-sxun][-w #] fd#</code> way.
  (What is this <code>fd#</code> parameter?)</p>
  
  <p>So, I tried:</p>
  
  <pre><code>flock [-sxon][-w #] file [-c] command
  </code></pre>
  
  <p>Using <code>flock -s -w5 "./file.xml" -c "tail -3 ./file.xml"</code> and it worked, tail  command at ./file.xml was executed. </p>
  
  <p>But I would like to know, does the lock end after the command or does it last 5 seconds after the end of the command execution? My main question is, how can I prevent another root process from deleting a file in linux?</p>