Skip to main content

Questions tagged [flock]

0 votes
1 answer
71 views

flock not working between forks on the same fd

I am working on a process that forks several times. To debug it, I am using a debug file for which I open a fd and which stays the same for all child forks. Then I have a function print_debug, that ...
Bastian's user avatar
  • 25
2 votes
1 answer
100 views

How to share a writable flock file in /tmp/ between two users?

It seems that Linux has tightened up security in /tmp in later kernels than 3.x and if /tmp has the sticky bit set another user may not modify a 0777 file. Are there any work arounds for sharing a ...
rrauenza's user avatar
  • 852
-1 votes
1 answer
2k views

What does "trap: SIGINT: bad trap" mean and how do I fix it?

I moved code to a new virtual server running Ubuntu 22. I have the following (edited to make names shorter) in my crontab so that it runs myCommand only if it is not already running: */1 * * * * ...
ferzle's user avatar
  • 3
2 votes
1 answer
302 views

When I use flock it exits immediately instead of waiting

I was confused for a very long time with the meaning of the -n flag for flock(1). Basically there are many guides for this tool, and often what we see is some command like flock -n 100. Here, fd ...
Steven Lu's user avatar
  • 2,432
2 votes
1 answer
120 views

Flock and bash strange chicken and egg problem

In which order are the distinct steps of this bash command done: (flock -n 9) 9> toto.txt If I do only the subshell part: (flock -n 9) I get this result: flock: 9: Mauvais descripteur de fichier (...
Laurent Lyaudet's user avatar
0 votes
0 answers
228 views

Force running a script using flock?

If given a lock on a script using flock(), is it possible to make a force run/unlock based on some argument passed to the script?
derwian36's user avatar
1 vote
0 answers
214 views

Ubuntu user not affected by sticky bit on Ubuntu 22.04

I experience a strange behaviour in stick bit on /tmp directory and flock command. Tried with two cases: Case 1: create file with Ubuntu user, root have no access to the created file. ubuntu@:~$ touch ...
Tien Dung Tran's user avatar
0 votes
2 answers
128 views

Shared locking of scripts that may call each other

This is unusual problem and probably it is the consequence of bad design. If somebody can suggest anything better, I'd happy to hear. But right now I want to solve it "as is". There is a ...
Nikita Kipriyanov's user avatar
0 votes
1 answer
1k views

Testing file locking

I have a script which locks a file to avoid concurrent access to it, How can I execute this same script from two different terminals synchronously, to check if it works? Here is the script #!/bin/bash ...
Rob's user avatar
  • 101
-2 votes
1 answer
347 views

Are there any plans for Linux to add higher-level things like Windows' WaitForMultipleObjects?

WaitForMultipleObjects is one of several Windows kernel functions that can suspend and synchronize a calling thread with other threads until resources or etc are available, similar to flock in Linux, ...
Codemeister's user avatar
0 votes
1 answer
288 views

Synchronizing access to shared, remote resource

I have a shared cache on a remote server that multiple clients are reading and writing to, so I need to synchronize access to this cache. I imagine I could: SSH into the remote and acquire a flock on ...
mola's user avatar
  • 101
0 votes
2 answers
206 views

How to run eval with lockf command?

I have a command which I run via eval as shown below. #! /bin/sh readonly scr="MYENV=1 sh /tmp/scr.sh" eval ${scr} -a 1 -b 2 Now I want to run the scr script with lockf utility, so I made ...
Rahul Bharadwaj's user avatar
1 vote
0 answers
490 views

Is this flock usage with if-else safe?

I have two shell scripts that may be run in parallel but may also be run one at a time. Both scripts rely on an initial setup step that takes a while and can't be run by both at the same time. To ...
Etheryte's user avatar
  • 227
-2 votes
2 answers
2k views

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

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/. ...
Aquarius Power's user avatar
13 votes
3 answers
11k views

Handling of stale file locks in Linux and robust usage of flock

I have a script I execute via cron regularly (every few minutes). However the script should not run multiple times in parallel and it sometimes runs a bit longer, thus I wanted to implement some ...
hanno's user avatar
  • 171

15 30 50 per page