Re: question on file locking
- From: "Nils O. Selåsdal" <noselasd@xxxxxxxxxxxxxxxxxxxxx>
- Date: 26 Feb 2006 17:05:46 +0100
Roman Mashak wrote:
Hello, "Nils!
You wrote on 25 Feb 2006 21:37:30 +0100:
??>> Here is 'strace' dump (removed not-important lines):
??>>
??>> open("dump", O_RDWR) = 3
??>> fcntl64(3, F_SETLK, {type=F_WRLCK, whence=SEEK_SET, start=0, len=0}) =
??>> 0 rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0 <here comes
??>> sleep()> ...
NOS> Good, now what about an strace of the second instance ? Or is this it
NOS> ?
Yes, that was second instance trace.
??>> Now compile and link code and run in first console and few seconds
??>> later in second. Second instance should've failed (as I assumed),
??>> because lock is already set on to file, and 'fcntl(fd, F_SETLK,
??>> &lock)' (where lock.l_type = F_WRLCK) should return -1.
NOS> I don't see why you think this should fail.
NOS> The first fcntl call in the code reads:
NOS> if (fcntl(fd, F_SETLKW, &lock) < 0) /* wait if locked */
NOS> return -1;
NOS> As the doc says F_SETLKW does not return with -1 if it can't get
NOS> the lock, it blocks/waits until it can aquire the lock.
NOS> The first instance gets the lock, and is then stuck in an infinte
NOS> loop, doing sleep calls. The lock is released when that process ends
NOS> (e.g. you kill it).
NOS> The second instance gets to that fcntl call. The fcntl call does
NOS> not return until it gets the lock on the file. This happens
NOS> when the first instance exits (is killed.)
The point is this never happens. As long as first instance runs in endless loop, I run second instance and it also comes into loop, no matter if I killed first process or not. Such behavior confuses me.
Ok, that is confusing. File a bugreport.
Though it'd be interresting if there is any difference if you set len to somthing larger than 0.
.
- References:
- question on file locking
- From: Roman Mashak
- Re: question on file locking
- From: Alex Fraser
- Re: question on file locking
- From: Roman Mashak
- Re: question on file locking
- From: "Nils O. Selåsdal"
- Re: question on file locking
- From: Roman Mashak
- Re: question on file locking
- From: "Nils O. Selåsdal"
- Re: question on file locking
- From: Roman Mashak
- question on file locking
- Prev by Date: Re: socket still open after app crashes
- Next by Date: Re: Shell looking in mysterious places for the svn execute file
- Previous by thread: Re: question on file locking
- Next by thread: Re: question on file locking
- Index(es):
Relevant Pages
|
|