S
sa
Hi all,
Consider the script below. After reading some man and perldoc on
fcntl, open, etc, I'm obviously doing something wrong - it gives me
the same result regardless whether a file I'm checking is open or
not.
[root@willow tmp]# lsof disk.txt
[root@willow tmp]# ./fcntl_test disk.txt
flags: 4294964736
O_TRUNC
O_APPEND
O_SYNC
O_NOFOLLOW
O_DIRECTORY
O_DIRECT
O_ASYNC
O_LARGEFILE
Now a run when the file is open.
[root@willow tmp]# lsof disk.txt
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
perl 22877 username 4w REG 104,6 18480 508036 disk.txt
[root@willow tmp]# ./fcntl_test disk.txt
flags: 4294964736
O_TRUNC
O_APPEND
O_SYNC
O_NOFOLLOW
O_DIRECTORY
O_DIRECT
O_ASYNC
O_LARGEFILE
Here is the script. Any pointers will be greatly appreciated.
=============================================
#!/usr/bin/perl -w
use Fcntl;
use strict;
use Symbol;
my $fh = gensym;
sysopen $fh, $ARGV[0], O_RDONLY or die "$ARGV[0]: Cannot open ($!)
\n";
my $buf = '';
fcntl($fh, F_GETFL, $buf) or die "Cannot run fcntl\n";
my $flags = unpack 's', $buf;
printf "flags: %u\n", $flags;
for my $f (qw[O_CREAT O_EXCL O_NOCTTY O_TRUNC O_APPEND O_NONBLOCK
O_SYNC O_NOFOLLOW O_DIRECTORY O_DIRECT O_ASYNC
O_LARGEFILE]) {
no strict;
print "$f\n" if ($flags & &$f) == &$f;
}
=============================================
Thanks,
Alex.
Consider the script below. After reading some man and perldoc on
fcntl, open, etc, I'm obviously doing something wrong - it gives me
the same result regardless whether a file I'm checking is open or
not.
[root@willow tmp]# lsof disk.txt
[root@willow tmp]# ./fcntl_test disk.txt
flags: 4294964736
O_TRUNC
O_APPEND
O_SYNC
O_NOFOLLOW
O_DIRECTORY
O_DIRECT
O_ASYNC
O_LARGEFILE
Now a run when the file is open.
[root@willow tmp]# lsof disk.txt
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
perl 22877 username 4w REG 104,6 18480 508036 disk.txt
[root@willow tmp]# ./fcntl_test disk.txt
flags: 4294964736
O_TRUNC
O_APPEND
O_SYNC
O_NOFOLLOW
O_DIRECTORY
O_DIRECT
O_ASYNC
O_LARGEFILE
Here is the script. Any pointers will be greatly appreciated.
=============================================
#!/usr/bin/perl -w
use Fcntl;
use strict;
use Symbol;
my $fh = gensym;
sysopen $fh, $ARGV[0], O_RDONLY or die "$ARGV[0]: Cannot open ($!)
\n";
my $buf = '';
fcntl($fh, F_GETFL, $buf) or die "Cannot run fcntl\n";
my $flags = unpack 's', $buf;
printf "flags: %u\n", $flags;
for my $f (qw[O_CREAT O_EXCL O_NOCTTY O_TRUNC O_APPEND O_NONBLOCK
O_SYNC O_NOFOLLOW O_DIRECTORY O_DIRECT O_ASYNC
O_LARGEFILE]) {
no strict;
print "$f\n" if ($flags & &$f) == &$f;
}
=============================================
Thanks,
Alex.