|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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
__________________
. Spiration channels: Free scripts, programming tutorials and articles Dotcut alerts: Online Press cuttings / news alerts Clearprop: UK microlight school, wiltshire Uk dating: UK safe dating with Topdates About Christo . . |
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Locking files?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|