Masanari Iida wrote: > > I am new to perl. > I run following sample script, and see strace output. > I have 2 questions. > > =========== > #!/usr/bin/perl > > use Fcntl qw/:DEFAULT :flock :seek F_GETFL/; > > sysopen( LOCK_FILE, "./sample.txt", O_WRONLY | O_CREAT); > > $PackedPattern = "ssllll"; > > $LockInfo = pack( $PackedPattern, F_WRLCK, SEEK_SET, 0, 0, $$ ); > $ReturnValue = fcntl( LOCK_FILE, F_SETLK, $LockInfo ) || -1; > > =========== > Strace output. > > open("./sample.txt", O_WRONLY|O_CREAT|O_LARGEFILE, 0666) = 3 > ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfba5928) = -1 ENOTTY > (Inappropriate ioctl for device) > _llseek(3, 0, [0], SEEK_CUR) = 0 > fstat64(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0 > fcntl64(3, F_SETFD, FD_CLOEXEC) = 0 > fcntl64(3, F_SETLK64, {type=F_WRLCK, whence=SEEK_SET, start=0, > len=19946}, 0x9b30b50) = 0 > close(3) = 0 > exit_group(0) = ? > Process 19946 detached > > =========== > Questions > > (1) I set F_SETLK in the script, but the perl returns F_SETLK64. > What makes it to do so? > My test environment is RHEL5 (ia32) perl-5.8.8 > > (2) I see len=19946 in strace output. > But I expect len should be "length of the file(sample.txt)". > So, it should be 0 byte. (st_size=0) > I know the 19946 is the PID of the script, and it is because I set "$$" > so that's why I see the PID in the strace output. > But my question is , why the PID value (19946) was put into the len > field. > > I am appreciate your advice.
The form of fcntl actually used at run time is determined when your perl interpreter is built. If you execute perl -V you will see entries like Off_t='__int64' and lseeksize=8 showing that the interpreter is built to use 64-bit file addressing, which is necessary to address files greater than 2GB in size. The reason you have the process ID in the wrong place is that you are packing the segment start and length values as 32-bit fields (you also have six template characters but only five values) but the fcntl64 structure has 64-bit values in these positions. So you need a pack format of 'ssqql'. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/