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
1 answer

What happens if we try to unlock an already unlocked file using flock? C lang

Title. What happens if we try to unlock an already unlocked file using flock? That is to say, when we already used a flock(file, LOCK_UN) and we try to use it again! This in C. Is the behavior unexpected? Does it give an error? Does it do…
0
votes
1 answer

using flock inside crontab with node script throws an error

I can't seem to execute this command from a crontab. It works fine from the command line. index.js #!/usr/bin/env node //do stuff crontab */5 * * * * flock -n /tmp/reddit.lock /usr/local/bin/node /home/user/projects/reddit/index.js -u me -p 'pass'…
chovy
  • 72,281
  • 52
  • 227
  • 295
0
votes
2 answers

crontab not running command

I've been trying to run a crontab command but it isn't running for some reason. The command is supposed to send push notifications. My sudo crontab -e looks like this: 0 0 * * 0 /home/[user]/resetWeeklyLeaderboard * * * * *…
user2012741
  • 89
  • 1
  • 8
0
votes
1 answer

File_exists() is returning false when it should return true, what can be causing this?

I edited the entire question to better represent the answer. I had a for loop which would access and edit image files. Within the loop a file_exists() check was made. If the image file did not exist a blank one would be created. What was happening…
Alex
  • 1
  • 2
0
votes
1 answer

What is the usage of flock here?

I am very new to bash scripting. I have read man page for flock but still I am not very clear how it works here. I'd appreciate if anyone could explain it for me. if [ "$passfile" != "/etc/passwd" ]; then ( flock -e 200 echo…
Bernard
  • 4,240
  • 18
  • 55
  • 88
0
votes
1 answer

Synchronize file_get_contents and file_put_contents functions using PHP

I have a json file. I am getting all the contents using file_get_contents and putting the content in a variable called $js. Then I am appending new data or maybe delete some data from the $js variable. Then I am overwriting the data to the json file…
odbhut.shei.chhele
  • 5,834
  • 16
  • 69
  • 109
0
votes
2 answers

How to prevent multiples instances of a shell script ?

using centos5 below is my shell script. I want to prevent it from multiple instance.. but it doesn't work with if I fir "kill -9" option. also I doubt It will work on reboot. Is there anyway to apply this logic ? which can also handle kill -9 or…
Jatin Bodarya
  • 1,425
  • 2
  • 20
  • 32
0
votes
1 answer

node-gyp undefined reference problems

I am attempting to use node-gyp to create an executable to use from node.js which links to shared library from an existing open source project. I can compile the existing open source project (zmap) as a shared object without any problems. My…
jas-
  • 1,801
  • 1
  • 18
  • 30
0
votes
1 answer

Which platforms implement flock?

I'm looking at the Ruby MRI code for File#flock. The documentation states that it's "Not available on all platforms.", but doesn't state which. If I should venture a guess, old FAT file systems might not have locking, but I would like to not be…
troelskn
  • 115,121
  • 27
  • 131
  • 155
0
votes
2 answers

Using flock() in crontab

I am using a crontab that executes a PHP file. I want to implement the flock() command to help prevent duplicate crontabs from running at one time. If I have: * * * * * php /var/www/html/welcome.php How can i add this flock() command? Thanks!
user3647894
  • 559
  • 1
  • 4
  • 28
0
votes
3 answers

fopen and write in file

I have some questions about fopen The first question it’s when i go for add new entry always put to the end of file and no start the file, for example: $fp=fopen("text.dat","a"); fputs($fp,"Hello 1"."\n"); fclose($fp); Always the results in this…
0
votes
2 answers

Make a hit counter using PHP

What's the best way to make a hit counter using PHP or MySQL? I'm having several file overwrite issues using the PHP flock() function, because it isn't working as it should. It tries to write the same file increasing the same variable at the same…
0
votes
2 answers

Python check if another python application is running

I have two applications (compiled from python, running on Windows only). The first one is scheduled: it starts, launches several instances of another application and dies. Also, this scheduled app should check if previously started instances of…
alkaponey
  • 155
  • 1
  • 10
0
votes
1 answer

What causes my json file to get corrupted?

I have a script that counts the frequency of words and saves the results to a json file. When it is run again, it reads the existing json file, combines the results, then re-writes the json file. This can happen repeatedly within a request, and…
TecBrat
  • 3,643
  • 3
  • 28
  • 45
0
votes
1 answer

What is the correct syntax for flock with bash options in cron

I have the following cron job 7,22,37,52 6-16 * * * myuser /bin/bash -l -c "cd /to/my/path/; rake my_rake_task" I need to use this with some file locking so the task doesn't run more than once, and looking about, I see flock is a good tool for…
yekta
  • 3,363
  • 3
  • 35
  • 50
1 2 3
19
20