The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Column wide file binding Jae Shell Programming and Scripting 2 08-07-2007 08:40 PM
binding problems damn_bkb IP Networking 2 12-17-2006 06:46 PM
CPU Binding in HP UX (psrset) nileshkarania HP-UX 3 08-29-2005 11:43 PM
Binding Virtual IP address to NIC Ronny IP Networking 8 08-23-2005 12:53 AM
key binding in the terminal orid SUN Solaris 4 11-20-2003 01:00 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-15-2008
Registered User
 

Join Date: Jul 2008
Posts: 3
Stumble this Post!
Binding file lifescope to a process

Hi,
I need a way to bind the lifescope of a file to the lifescope of a process, but that file needs to remain visible in the filesystem for other processes. I've been able to do this on Widows based OSes, but the UNIX based OSes solution have eluded me so far. I am aware of the common solution where you can create a file and then unlink it, but then it only is visible to the process who created it, and I need it to be visible to other users on other machines. Any hints?
Thanks for any help on this matter.
Thanks!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-15-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,849
Stumble this Post!
You need a file to remain visible, as in: test for the existence of or list with ls.
But no other process can read or write the file. Then at process exit the file is unlinked and gone forever.

1. each directory in the path the file lives in has to be other execute (world execute)
2. process opens the file, calls flock to gain exclusive read/write. If the processes that need to "see" the file are created by other usernames, open() allows you to set protections like 7-0-0 which means only the given user (or root) can do anything to the file
3. When process is done unlink the file and process exits.
Reply With Quote
  #3 (permalink)  
Old 07-15-2008
Registered User
 

Join Date: Jul 2008
Posts: 3
Stumble this Post!
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!
Reply With Quote
  #4 (permalink)  
Old 07-16-2008
Registered User
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 250
Stumble this Post!
Since the filesystem locking implementation across windows and unix(es) is entirely different
(mandatory -vs- advisory models) and NFS in particular uses statd and lockd userspace processes to guarantee file integrity and provide reasonable nlm behavior you may not be
able to convince me that any approach aimed at cross-platform file locking regardless of context (as you describe) is workable.

The deletion on process close that you desire (though I don't understand why this one feature is terribly important) can only be mandatorily enforced by an extant process.
The kernel will not clean up after you by default.

So a couple of ideas.
1. You could create a locking manager, have processes register a callback with it for action at time of the supplicant's exit and the manager would in turn be responsible for verification of process existence, granting of locks and privilege. All processes seeking access to controlled resources would have to consult the manager. This is the unix way. A way to do this via the new event trigger mechanisms (epoll linux, kqueue, bsd), shouldn't be too hard to write and would probably scale well.
2. Write a kernel module that implements your windows like behavior for a subset of processes and filesystems without the messiness of a locking manager.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
file lifescope process

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0