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
0
votes
2 answers

PHP Flock and File Upload

I have two processes running in different scripts indepdent of each other. PHP #1 script reads the filename of a file and writes it to a DB PHP #2 script uploads the file I would like to create a third script (also independent) that only executes…
Tegan Snyder
  • 741
  • 1
  • 9
  • 20
0
votes
1 answer

Change flock (util-linux) source so that locks are closed on exec()

Currently flock works as follows: % exec {MY}
Itzie
  • 65
  • 5
0
votes
1 answer

I am getting error when executing flock command

when I am trying to execute flock through cron job I am getting error. I am executing * * * * * /usr/bin/flock -n /usr/local/monitor/asdp_cloudwatch/run_asdp0101.sh and I am getting below error /usr/bin/flock: bad number:…
0
votes
0 answers

Store number of running scripts in a file

I have a PHP script that runs during about 1s (15s for my tests), and I would like to store the number of threads that are running this script to do a specific action when too many scripts/threads are running. To do that I tried to store the number…
B 7
  • 670
  • 7
  • 23
0
votes
2 answers

PHP block file from reading

I am trying a simple algorithm which says: File1: (lock.php) Open a File Lock the File, so that no other PHP file can read this Sleep Release Lock File2: (lockstatus.php) Try to open the file. If not opening Wait for Lock to release Else…
Veer Shrivastav
  • 5,434
  • 11
  • 53
  • 83
0
votes
0 answers

Setting a time limit for flock()

Sometimes my server freezes after a call flock(), and only rebooting it will unfreeze it. This happens because PHP's flock() ignores the execution time limit and some errors when LOCK_UN is used. Question: How can I set the time limit for flock()?…
user3449979
  • 439
  • 1
  • 5
  • 7
0
votes
1 answer

How to make flock block if other process locked the file?

I have a JavaScript application which posts messages to server. I have to gather those messages on server side and analyse them later, so I'm simply writing them to file. The problem is, when I open the file for reading, ie. in Notepad, messages are…
0
votes
1 answer

2D Tower Defense - Units stacking on top of each other

I'm currently implementing a 2D top down Tower Defense game. For the pathfinding I've used a Breadth-First-Search backwards from the goal. Everything works quite fine, though my units all follow the exact same line and therefore might stack on top…
keyboard
  • 2,137
  • 1
  • 20
  • 32
0
votes
1 answer

How to check a file is locked for writing in perl without actually locking it again?

How to check a file is locked for writing in perl. I don't want to use lock again and if it fails it tells that it is being locked by other processes. flock (FILE, LOCK_EX | LOCK_NB) I don't want to use the above technique since it locks the file…
0
votes
2 answers

Using flock to read and write to a file in bash

I have a bash script that may be run many times in parallel, and I need to be able to check the value in a file and modify it. Ideally, I'd like whichever script instance that gets there first to be able to do the reading and the writing without…
donutbrew
  • 81
  • 1
  • 6
0
votes
2 answers

C warning: implicit declaration of function 'flock' only applies to one of two flock() calls

I improved my signal handling function but now when I try to compile my program via gcc ./test2.c -Wall -Wextra, I receive the following; ./test2.c: In function 'end_app': ./test2.c:21: warning: implicit declaration of function 'flock' ./test2.c: In…
Mike -- No longer here
  • 2,064
  • 1
  • 15
  • 37
0
votes
2 answers

Flock in Perl doesnt work

I have a Perl file. The user opens a file, reads data and displays the data in grid. user edits it and saves it back to the file. I am trying to use flock so that when the user reads the file, the file gets locked. I tried below code but it didnt…
Ayesha
  • 835
  • 4
  • 14
  • 33
0
votes
1 answer

bash script flock() locking and starting service

I want to use flock to make sure only once instance of script is running at any given time. Script skeleton looks like this: ME=`basename "$0"`; LOCK="/tmp/${ME}.LCK"; exec 8>$LOCK; if flock -n -x 8; then do things if [ condition ];…
gilbertasm
  • 126
  • 8
0
votes
2 answers

with php fopen() flock() file() Why does it work like this

so if i fopen one file with a+ like fopen($filepath,'a+'); file($filepath); and then i use file($filepath) get the file contents it's ok but why i when i locked the file with flock i also can use file() function get the content why ? $fp =…
poone
  • 29
  • 1
  • 1
  • 5
0
votes
1 answer

Mutex ( Lock File ) on a PHP file

hi guys i searched a lot but i get stocked on this one i have a Mutex class witch basically is using flock and it will lock a file just fine but my script is running over about 200~ above users so because of this my Server Hard Drive will always…
Benjamin fox
  • 95
  • 1
  • 10