Sponsored Content
Top Forums Programming Binding file lifescope to a process Post 302215066 by Fronsac on Tuesday 15th of July 2008 12:38:41 PM
Old 07-15-2008
Hi Jim,
Thanks for your reply. I fear I may have not written enough details on the problem I am trying to solve. What I forgot to tell is that I am working in a possibly multiplatform solution (Windows and UN*X) and hence can't rely on OS locking mechanisms. The more I think about it the more it seems like it needs to be application-driven.

The problem with your solution is that it's probably not network safe, as different NFS implementations don't correctly support calls from flock or fnctl and these function calls are not guaranteed to be honored by file systems from other OSes. So basically any OS specific file locking is not going to work. What I am really looking for is a way to make sure a file is deleted when a process ends. I've thought of having a 2nd process monitor my first process and then clean up any files left behind in case of a crash, but it seems like a subpart solution when a perfectly viable solution exists for Windows based OSes (CreateFile with FILE_FLAG_DELETE_ON_CLOSE). Is there an equivalent OS provided service I can use that does that?

Don't know if this helps, but the reason I'm going through all this trouble is because I'm trying to implement some form of cross platform advisory file locking that is at least process-crash-tolerant where multiple users on different machines can take the lock for a given file. Obviously, if you've read any papers on such a locking mechanism, please do point me towards it, even if they aren't related at all with the approach I am trying to take right now.

Thanks again!
 

10 More Discussions You Might Find Interesting

1. Solaris

key binding in the terminal

Hello all I would like to make shift+insert a shortcut for "paste from clipboard". how do I do it? where can I find the format to set this key binding, or others? thanks Ori (4 Replies)
Discussion started by: orid
4 Replies

2. HP-UX

CPU Binding in HP UX (psrset)

Hi All, I would like to know the behaviour of psrset in the following model. I have a 4 CPU machine on which i have a couple of databases running and a web application running. supposing i have processers 0 1 2 and 3 I bind processor 0 and 1 to the web application. This ensures that... (3 Replies)
Discussion started by: nileshkarania
3 Replies

3. IP Networking

binding problems

i had a problem when using the bind function.. that is when i create a socket and bind it with a address(usually some file name)... when i run it once it goes on fine but the second time it tells a error since there is already a socket file in that name created by my previous run... but when i... (2 Replies)
Discussion started by: damn_bkb
2 Replies

4. Shell Programming and Scripting

Column wide file binding

What is the best way to bind files in column wide? Looks a simple, but I don't know the most economic way. I tried to merge, and cat function, but not success!! Ex.) file 1 1 2 3 2 3 4 file 2 3 4 5 4 5 6 file 3 2 3 4 1 2 7 I would like to see the result below file 4 1 2 3 3... (2 Replies)
Discussion started by: Jae
2 Replies

5. IP Networking

Binding the IP address

hi all, i have an udp based application that doesn't bind to any particular address. -->while sneding the packets, i have some doubts.... 1) can the packet be transmitted with an source ip address as 0.0.0.0 2) if we select an interface based on destination ip address,... (0 Replies)
Discussion started by: vijaypdp2006
0 Replies

6. IP Networking

Binding the port number.

Hi all, Application A is using an port number 100 and is binded to an interface 1. Application B is using an port number 100 and is binded to an interface 2. can we bind the two applications on same port number based on interfaces. what i want to know is two... (3 Replies)
Discussion started by: vijaypdp2006
3 Replies

7. Red Hat

Lazy binding related

Hi, I'm building an application that would connect to either one of the 2 databases in production. I want to keep the source code common for both environments. The problem lies in the fact that in the target servers there will be only one of the 2 databases installed, hence the application... (2 Replies)
Discussion started by: ishdeepanand
2 Replies

8. UNIX for Dummies Questions & Answers

Binding command in wget.

I was recently reading a manual of wget and there was command as "binding-address" and I read about tcp/ip binding but i don't understand one thing is...what is the use of binding address in wget.. Can anyone help me with this. (6 Replies)
Discussion started by: jFreak619
6 Replies

9. Shell Programming and Scripting

ftp binding error

Hi, I am rite now made my unix box machine as ftp server that is it acting both ways..Now I have sftp script but when I execute get the following error ftp: bind: Address already in use $ From Secure4Access server process at 31-Oct-11 04:52... Your session is inactive and will... (5 Replies)
Discussion started by: rahul125
5 Replies

10. Shell Programming and Scripting

Monitoring processes in parallel and process log file after process exits

I am writing a script to kick off a process to gather logs on multiple nodes in parallel using "&". These processes create individual log files. Which I would like to filter and convert in CSV format after they are complete. I am facing following issues: 1. Monitor all Processes parallelly.... (5 Replies)
Discussion started by: shunya
5 Replies
FLOCK(2)						      BSD System Calls Manual							  FLOCK(2)

NAME
flock -- apply or remove an advisory lock on an open file LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/file.h> #define LOCK_SH 0x01 /* shared file lock */ #define LOCK_EX 0x02 /* exclusive file lock */ #define LOCK_NB 0x04 /* do not block when locking */ #define LOCK_UN 0x08 /* unlock file */ int flock(int fd, int operation); DESCRIPTION
The flock() system call applies or removes an advisory lock on the file associated with the file descriptor fd. A lock is applied by speci- fying an operation argument that is one of LOCK_SH or LOCK_EX with the optional addition of LOCK_NB. To unlock an existing lock operation should be LOCK_UN. Advisory locks allow cooperating processes to perform consistent operations on files, but do not guarantee consistency (i.e., processes may still access files without using advisory locks possibly resulting in inconsistencies). The locking mechanism allows two types of locks: shared locks and exclusive locks. At any time multiple shared locks may be applied to a file, but at no time are multiple exclusive, or both shared and exclusive, locks allowed simultaneously on a file. A shared lock may be upgraded to an exclusive lock, and vice versa, simply by specifying the appropriate lock type; this results in the pre- vious lock being released and the new lock applied (possibly after other processes have gained and released the lock). Requesting a lock on an object that is already locked normally causes the caller to be blocked until the lock may be acquired. If LOCK_NB is included in operation, then this will not happen; instead the call will fail and the error EWOULDBLOCK will be returned. NOTES
Locks are on files, not file descriptors. That is, file descriptors duplicated through dup(2) or fork(2) do not result in multiple instances of a lock, but rather multiple references to a single lock. If a process holding a lock on a file forks and the child explicitly unlocks the file, the parent will lose its lock. The flock(), fcntl(2), and lockf(3) locks are compatible. Processes using different locking interfaces can cooperate over the same file safely. However, only one of such interfaces should be used within the same process. If a file is locked by a process through flock(), any record within the file will be seen as locked from the viewpoint of another process using fcntl(2) or lockf(3), and vice versa. Processes blocked awaiting a lock may be awakened by signals. RETURN VALUES
The flock() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. ERRORS
The flock() system call fails if: [EWOULDBLOCK] The file is locked and the LOCK_NB option was specified. [EBADF] The argument fd is an invalid descriptor. [EINVAL] The argument fd refers to an object other than a file. [EOPNOTSUPP] The argument fd refers to an object that does not support file locking. [ENOLCK] A lock was requested, but no locks are available. SEE ALSO
close(2), dup(2), execve(2), fcntl(2), fork(2), open(2), flopen(3), lockf(3) HISTORY
The flock() system call appeared in 4.2BSD. BSD
November 9, 2011 BSD
All times are GMT -4. The time now is 11:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy