I have a bunch of different R processes (independently launched from the command line) that all need to load different big files. To avoid clogging the network, I want to add a lock / semaphore, e.g. via a lock file, so that they get their file one after the other. Only one process should be able to acquire the lock, on a standard Linux system.
While I couldn't find an R package, there is the Linux command lockfile
that can be used:
write("Attempting to get lock", stderr())
system("lockfile /tmp/my_simple_lock")
# Do stuff
write("Releasing lock", stderr())
system("rm -f /tmp/my_simple_lock")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With