Sample Header Ad - 728x90

is there a really simple and reliable way to create a unique lock (file) on linux? without using `flock`

-2 votes
2 answers
1654 views
EDIT: I learned how to use flock for exclusive lock and how to not mess with it: https://superuser.com/questions/1619940/flock-is-randomly-failing-on-desktop-pc-but-not-on-notebook-could-be-defectiv/ . I think this question is unecessary as there is no need to use anything else than flock. But... "Repeated deletion of answered questions can result in your account being blocked from asking. Are you sure you wish to delete?" I wont delete this question to not mess my account. If left here may also help ppl to understand and use flock. Feel free to delete it tho. --- OLD UNNECESSARY QUESTION For example: I want to create a file lock to prevent a simultaneous backup attempt of the same file, that is run every time I start a new terminal, like on guake that can start several named tabs simultaneously. I do not want to use flock. I have extreme difficulty understanding and trying to use it :( I think the biggest problem is flock -x asdf.txt where asdf.txt is a real existing file, and it gives "flock: bad file descriptor: 'asdf.txt'" and that feels like a not user friendly implementation. I got that example from the man page and I am stuck again. It feels like I am not being able to explain the problem, but the problem is on my test case (answer): I need a file lock to do things exclusively, and I always have a hard time trying to do that with flock...
Asked by Aquarius Power (4537 rep)
Jan 13, 2021, 07:42 PM
Last activity: Jan 22, 2021, 10:09 PM