file-locking

Open in Java(TM) Platform SE binary

对着背影说爱祢 提交于 2019-12-03 08:12:00
问题 I tried to delete a file that I have two of, one slightly changed, so I could delete the older one and replace it with the new one I changed. When I tried to delete the file I got the error message 'file in use' where it said the action can't be completed because the file is open in Java(TM) Platform SE binary. How do I close it? 回答1: This is what worked for me (using Windows). It is basically the same procedure as commented by ali haider, but with more details... Using Windows command prompt

Persistent memoization in Python

巧了我就是萌 提交于 2019-12-03 06:23:20
I have an expensive function that takes and returns a small amount of data (a few integers and floats). I have already memoized this function, but I would like to make the memo persistent. There are already a couple of threads relating to this, but I'm unsure about potential issues with some of the suggested approaches, and I have some fairly specific requirements: I will definitely use the function from multiple threads and processes simultaneously (both using multiprocessing and from separate python scripts) I will not need read or write access to the memo from outside this python function I

Mac OS X equivalent of Linux flock(1) command

丶灬走出姿态 提交于 2019-12-03 01:14:22
Is there a flock command on Mac OS X that manages file lock? http://linux.die.net/man/1/flock There is a cross-platform flock command here: https://github.com/discoteq/flock I have tested it and it works well on OSX as a drop-in replacement for the util-linux flock. Ernest Perl one-liner: perl -MFcntl=:flock -e '$|=1; $f=shift; print("starting\n"); open(FH,$f) || die($!); flock(FH,LOCK_EX); print("got lock\n"); system(join(" ",@ARGV)); print("unlocking\n"); flock(FH,LOCK_UN); ' /tmp/longrunning.sh /tmp/longrunning.sh As a script: #!/usr/bin/perl # emulate linux flock command line utility # use

Open in Java(TM) Platform SE binary

耗尽温柔 提交于 2019-12-02 23:27:49
I tried to delete a file that I have two of, one slightly changed, so I could delete the older one and replace it with the new one I changed. When I tried to delete the file I got the error message 'file in use' where it said the action can't be completed because the file is open in Java(TM) Platform SE binary. How do I close it? robguinness This is what worked for me (using Windows). It is basically the same procedure as commented by ali haider, but with more details... Using Windows command prompt: tasklist | findstr java ("findstr" is a command line utility for Windows similar to "grep" in

Is a Java FileLock a POSIX advisory (fcntl) lock

徘徊边缘 提交于 2019-12-01 09:24:33
I have a C++ program that locks files using POSIX advisory locks. That is, it uses the POSIX fcntl system call for lock operations. I want a Java program to interoperate with that C++ program, so I want my Java program to also use POSIX advisory locks. File locking in Java should use the standard FileLock class. But the API documentation is understandably vague on just how locking is implemented: This file-locking API is intended to map directly to the native locking facility of the underlying operating system. Thus the locks held on a file should be visible to all programs that have access to

Is a Java FileLock a POSIX advisory (fcntl) lock

谁都会走 提交于 2019-12-01 06:24:11
问题 I have a C++ program that locks files using POSIX advisory locks. That is, it uses the POSIX fcntl system call for lock operations. I want a Java program to interoperate with that C++ program, so I want my Java program to also use POSIX advisory locks. File locking in Java should use the standard FileLock class. But the API documentation is understandably vague on just how locking is implemented: This file-locking API is intended to map directly to the native locking facility of the

How to find out which thread is locking a file in java?

北战南征 提交于 2019-12-01 04:04:08
I'm trying to delete a file that another thread within my program has previously worked with. I'm unable to delete the file but I'm not sure how to figure out which thread may be using the file. So how do I find out which thread is locking the file in java? I don't have a straight answer (and I don't think there's one either, this is controlled at OS-level (native), not at JVM-level) and I also don't really see the value of the answer (you still can't close the file programmatically once you found out which thread it is), but I think you don't know yet that the inability to delete is usually

How do I use the linux flock command to prevent another root process from deleting a file?

Deadly 提交于 2019-12-01 03:37:01
I would like to prevent one of my root processes from deleting a certain file. So I came across the flock command, it seems to fit my need, but I didn't get its syntax. If I only indicate a shared lock, it doesn't work: flock -s "./file.xml" If I add a timeout parameter, it still doesn't work: flock -s -w5 "./file.xml" It seems that way, it fits in flock [-sxun][-w #] fd# way. (What is this fd# parameter?) So, I tried: flock [-sxon][-w #] file [-c] command Using flock -s -w5 "./file.xml" -c "tail -3 ./file.xml" and it worked, tail command at ./file.xml was executed. But I would like to know,

How do I use the linux flock command to prevent another root process from deleting a file?

邮差的信 提交于 2019-11-30 23:56:55
问题 I would like to prevent one of my root processes from deleting a certain file. So I came across the flock command, it seems to fit my need, but I didn't get its syntax. If I only indicate a shared lock, it doesn't work: flock -s "./file.xml" If I add a timeout parameter, it still doesn't work: flock -s -w5 "./file.xml" It seems that way, it fits in flock [-sxun][-w #] fd# way. (What is this fd# parameter?) So, I tried: flock [-sxon][-w #] file [-c] command Using flock -s -w5 "./file.xml" -c

PHP check if file locked with flock()?

一曲冷凌霜 提交于 2019-11-30 17:54:24
Will fopen() fail if a file exists, but is currently locked with LOCK_EX ? Or do I have to open it, and then try and set a lock, in order to determine if one already exists? I've also read that flock() will; pause [the script] untill you get the lock for indefinite amount of time or till your script times out http://www.php.net/manual/en/function.flock.php#95257 If so, is it true this 'pause' can be by-passed with; if (!flock($f, LOCK_SH | LOCK_NB)) { // file locked, do something else } flock() doesn't actually prevent you from reading/writing to a file, it only allows you to "communicate" the