POSIX::1003::Fcntl - POSIX function fcntl
POSIX::1003::Fcntl is a POSIX::1003::Module
use POSIX::1003::Fcntl;
One function, which hides many tricks with file-descriptors. This module tries to provide functions which separates the various uses.
Extends "DESCRIPTION" in POSIX::1003::Module.
Extends "METHODS" in POSIX::1003::Module.
Inherited, see "METHODS" in POSIX::1003::Module
See perlfunc fcntl. This raw call to fcntl() is only in some cases simple, but often isn't.
perlfunc fcntl
fcntl()
Not standard POSIX, but available on many POSIX platforms. Often implemented as fcntl(), which is more complex to use. On other platforms implemented as separate OS feature.
Perl core provides a flock which may hide plaform differences. This flockfd is the pure version. Try to use setfd_lock(), which is more portable and flexible.
flock
flockfd
example:
use POSIX::1003::Fcntl ':flock'; if(flockfd $fd, LOCK_EX|LOCK_NB) ... flockfd $fd, LOCK_UN;
Not standard POSIX, but available on many POSIX platforms. Often implemented via fcntl(), which is more complex to use.
use POSIX::1003::Fcntl ':lockfd'; if(lockf $fd, $fcntl->{F_LOCK}) ... lockf $fd, $fcntl->{F_ULOCK};
Functions $fcntl->{F_DUPFD} and $fcntl->{F_DUPFD_CLOEXEC}: dupplicate a file-descriptor to the lowest free fd number.
-Option --Default close_on_exec <false>
my $dup_fd = fcntl_dup \*STDOUT; my $dup_fd = fcntl_dup 2, close_on_exec => 1;
Control the file descriptor flags, function $fcntl->{F_GETFD}.
Get the file status flags and access modes, function $fcntl->{F_GETFL}.
my $flags = getfd_flags(fd); if ((flags & O_ACCMODE) == O_RDWR)
Function $fcntl->{F_GETLCK}. Returns the first lock which would prevent getting the lock. The %options are the same as for setfd_lock().
if(my $lock = getfd_islocked \*IN) ...
Function $fcntl->{F_GETLEASE}.
my $lease = getfd_lease(\*STDIN) or die $!; if($lease != $fcntl->{F_RDLCK}) ...
Function $fcntl->{F_GETOWN} or $fcntl->{F_GETOWN_EX}.
my ($type, $pid) = getfd_owner($fd); defined $type or die $!; if($type==$fcntl->{F_OWNER_PGRP}) ... my $pid = getfd_owner($fd) or die $!;
Function $fcntl->{F_GETPIPE_SZ}.
my $size = getfd_pipe_size($pipe) or die $!;
Function $fcntl->{F_GETSIG}.
my $signal = getfd_signal(\*STDOUT) or die $!;
Change the file descriptor flags, function $fcntl->{F_SETFD}.
Change the file status flags and access modes, function $fcntl->{F_SETFL}.
Function $fcntl->{F_SETLEASE}.
setfd_lease(\*STDOUT, $fcntl->{F_WRLCK}) or die $!;
Functions $fcntl->{F_SETLK} and $fcntl->{F_SETLKW}: request a lock for (a section of) a file.
-Option --Default len <until end of file> private <false> start 0 type $fcntl->{F_RDLCK} wait <false> whence SEEK_SET
Linux kernel >= 3.15 provides "open file description locks", also known as "file-private POSIX locks". Use them when available.
setfd_lock \*IN, type => $fcntl->{F_WRLCK}, wait => 1 or die "cannot lock IN: $!\n";
Function $fcntl->{F_NOTIFY}.
my $d = openfd('/etc', O_RDONLY|O_DIRECTORY) or die $!; setfd_notify($d, DN_ACCESS|DN_CREATE|DN_MULTISHOT) or die $!;
Function $fcntl->{F_GETOWN} or $fcntl->{F_GETOWN_EX}. The _EX version is attempted if provided.
-Option--Default type <looks at sign>
setfd_owner($fh, $pid) or die $!; setfd_owner($fh, $pid, type => $fcntl->{F_OWNER_TID}) or die $!; setfd_owner($fh, -9); # $pid=9, type=$fcntl->{F_OWNER_PGRP}
Function $fcntl->{F_SETPIPE_SZ}.
setfd_pipe_size($pipe, 16384) or die $!;
Function $fcntl->{F_SETSIG}.
setfd_signal(\*STDOUT, SIGINT) or die $!;
The following constants are exported, shown here with the values discovered during installation of this module.
The constant names for this fcntl module are inserted here during installation.
This module is part of POSIX-1003 distribution version 0.99_04, built on March 11, 2015. Website: http://perl.overmeer.net. The code is based on POSIX, which is released with Perl itself. See also POSIX::Util for additional functionality.
Copyrights 2011-2015 on the perl code and the related documentation by [Mark Overmeer]. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html
To install POSIX::1003, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POSIX::1003
CPAN shell
perl -MCPAN -e shell install POSIX::1003
For more information on module installation, please visit the detailed CPAN module installation guide.