- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to lock a file ?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2007 09:47 PM
тАО04-18-2007 09:47 PM
We want to prevent that two or more people edit a text file and overwrite the text typed by others. I thought in file locking.
Is it possible to force a file to be locked when it is gonna be changed ?
Thanx in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2007 10:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2007 10:13 PM
тАО04-18-2007 10:13 PM
Re: How to lock a file ?
The most simple to use would be the RCS commands that already are installed with hpux.
Your users can set locks on the files they check out for editing them (e.g. co -l file).
But all users would be required to abide by RCS.
Then they would prevent each other from modifying locked files.
See manpages rcs, rlog, ci, co, ...
If you need a revision control at a larger (concurrent) scale you could use cvs or subversion.
As for programmatic file locking you can use the fcntl() syscall.
But this also would require the programmes that access or modify files to all abide to this locking mechanism (so called advisory locking).
See man fcntl.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2007 10:14 PM
тАО04-18-2007 10:14 PM
Re: How to lock a file ?
what sort of application ? Or are you talking about OS level lock ?
Please see:
http://www.ecst.csuchico.edu/~beej/guide/ipc/flock.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2007 10:27 PM
тАО04-18-2007 10:27 PM
Re: How to lock a file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2007 11:22 PM
тАО04-18-2007 11:22 PM
Re: How to lock a file ?
from what you describe I don't think there is an actual user controlled locking mechanism available.
If user B for example uses vi, user B will see a message about user A using the file.
But I don't think you can inforce a lock, unless you use the chmod to change ownership.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2007 06:55 PM
тАО04-19-2007 06:55 PM
Re: How to lock a file ?
Since you anyway intend to write a script/program to do this, you could just create a separate lockfile.
I do this for ensuring exclusive editing of some files.
I use:
who am i > $LOCKFILE
or
who -Rm > $LOCKFILE
So that I can show who is holding the lock and when it was created, to anyone who try to edit while lock exist.
You should also trap signals so you make sure to remove the file when editing finish.
To check if someone is bypassing your program you might want to use a ps command, though this might not be feasible if you're on a shared filesystem.
Another idea is to keep a couple of generations of the file in case you want to check differences.
/Tor-Arne
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2007 06:59 PM
тАО04-19-2007 06:59 PM
Re: How to lock a file ?
[[ -e "$LOCKFILE" ]] && {
echo "File is being edited by:"
cat $LOCKFILE
}
/2r
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2007 01:13 AM
тАО04-29-2007 01:13 AM
Re: How to lock a file ?
Don't grant that group write permissions with chown.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2009 04:22 AM
тАО12-18-2009 04:22 AM