flock

BASH local and flock

不问归期 提交于 2019-12-24 05:52:08
问题 I try to use a flock like here https://stackoverflow.com/a/169969 but within a function ... and I try to update a local variable (locale to the function) from within the flock part, but it seems not update ... cat test.sh #!/bin/bash function _job_worker() { local z=1 local result= ( # Wait for lock on /var/lock/.manager.exclusivelock (fd 200) flock -x -w 10 200 || return z=2 echo "slot equal $z" ) 200>/var/lock/.manager.exclusivelock echo "slot equal $z" } _job_worker ./test.sh slot equal 2

Writing to same file at the very same time

╄→尐↘猪︶ㄣ 提交于 2019-12-24 02:14:10
问题 Ok, I know that there's been similar questions on this site about this problem, but none of this questions and provided answers isn't exactly what I need. I'm building flat-file based CMS. What if, for example: 2, 3, 10..... fwrite in appending mode requestes come to same php file "contact_form_messages_container.php" at the same time? 2, 3, 10..... fwrite in "w" mode requestes come to same php file which holds the simpley nubmer of specific page visits, again at the same time? I know about

Apache RewriteLock alternative using PHP?

最后都变了- 提交于 2019-12-23 03:02:42
问题 My server is running CentOS under Plesk so editing my httpd.conf to add a Rewritelock entry is not an option as I understand it. A RewriteLock entry is also not allowed in a vhost.config either, so I think I'm stuck looking at an alternative as decribed here. As a test I am successfully using this approach, which is slightly modified since my entries are in my vhost.conf. I also added my attempt at locking the file: #!/usr/bin/env php <?php /* Extra lines to add to vhost.conf: RewriteEngine

Locking Files in Bash

痴心易碎 提交于 2019-12-20 02:27:28
问题 I have a Problem to find a good concept on locking files in bash, Basically I want to achieve the following: Lock File Read in the data in the file (multiple times) Do stuff with the data. Write new stuff to the file (not necessarily to the end) Unlock that file Doing this with flock seems not possible to me, because the file descriptor will just move once to the end of the file. Also creating a Tempfile fails, because I might overwrite already read lines which is also not possible. Edit:

Having issues with flock() function

☆樱花仙子☆ 提交于 2019-12-19 11:23:03
问题 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 thinking of using flock() , but I'm having trouble finding enough information about how exactly flock works. I read that flock() unlocks the file once the file is

flock(): removing locked file without race condition?

淺唱寂寞╮ 提交于 2019-12-17 09:42:37
问题 I'm using flock() for inter-process named mutexes (i.e. some process can decide to hold a lock on "some_name", which is implemented by locking a file named "some_name" in a temp directory: lockfile = "/tmp/some_name.lock"; fd = open(lockfile, O_CREAT); flock(fd, LOCK_EX); do_something(); unlink(lockfile); flock(fd, LOCK_UN); The lock file should be removed at some point, to avoid filling the temp directory with hundreds of files. However, there is an obvious race condition in this code;

What is the best way to ensure only one instance of a Bash script is running? [duplicate]

廉价感情. 提交于 2019-12-17 03:23:12
问题 This question already has answers here : Quick-and-dirty way to ensure only one instance of a shell script is running at a time (39 answers) Closed 2 years ago . What is the simplest/best way to ensure only one instance of a given script is running - assuming it's Bash on Linux? At the moment I'm doing: ps -C script.name.sh > /dev/null 2>&1 || ./script.name.sh but it has several issues: it puts the check outside of script it doesn't let me run the same script from separate accounts - which I

What does 200>“$somefile” accomplish? [duplicate]

风流意气都作罢 提交于 2019-12-12 19:39:49
问题 This question already has an answer here : How does this canonical flock example work? (1 answer) Closed 5 years ago . I've found boilerplate flock(1) code which looks promising. Now I want to understand the components before blindly using it. Seems like these functions are using the third form of flock flock [-sxun] [-w timeout] fd The third form is convenient inside shell scripts, and is usually used the following manner: ( flock -s 200 # ... commands executed under lock ... ) 200>/var/lock

IDM如何工作?

江枫思渺然 提交于 2019-12-12 12:15:13
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 互联网上有许多网站,其中存储着很多数据,例如视频,音乐,文本,图像等。一个网站需要良好的互联网连接才能 访问 各种网站上的 所有数据 。但是,如果您希望在离线时获取此数据,则可以将其下载到设备上并随时访问! 您可以使用多种应用程序在智能手机上下载文件。但是,在 Windows 上没有很多可用于下载数据的选项。 Internet Download Manager 也称为“ IDM ”,它是Windows用户的应用程序,可帮助用户管理和计划Windows上的下载。 IDM如何工作 ? IDM将您的文件分为多个部分,并同时在PC上下载它们。下载的部件将以其格式临时保存在硬盘上,然后将它们合并以恢复已下载的原始文件。 由于此功能分别下载所有部分,因此有助于节省大量时间。 99.99%完成后, 此功能可以帮助您在 IDM下载中断后继续恢复 ! 您可以在各种Internet浏览器上使用它,例如Internet Explorer,Google Chrome,Opera,Apple Safari,Flock,Firefox,Netscape Navigator等。 来源: oschina 链接: https://my.oschina.net/u/4295806/blog/3142117

How can I lock a directory in C on a linux machine

旧巷老猫 提交于 2019-12-12 10:46:36
问题 Will flock or lockf work on a directory? I there another way to lock a directory in C on a linux machine? 回答1: Yes, more info about using flock on file/directory can be found here 回答2: You can't open a directory for writing, so that means you can't get a write lock on it. Even if you could, please keep in mind that flock and fcntl and other kinds of POSIX locks are advisory, so they don't actually prevent software that doesn't respect the lock from doing things. Maybe you want to look at