Questions tagged [flock]

Shell: The `flock` utility manages locks in scripts; C programming: flock() applies or removes an advisory lock on an open file.

flock is a command line utility to manage flock advisory locks - i.e., they're a convention instead of a hard restriction.

298 questions
4
votes
2 answers

Do flock locks reset after a system restart?

Let's say the system powers down unexpectedly due to a power outage. Are flock locks always considered to be "unlocked" when the system starts up? On Linux, flock relies on fcntl(...) (file descriptors). Asked another way: Is it unnecessary to…
dajon
  • 2,350
  • 1
  • 16
  • 17
4
votes
0 answers

rsync flock not deleting flocktmp.lock file?

Recently i changed my rsync flock command, and now it stopped deleting the flocktmp.lock file, when the sync is done. Can anyone see the error in my command? That would really help me out! flock -xn /tmp/flocktmp.lock -c "/usr/bin/rsync -avz…
Zeroz
  • 41
  • 3
4
votes
2 answers

Lua Separation Steering algorithm groups overlapping rooms into one corner

I'm trying to implement a dungeon generation algorithm (presented here and demo-ed here ) that involves generating a random number of cells that overlap each other. The cells then are pushed apart/separated and then connected. Now, the original…
BacioiuC
  • 73
  • 1
  • 5
4
votes
2 answers

Use inheritance with stdvector based flocking

At the moment I'm working at an assignment for which I have to make a flocking system with different subclasses that behave different. I'm working with OpenFrameworks and C++. I'm pretty new to Open Frameworks and C++. As a basis I us this…
4
votes
1 answer

fopen(file,w+) truncates the file before I can check if it's locked with flock()

I have a function which receives a filename and a json object to write to a text file. The object is updated and needs to entirely replace the current contents of the file. Each site visitor has their own file. Multiple rapid changes create a…
Peter Oram
  • 6,213
  • 2
  • 27
  • 40
3
votes
1 answer

How to use flock()

I want to use system locks to avoid race conditions. One process being an opencv program saving captured image to a .jpg file. The other process being browser fetching the same image file from the server. I want to avoid race condition between these…
user927774
  • 43
  • 1
  • 4
3
votes
1 answer

PHP - PHPUnit - Test Ability to Secure a Filelock

I am working on updating unit tests for my core library, and came across a scenario regarding filelocks (flock), and wanted to see how others implemented these types of unit tests. Basically I have a utlity File class which will write contents to a…
Mike Purcell
  • 19,847
  • 10
  • 52
  • 89
3
votes
3 answers

Flocking and surrounding instead of moving away?

Are there any examples of flocking where the flock surrounds and engages the target instead of a fish like feeding frenzy where they swoop in then fly away? I'm working on an overhead shooter and I want the pack of melee enemies to rush the enemy…
3
votes
0 answers

When using flock(2) to lock a file, why is it necessary to create a lock file?

I'm learning file locking using flock(2), and I want to write a little C++ utility class to handle the locking. I've read quite a lot online, but there is one part I don't understand. In e.g. Optimal lock file method: 1: open the lock file creating…
picklepick
  • 1,370
  • 1
  • 11
  • 24
3
votes
2 answers

flock() vs. fcntl() semantics in glibc

Related: one, two It's stated that flock() (BSD-locks) and fcntl() (POSIX record-level locks) gives the user incompatible semantics, particularly, in regards of lock release. However, in glibc flock() is implemented in terms of POSIX fcntl(). (I…
DimG
  • 1,641
  • 1
  • 16
  • 23
3
votes
1 answer

Does file() lock the file when reading?

I'm using file() to read through a file like an array with tabs. I want to lock the file but I cannot seem to get flock() working on the file. Is it possible to do this? If so, how? If not, does the file() lock the file from the start and alleviate…
Mr Brimm
  • 133
  • 2
  • 12
3
votes
1 answer

linux: Determining file handle identity via procfs

I'm trying to determine whether it's possible to distinguish between two separate handles on the same file, and a single handle with two file descriptors pointing to it, using metadata from procfs. Case 1: Two File Handles # setup exec…
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
3
votes
1 answer

How to implement cross platform file lock in GO

I need to implement the following behavior in GO: A process should be able to read a file irrespective if any other process has locked the file for writing A process should obtain a write lock, before it can write to the file. This is to ensure…
coder_bro
  • 10,503
  • 13
  • 56
  • 88
3
votes
3 answers

How to flock() an image?

I am looking to flock() an image. Currently I am using the following $img = ImageCreateFromPng($img_path); flock($img,LOCK_EX); It seems that the GD library's file handle is not valid with flock. How can I access the image and flock the file?
Pablo
  • 4,273
  • 7
  • 33
  • 34
3
votes
1 answer

Why doesn't bash's flock with timeout exit if it fails to acquire the lock?

I am playing with using flock, a bash command for file locks to prevent two different instances of the code from running more than once. I am using this testing code: ( ( flock -x 200 ; sleep 10 ; echo "original finished" ; ) 200>./test.lock ) & (…
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248