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.
If I only indicate a shared lock, it doesn't work:
flock -s "./file.xml"
flock -s -w5 "./file.xml"
flock [-sxun][-w #] fd#
flock [-sxon][-w #] file [-c] command
flock -s -w5 "./file.xml" -c "tail -3 ./file.xml"
No, flock does NOT prevent anyone from doing anything. Unix locks are ADVISORY, which means that they prevent other processes from also calling flock (or in the case of a shared lock, prevent another process using an exclusive one).
It doesn't stop root, or anyone else, from reading, writing or deleting the file.
In any case, even if it was a mandatory lock, it wouldn't stop the file being deleted, as it's the file being locked not the directory entry.