Questions tagged [lock]
140 questions
401
votes
9 answers
How to get over "device or resource busy"?
I tried to rm -rf a folder, and got "device or resource busy".
In Windows, I would have used LockHunter to resolve this. What's the linux equivalent? (Please give as answer a simple "unlock this" method, and not complete articles like this one.…
ripper234
- 31,063
- 43
- 82
- 90
103
votes
3 answers
What are pid and lock files for?
I often see that programs specify pid and lock files. And I'm not quite sure what they do.
For example, when compiling nginx:
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
Can somebody shed some light on this one?
Stann
- 2,159
- 5
- 23
- 24
80
votes
4 answers
How to list processes locking file?
Using flock, several processes can have a shared lock at the same time, or be waiting to acquire a write lock. How do I get a list of these processes?
That is, for a given file X, ideally to find the process id of each process which either holds, or…
Benubird
- 5,752
- 10
- 36
- 41
76
votes
13 answers
Correct locking in shell scripts?
Sometimes you have to make sure that only one instance of a shell script is running at the same time.
For example a cron job which is executed via crond that does not provide
locking on its own (e.g. the default Solaris crond).
A common pattern to…
maxschlepzig
- 56,316
- 50
- 205
- 279
44
votes
6 answers
Gedit won't save a file on a VirtualBox share: Text file busy
I have a text file that I can change using other applications (for example openoffice). But when I try to change and save it using gedit, I am getting error from gedit:
Could not save the file /media/sf_Ubuntu/BuildNotes.txt.
Unexpected error:…
user654019
- 2,277
- 4
- 21
- 20
41
votes
14 answers
How to make sure only one instance of a bash script runs?
A solution that does not require additional tools would be prefered.
Tobias Kienzler
- 9,184
- 13
- 65
- 106
39
votes
5 answers
What is a spinlock in Linux?
I would like to know about Linux spinlocks in detail; could someone explain them to me?
Navaneeth Sen
- 9,369
- 17
- 58
- 65
30
votes
2 answers
Does redirecting output to a file apply a lock on the file?
If I have a command
$ ./script >> file.log
that gets called twice, with the second call occurring before the first one ends, what happens?
Does the first call get an exclusive lock on the output file? If so, does the second script fail when…
user20672
25
votes
3 answers
How does this script ensure that only one instance of itself is running?
On 19 Aug 2013, Randal L. Schwartz posted this shell script, which was intended to ensure, on Linux, "that only one instance of [the] script is running, without race conditions or having to clean up lock files":
#!/bin/sh
#…
user6860
19
votes
1 answer
Why flock doesn't clean the lock file?
After process is completed, I see that the lock file isn't deleted? Is there any reason that why flock keeps the file ? Also how does flock knows if there is a lock acquired ?
Here is the example from a crontab file
* * * * * flock python…
wayfare
- 293
- 1
- 2
- 5
18
votes
2 answers
How to lock my session in Xfce?
I am looking a simple way to lock my session in Xfce (Debian Unstable). I don't want to have to write my password at every wake-up but I want to be able to press to a shortcut (which launches a commandline) which asks for identification.
The usage…
ppr
- 1,887
- 7
- 23
- 40
17
votes
2 answers
How do you make a cross-process locking in Linux (C/C++)?
I need to make sure one process executes only in one instance at a time. On Windows you could use named mutex. But I have no idea what to use on Linux.
I think I've seen an approach were app creates an exclusive file, but I can't find it anymore. Do…
Coder
- 457
- 2
- 6
- 10
15
votes
3 answers
what is the difference between spin locks and semaphores?
What are the basic differences between spin locks and semaphores in action?
Renjith G
- 5,788
- 16
- 40
- 48
14
votes
3 answers
apt-get wait for lock release
If you are running apt-get commands on terminal and want to install stuff on the software center, the center says it waits until apt-get finishes. I wanted to know if it is possible to do the same but on the terminal, i.e., make apt-get on the…
Camandros
- 443
- 3
- 5
- 13
14
votes
4 answers
Pass multiple commands to flock
flock -x -w 5 ~/counter.txt 'COUNTER=$(cat ~/counter.txt); echo $((COUNTER + 1)) > ~/counter.txt'
How would I pass multiple commands to flock as in the example above?
As far as I understand, flock takes different flags (-x for exclusive, -w for…
d-_-b
- 1,167
- 5
- 18
- 27