Hello,
I've got a question regarding file locking and the 'wholock' utility. I'm running on Solaris 10 with version
cat $COBDIR/etc/cobver
cobol v5.0.00-e
PRN=R9CTH/AAH:9l.a5.50.03
PTI=WrapPack 4 (7276.7659)
PTI=ES
PTI=Fixpack50.03_13
Process A is reading a file with fcd.LockModeFlags,FCD_LM_MANUAL. wholock shows that process A holds 0 read and 1 write lock.
Process 26709 (user1) on tty ? holds 0 read and 1 write locks
What confuses me is that while Process A holds a write lock, Process B is able to WRITE and REWRITE records on that same file with no problems. Should this be possible and can I rely on 'wholock'?
Thanks in advance for any insight or advice.
- Rich
Hello Rich:
File locks and record locks are different things. A file lock would prevent a process from OPENing a file. In the scenario you describe, it seems process A and process B have both successfully OPENed the file.
Record locks pertain to individual records. Just because process A holds a lock on a particular record, doesn't mean process B is prohibited from reading/writing other records within the file.
Hello,
I've got a question regarding file locking and the 'wholock' utility. I'm running on Solaris 10 with version
cat $COBDIR/etc/cobver
cobol v5.0.00-e
PRN=R9CTH/AAH:9l.a5.50.03
PTI=WrapPack 4 (7276.7659)
PTI=ES
PTI=Fixpack50.03_13
Process A is reading a file with fcd.LockModeFlags,FCD_LM_MANUAL. wholock shows that process A holds 0 read and 1 write lock.
Process 26709 (user1) on tty ? holds 0 read and 1 write locks
What confuses me is that while Process A holds a write lock, Process B is able to WRITE and REWRITE records on that same file with no problems. Should this be possible and can I rely on 'wholock'?
Thanks in advance for any insight or advice.
- Rich
Thanks Dan. So does that mean that 'wholock' is reporting record locks rather than file locks?
Hello,
I've got a question regarding file locking and the 'wholock' utility. I'm running on Solaris 10 with version
cat $COBDIR/etc/cobver
cobol v5.0.00-e
PRN=R9CTH/AAH:9l.a5.50.03
PTI=WrapPack 4 (7276.7659)
PTI=ES
PTI=Fixpack50.03_13
Process A is reading a file with fcd.LockModeFlags,FCD_LM_MANUAL. wholock shows that process A holds 0 read and 1 write lock.
Process 26709 (user1) on tty ? holds 0 read and 1 write locks
What confuses me is that while Process A holds a write lock, Process B is able to WRITE and REWRITE records on that same file with no problems. Should this be possible and can I rely on 'wholock'?
Thanks in advance for any insight or advice.
- Rich
If you truly wish to implement file locking then your program should define the file with LOCK MODE EXCLUSIVE like:
select my-file assign to "myfile.dat"
organization is indexed
access is dynamic
record key is key1
lock mode is exclusive.
An alternative to lock mode is the SHARING clause:
select my-file assign to "myfile.dat"
organization is indexed
access is dynamic
record key is key1
sharing with no other.
Then while the file is opened by one user, other users will be locked out and wll not be able to open the file.
You can also control this type of access by using the sharing clause in the open statement.
OPEN I-O SHARING WITH NO OTHER my-file
Record locks are implemented in the Micro Focus file handler by obtaining a lock on a certain offset and length of bytes within the file so that when another process opens the file and tries to access the same set of bytes they will return a locked status for that record.
That same process can certainly access other records within the same file that are not locked and can write or rewrite records that are not locked as well.
wholock can tell you which processes currently hold locks within the file but this could show many different processes holding locks on different areas within the file.
Thanks.