flock

Using AppleScript to grab the URL from the frontmost window in web browsers: The definitive list

I built a widget that grabs the URL from the frontmost window in Safari, then allows you to shorten it using the tr.im API. Works sweet as. I want to make this more flexible, so am investigating how to grab an URL from other browsers. Here's the AppleScript that works in Safari: tell application "Safari" return URL of front documen...

Where is flock() for Perl on Windows?

I have a Perl script that I'd like to run on Windows, using either Strawberry Perl or ActivePerl; I don't care which. This script however, uses flock() calls, which does not seem to be included in either of those versions of Perl. Can anyone help a Perl n00b get this up and running easily? ...

PHP flock() - what's under the hood?

After wrestling with PHP source for a half an hour, I gave up. :P The question is - what system call does the PHP flock() function call boil down to on a Gentoo Linux system? I'm having some issues with it (like block-for-30-seconds-in-every-one-of-20-loop-iterations kind of issues) and I would like to know why that is so. ...

How do I can linux flock command to prevent another root process deleting a file?

Hello there, I would like to prevent one of my root process from deleting a certaing file. So I came across the flock command, it seems to fit my need, but I didnt get its sintax. If I only indicate a shared lock, it doesnt work: flock -s "./file.xml" If I add a timeout parameter, it still doesnt work flock -s -w5 "./file.xml" It ...

Global disk resource becomes unavailable

Hi all, If I've got a global disk resource (mount point on an isilon file server) that multiple servers use to access a lock file. What is a good way to handle the situation if that global disk becomes unavailable and the servers can't access the global lock file? Thanks, Doug ...

How do I check the exit code of a command executed by flock?

Greetings all. I'm setting up a cron job to execute a bash script, and I'm worried that the next one may start before the previous one ends. A little googling reveals that a popular way to address this is the flock command, used in the following manner: flock -n lockfile myscript.sh if [ $? -eq 1 ]; then echo "Previous script is s...

How to write to file in large php application(multiple questions)

What is the best way to write to files in a large php application. Lets say there are lots of writes needed per second. How is the best way to go about this. Could I just open the file and append the data. Or should i open, lock, write and unlock. What will happen of the file is worked on and other data needs to be written. Will this ...

[linux] flock locking order?

hi all im using a simple test script from http://www.tuxradar.com/practicalphp/8/11/0 like this <?php $fp = fopen("foo.txt", "w"); if (flock($fp, LOCK_EX)) { print "Got lock!\n"; sleep(10); flock($fp, LOCK_UN); } i opened 5 shell's and executed the script one after the other the scripts block until the lock is free'ed and...

Why doesn't bash's flock with timeout exit if it fails to acquire the lock?

I am playing with using flock, a bash command for file locks to prevent two different instances of the code from running more than once. I am using this testing code: ( ( flock -x 200 ; sleep 10 ; echo "original finished" ; ) 200>./test.lock ) & ( sleep 2 ; ( flock -x -w 2 200 ; echo "a finished" ) 200>./test.lock ) & I am running 2...

How to flock() an image?

I am looking to flock() an image. Currently I am using the following $img = ImageCreateFromPng($img_path); flock($img,LOCK_EX); It seems that the GD library's file handle is not valid with flock. How can I access the image and flock the file? ...

PHP check if file locked with flock()?

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...

Does python's fcntl.flock function provide thread level locking of file access?

Python's fcnt module provides a method called [flock][1] to proved file locking. It's description reads: Perform the lock operation op on file descriptor fd (file objects providing a fileno() method are accepted as well). See the Unix manual flock(2) for details. (On some systems, this function is emulated using fcntl().)fu...

flock() question

I have a question about how flock() works, particularly in python. I have a module that opens a serial connection (via os.open()). I need to make this thread safe. It's easy enough making it thread safe when working in the same module using threading.Lock(), but if the module gets imported from different places, it breaks. I was thinkin...

How can I ensure only one copy of a Perl script is running at a time?

I need to ensure that only one copy of my Perl script is running at a time. According to the suggestions here I wrote a sub to do the check: sub check_instances { open my $fh, '<', $0 or die $!; unless (flock($fh, LOCK_EX|LOCK_NB)) { print "$0 is already running. Exiting.\n"; exit 1; } } But it doesn't ...

PHP Flock and File Upload

I have two processes running in different scripts indepdent of each other. PHP #1 script reads the filename of a file and writes it to a DB PHP #2 script uploads the file I would like to create a third script (also independent) that only executes once script #2 has fully completed uploading the file. I'm thinking of using PHP's floc...