UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 4th, 2006, 01:59 PM
karyn1617 karyn1617 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 20 karyn1617 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 23 m 15 sec
Reputation Power: 0
Locking files??

I am using Korn Shell. Is there a way to control access to a file through locking?? Any system calls I could make? I am not sure if I can use flock or fcntl in korn shell..??

Thanks

Reply With Quote
  #2  
Old April 20th, 2006, 04:37 AM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,297 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 9 m 17 sec
Reputation Power: 104
Send a message via ICQ to christo Send a message via Yahoo to christo
you could do it in C or perl using flock(). If your script /has/ to be in ksh, then maybe call something external which uses flock. I'm not aware of any file lock utility in korn itself tho.

christo

Reply With Quote
  #3  
Old April 20th, 2006, 11:22 AM
Ehlanna's Avatar
Ehlanna Ehlanna is offline
Not a clue what to put ...
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: in front of this keyboard
Posts: 814 Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 5 h 10 m 43 sec
Reputation Power: 243
One obvious thing to say is that it would be fruitless to implement this if the file was available via any other route. If you can pretty much confirm that you wil be able to control access to it - or rather all access of nay note will be via your code, then it would be a 'simple' matter of using the existence of another, temporary, file as a locking or enquing mechanism. If the 'lock file' exists then someone else has the file - either retry a few times or just pack up and go home.

Reply With Quote
  #4  
Old April 20th, 2006, 04:12 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 2 m 57 sec
Reputation Power: 48
You need to understand advisory versus mandatory locking.

Advisory means all the players agree to play by the same rules like calling flock.
It also means if you do not call flock or fcntl then there is no way to stop access.

Mandatory means that a lock call via fcntl or flock asks the kernel to lock it.

Therefore, the type of locking you have depends on the UNIX OS you have.
As I remember, AIX has mandatory locking. Most other UNIX flavors have advisory.

The only way to accomplish this in a small way: open the file and chmod 000 the file while you have it open. Then reset access just before you are done.


There are problems with this:
1. if someone else already has the file open befroe your chmod, you lose, and you can't keep him from playing with it.
2. if your process crashes or abends you leave the file in a bad place.
3. you actually have to have the file continuously open, without ever closing it, during the process. For example, you can't call grep or anything else to open the file in the middle of your shell script.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Locking files??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway