welchavw has asked for the wisdom of the Perl Monks concerning the following question:
I look at the output of "lsof -p" for visudo and compare the same output for the perl program.
When visudo is running, I get...
visudo 13070 root 3uW REG 3,3 640 12835419 /etc/sudoers
When the perl program is running (having gotten lock and is looping), I get...
fcntl_loc 13091 root 3w REG 3,3 640 12835419 /etc/sudoers
See, the 3uW looks good for visudo, but where's the "W" to indicate write lock for the perl? Do I have a file lock, or is visudo failing to acquire the lock on /etc/sudoers for some other reason while this perl code is running?
So, I wonder if perhaps my pack is wrong and I am stomping on some memory. Or else something else is going on? Its too late on Friday for me to see what it is - maybe one of you monks can? (Pls don't kill me for the treatment of $rc - this code is just hacked together, thx).
Here's the program.
#!/usr/bin/perl use Fcntl qw(:DEFAULT :flock); use Errno qw(EAGAIN); use strict; use warnings; @ARGV == 1 or die "usage: $0 <filename>\n"; print "opening $ARGV[0]...\n"; open my $fh, ">>$ARGV[0]" or die "open:$!\n"; my $results = pack( "sslll", &F_WRLCK, 0, 0, 0, 0); print "locking $ARGV[0]...\n"; my $rc; while (1) { $rc = fcntl($fh, F_SETLK, $results); last if ($! != EAGAIN || (defined $rc && $rc == 0)); print "sleeping...\n"; sleep 5; print "trying again...\n"; } if ((!defined $rc) || $rc != 0) { die "fcntl:$!\n" }; print "looping forever...\n"; sleep 64*64;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: With a fcntl lock, why this lsof output?
by traveler (Parson) on Sep 23, 2005 at 22:55 UTC | |
by welchavw (Pilgrim) on Sep 26, 2005 at 14:25 UTC |