POSIX(3pm) | Perl Programmers Reference Guide | POSIX(3pm) |
POSIX - Perl interface to IEEE Std 1003.1
use POSIX (); use POSIX qw(setsid); use POSIX qw(:errno_h :fcntl_h); printf "EINTR is %d\n", EINTR; $sess_id = POSIX::setsid(); $fd = POSIX::open($path, O_CREAT|O_EXCL|O_WRONLY, 0644); # note: that's a filedescriptor, *NOT* a filehandle
The POSIX module permits you to access all (or nearly all) the standard POSIX 1003.1 identifiers. Many of these identifiers have been given Perl-ish interfaces.
This document gives a condensed list of the features available in the POSIX module. Consult your operating system's manpages for general information on most features. Consult perlfunc for functions which are noted as being identical or almost identical to Perl's builtin functions.
The first section describes POSIX functions from the 1003.1 specification. The second section describes some classes for signal objects, TTY objects, and other miscellaneous objects. The remaining sections list various constants and macros in an organization which roughly follows IEEE Std 1003.1b-1993.
The notation "[C99]" indicates functions that were added in the ISO/IEC 9899:1999 version of the C language standard. Some may not be available on your system if it adheres to an earlier standard. Attempts to use any missing one will result in a fatal runtime error message.
Everything is exported by default (with a handful of exceptions). This is an unfortunate backwards compatibility feature and its use is strongly discouraged. You should either prevent the exporting (by saying "use POSIX ();", as usual) and then use fully qualified names (e.g. "POSIX::SEEK_END"), or give an explicit import list. If you do neither and opt for the default (as in "use POSIX;"), you will import hundreds and hundreds of symbols into your namespace.
A few functions are not implemented because they are C specific. If you attempt to call these, they will print a message telling you that they aren't implemented, and suggest using the Perl equivalent, should one exist. For example, trying to access the "setjmp()" call will elicit the message ""setjmp() is C-specific: use eval {} instead"".
Furthermore, some evil vendors will claim 1003.1 compliance, but in fact are not so: they will not pass the PCTS (POSIX Compliance Test Suites). For example, one vendor may not define "EDEADLK", or the semantics of the errno values set by open(2) might not be quite right. Perl does not attempt to verify POSIX compliance. That means you can currently successfully say "use POSIX", and then later in your program you find that your vendor has been lax and there's no usable "ICANON" macro after all. This could be construed to be a bug.
Note that when using threads and in Linux this is not a good way to exit a thread because in Linux processes and threads are kind of the same thing (Note: while this is the situation in early 2003 there are projects under way to have threads with more POSIXly semantics in Linux). If you want not to return from a thread, detach the thread.
$absolute_value = POSIX::abs(42); # good $absolute_value = POSIX::abs(); # throws exception
if( POSIX::access( "/", &POSIX::R_OK ) ){ print "have read permission\n"; }
Returns "undef" on failure. Note: do not use "access()" for security purposes. Between the "access()" call and the operation you are preparing for the permissions might change: a classic race condition.
POSIX::alarm(3) # good POSIX::alarm() # throws exception
"Fri Jun 2 18:22:13 2000\n\0"
and it is called thusly
$asctime = asctime($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
The $mon is zero-based: January equals 0. The $year is 1900-based: 2001 equals 101. $wday and $yday default to zero (and are usually ignored anyway), and $isdst defaults to -1.
Note the result is always in English. Use "strftime" instead to get a result suitable for the current locale. That function's %c format yields the locale's preferred representation.
$rv = POSIX::chdir('path/to/dir'); # good $rv = POSIX::chdir(); # throws exception
$c = chmod 0664, $file1, $file2; # good $c = POSIX::chmod 0664, $file1; # throws exception $c = POSIX::chmod 0664, $file1, $file2; # throws exception
As with the built-in "chmod()", $file may be a filename or a file handle.
$fd = POSIX::open( "foo", &POSIX::O_RDONLY ); POSIX::close( $fd );
Returns "undef" on failure.
See also "close" in perlfunc.
$x_with_sign_of_y = POSIX::copysign($x, $y);
See also "signbit".
$fd = POSIX::creat( "foo", 0611 ); POSIX::close( $fd );
See also "sysopen" in perlfunc and its "O_CREAT" flag.
$path = POSIX::ctermid();
$name = POSIX::cuserid();
Note: this function has not been specified by POSIX since 1990 and is included only for backwards compatibility. New code should use "getlogin()" instead.
This uses file descriptors such as those obtained by calling "POSIX::open".
Returns "undef" on failure.
This uses file descriptors such as those obtained by calling "POSIX::open".
Returns "undef" on failure.
$errno = POSIX::errno();
This identical to the numerical values of the $!, see "$ERRNO" in perlvar.
See also "log1p".
FE_TONEAREST FE_TOWARDZERO FE_UPWARD FE_DOWNWARD
"FE_TONEAREST" is like "round", "FE_TOWARDZERO" is like "trunc" [C99]. Added in Perl v5.22.
my $fused = POSIX::fma($x, $y, $z);
my $min = POSIX::fmax($x, $y);
my $min = POSIX::fmin($x, $y);
$r = fmod($x, $y);
It returns the remainder "$r = $x - $n*$y", where "$n = trunc($x/$y)". The $r has the same sign as $x and magnitude (absolute value) less than the magnitude of $y.
The following will determine the maximum length of the longest allowable pathname on the filesystem which holds /var/foo.
$fd = POSIX::open( "/var/foo", &POSIX::O_RDONLY ); $path_max = POSIX::fpathconf($fd, &POSIX::_PC_PATH_MAX);
Returns "undef" on failure.
FP_NORMAL FP_ZERO FP_SUBNORMAL FP_INFINITE FP_NAN
telling the class of the argument [C99]. "FP_INFINITE" is positive or negative infinity, "FP_NAN" is not-a-number. "FP_SUBNORMAL" means subnormal numbers (also known as denormals), very small numbers with low precision. "FP_ZERO" is zero. "FP_NORMAL" is all the rest. Added in Perl v5.22.
($mantissa, $exponent) = POSIX::frexp( 1.234e56 );
$fd = POSIX::open( "foo", &POSIX::O_RDONLY ); @stats = POSIX::fstat( $fd );
use POSIX ':nan_payload'; getpayload($var)
Returns the "NaN" payload. Added in Perl v5.24.
Note the API instability warning in "setpayload".
See "nan" for more discussion about "NaN".
NOTE: if you have C programs that still use "gets()", be very afraid. The "gets()" function is a source of endless grief because it has no buffer overrun checks. It should never be used. The "fgets()" function should be preferred instead.
For example "ilogb(20)" is 4, as an integer.
See also "logb".
use POSIX qw(Inf); my $pos_inf = +Inf; # Or just Inf. my $neg_inf = -Inf;
See also "isinf", and "fpclassify".
See also "isinf", "isnan", and "fpclassify".
Floating point comparisons which handle the "NaN" [C99]. Added in Perl v5.22.
See also "Inf", "isnan", "isfinite", and "fpclassify".
Note that you cannot test for ""NaN"-ness" with
$x == $x
since the "NaN" is not equivalent to anything, including itself.
See also "nan", "NaN", "isinf", and "fpclassify".
See also "isfinite", and "fpclassify".
use POSIX ':nan_payload'; issignaling($var, $payload)
Return true if the argument is a signaling NaN. Added in Perl v5.24.
Note the API instability warning in "setpayload".
See "nan" for more discussion about "NaN".
POSIX::lchown($uid, $gid, $file_path);
$x_quadrupled = POSIX::ldexp($x, 2);
See also "tgamma".
See also "expm1".
For example "logb(20)" is 4, as a floating point number.
See also "ilogb".
Here is how to query the database for the de (Deutsch or German) locale.
my $loc = POSIX::setlocale( &POSIX::LC_ALL, "de" ); print "Locale: \"$loc\"\n"; my $lconv = POSIX::localeconv(); foreach my $property (qw( decimal_point thousands_sep grouping int_curr_symbol currency_symbol mon_decimal_point mon_thousands_sep mon_grouping positive_sign negative_sign int_frac_digits frac_digits p_cs_precedes p_sep_by_space n_cs_precedes n_sep_by_space p_sign_posn n_sign_posn int_p_cs_precedes int_p_sep_by_space int_n_cs_precedes int_n_sep_by_space int_p_sign_posn int_n_sign_posn )) { printf qq(%s: "%s",\n), $property, $lconv->{$property}; }
The members whose names begin with "int_p_" and "int_n_" were added by POSIX.1-2008 and are only available on systems that support them.
@localtime = POSIX::localtime(time); # good @localtime = localtime(); # good @localtime = POSIX::localtime(); # throws exception
sub log10 { log($_[0]) / log(10) }
or
sub log10 { log($_[0]) / 2.30258509299405 }
or
sub log10 { log($_[0]) * 0.434294481903252 }
$fd = POSIX::open( "foo", &POSIX::O_RDONLY ); $off_t = POSIX::lseek( $fd, 0, &POSIX::SEEK_SET );
Returns "undef" on failure.
For the rounding mode, see "fegetround".
See also "ceil", "floor", "trunc".
Owing to an oversight, this is not currently exported by default, or as part of the ":math_h_c99" export tag; importing it must therefore be done by explicit name.
Core Perl does not have any support for wide and multibyte locales, except Unicode UTF-8 locales. This function, in conjunction with "mbtowc" and "wctomb" may be used to roll your own decoding/encoding of other types of multi-byte locales.
Use "undef" as the first parameter to this function to get the effect of passing NULL as the first parameter to "mblen". This resets any shift state to its initial value. The return value is undefined if "mbrlen" was substituted, so you should never rely on it.
When the first parameter is a scalar containing a value that either is a PV string or can be forced into one, the return value is the number of bytes occupied by the first character of that string; or 0 if that first character is the wide NUL character; or negative if there is an error. This is based on the locale that currently underlies the program, regardless of whether or not the function is called from Perl code that is within the scope of "use locale". Perl makes no attempt at hiding from your code any differences in the "errno" setting between "mblen" and "mbrlen". It does set "errno" to 0 before calling them.
The optional second parameter is ignored if it is larger than the actual length of the first parameter string.
Core Perl does not have any support for wide and multibyte locales, except Unicode UTF-8 locales. This function, in conjunction with "mblen" and "wctomb" may be used to roll your own decoding/encoding of other types of multi-byte locales.
The first parameter is a scalar into which, upon success, the wide character represented by the multi-byte string contained in the second parameter is stored. The optional third parameter is ignored if it is larger than the actual length of the second parameter string.
Use "undef" as the second parameter to this function to get the effect of passing NULL as the second parameter to "mbtowc". This resets any shift state to its initial value. The return value is undefined if "mbrtowc" was substituted, so you should never rely on it.
When the second parameter is a scalar containing a value that either is a PV string or can be forced into one, the return value is the number of bytes occupied by the first character of that string; or 0 if that first character is the wide NUL character; or negative if there is an error. This is based on the locale that currently underlies the program, regardless of whether or not the function is called from Perl code that is within the scope of "use locale". Perl makes no attempt at hiding from your code any differences in the "errno" setting between "mbtowc" and "mbrtowc". It does set "errno" to 0 before calling them.
if (mkfifo($path, $mode)) { ....
Returns "undef" on failure. The $mode is similar to the mode of "mkdir()", see "mkdir" in perlfunc, though for "mkfifo" you must specify the $mode.
Synopsis:
mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
The month ("mon"), weekday ("wday"), and yearday ("yday") begin at zero, i.e., January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The year ("year") is given in years since 1900; i.e., the year 1995 is 95; the year 2001 is 101. Consult your system's "mktime()" manpage for details about these and the other arguments.
Calendar time for December 12, 1995, at 10:30 am.
$time_t = POSIX::mktime( 0, 30, 10, 12, 11, 95 ); print "Date = ", POSIX::ctime($time_t);
Returns "undef" on failure.
($fractional, $integral) = POSIX::modf( 3.14 );
See also "round".
use POSIX qw(NaN); my $nan = NaN;
See also "nan", "/isnan", and "fpclassify".
my $nan = nan();
Returns "NaN", not-a-number [C99]. Added in Perl v5.22.
The returned NaN is always a quiet NaN, as opposed to signaling.
With an argument, can be used to generate a NaN with payload. The argument is first interpreted as a floating point number, but then any fractional parts are truncated (towards zero), and the value is interpreted as an unsigned integer. The bits of this integer are stored in the unused bits of the NaN.
The result has a dual nature: it is a NaN, but it also carries the integer inside it. The integer can be retrieved with "getpayload". Note, though, that the payload is not propagated, not even on copies, and definitely not in arithmetic operations.
How many bits fit in the NaN depends on what kind of floating points are being used, but on the most common platforms (64-bit IEEE 754, or the x86 80-bit long doubles) there are 51 and 61 bits available, respectively. (There would be 52 and 62, but the quiet/signaling bit of NaNs takes away one.) However, because of the floating-point-to- integer-and-back conversions, please test carefully whether you get back what you put in. If your integers are only 32 bits wide, you probably should not rely on more than 32 bits of payload.
Whether a "signaling" NaN is in any way different from a "quiet" NaN, depends on the platform. Also note that the payload of the default NaN (no argument to nan()) is not necessarily zero, use "setpayload" to explicitly set the payload. On some platforms like the 32-bit x86, (unless using the 80-bit long doubles) the signaling bit is not supported at all.
See also "isnan", "NaN", "setpayload" and "issignaling".
my $nextafter = POSIX::nextafter($x, $y);
Like "nexttoward", but potentially less accurate.
my $nexttoward = POSIX::nexttoward($x, $y);
Like "nextafter", but potentially more accurate.
Returns "undef" on failure.
Open a file read-only with mode 0666.
$fd = POSIX::open( "foo" );
Open a file for read and write.
$fd = POSIX::open( "foo", &POSIX::O_RDWR );
Open a file for write, with truncation.
$fd = POSIX::open( "foo", &POSIX::O_WRONLY | &POSIX::O_TRUNC );
Create a new file with mode 0640. Set up the file for writing.
$fd = POSIX::open( "foo", &POSIX::O_CREAT | &POSIX::O_WRONLY, 0640 );
Returns "undef" on failure.
See also "sysopen" in perlfunc.
$dir = POSIX::opendir( "/var" ); @files = POSIX::readdir( $dir ); POSIX::closedir( $dir );
Returns "undef" on failure.
The following will determine the maximum length of the longest allowable pathname on the filesystem which holds "/var".
$path_max = POSIX::pathconf( "/var", &POSIX::_PC_PATH_MAX );
Returns "undef" on failure.
Returns "undef" on failure.
my ($read, $write) = POSIX::pipe(); POSIX::write( $write, "hello", 5 ); POSIX::read( $read, $buf, 5 );
See also "pipe" in perlfunc.
$ret = POSIX::pow( $x, $exponent );
You can also use the "**" operator, see perlop.
$fd = POSIX::open( "foo", &POSIX::O_RDONLY ); $bytes = POSIX::read( $fd, $buf, 3 );
Returns "undef" on failure.
See also "sysread" in perlfunc.
my $remainder = POSIX::remainder($x, $y)
See also "remquo".
(This is quite esoteric interface, mainly used to implement numerical algorithms.)
See also "ceil", "floor", "lround", "modf", and "trunc".
See also "frexp" and "ldexp".
This function modifies and queries the program's underlying locale. Users of this function should read perllocale, whch provides a comprehensive discussion of Perl locale handling, knowledge of which is necessary to properly use this function. It contains a section devoted to this function. The discussion here is merely a summary reference for "setlocale()". Note that Perl itself is almost entirely unaffected by the locale except within the scope of "use locale". (Exceptions are listed in "Not within the scope of "use locale"" in perllocale, and locale-dependent functions within the POSIX module ARE always affected by the current locale.)
The following examples assume
use POSIX qw(setlocale LC_ALL LC_CTYPE);
has been issued.
The following will set the traditional UNIX system locale behavior (the second argument "C").
$loc = setlocale( LC_ALL, "C" );
The following will query the current "LC_CTYPE" category. (No second argument means 'query'.)
$loc = setlocale( LC_CTYPE );
The following will set the "LC_CTYPE" behaviour according to the locale environment variables (the second argument ""). Please see your system's setlocale(3) documentation for the locale environment variables' meaning or consult perllocale.
$loc = setlocale( LC_CTYPE, "" );
The following will set the "LC_COLLATE" behaviour to Argentinian Spanish. NOTE: The naming and availability of locales depends on your operating system. Please consult perllocale for how to find out which locales are available in your system.
$loc = setlocale( LC_COLLATE, "es_AR.ISO8859-1" );
use POSIX ':nan_payload'; setpayload($var, $payload);
Sets the "NaN" payload of var. Added in Perl v5.24.
NOTE: the NaN payload APIs are based on the latest (as of June 2015) proposed ISO C interfaces, but they are not yet a standard. Things may change.
See "nan" for more discussion about "NaN".
See also "setpayloadsig", "isnan", "getpayload", and "issignaling".
use POSIX ':nan_payload'; setpayloadsig($var, $payload);
Like "setpayload" but also makes the NaN signaling. Added in Perl v5.24.
Depending on the platform the NaN may or may not behave differently.
Note the API instability warning in "setpayload".
Note that because how the floating point formats work out, on the most common platforms signaling payload of zero is best avoided, since it might end up being identical to "+Inf".
See also "nan", "isnan", "getpayload", and "issignaling".
Returns "undef" on failure.
Synopsis:
sigaction(signal, action, oldaction = 0)
Returns "undef" on failure. The "signal" must be a number (like "SIGHUP"), not a string (like "SIGHUP"), though Perl does try hard to understand you.
If you use the "SA_SIGINFO" flag, the signal handler will in addition to the first argument, the signal name, also receive a second argument, a hash reference, inside which are the following keys with the following semantics, as defined by POSIX/SUSv3:
signo the signal number errno the error number code if this is zero or less, the signal was sent by a user process and the uid and pid make sense, otherwise the signal was sent by the kernel
The constants for specific "code" values can be imported individually or using the ":signal_h_si_code" tag, since Perl v5.24.
The following are also defined by POSIX/SUSv3, but unfortunately not very widely implemented:
pid the process id generating the signal uid the uid of the process id generating the signal status exit value or signal for SIGCHLD band band event for SIGPOLL addr address of faulting instruction or memory reference for SIGILL, SIGFPE, SIGSEGV or SIGBUS
A third argument is also passed to the handler, which contains a copy of the raw binary contents of the "siginfo" structure: if a system has some non-POSIX fields, this third argument is where to "unpack()" them from.
Note that not all "siginfo" values make sense simultaneously (some are valid only for certain signals, for example), and not all values make sense from Perl perspective, you should to consult your system's "sigaction" and possibly also "siginfo" documentation.
Synopsis:
sigpending(sigset)
Returns "undef" on failure.
Synopsis:
sigprocmask(how, sigset, oldsigset = 0)
Returns "undef" on failure.
Note that you can't reliably block or unblock a signal from its own signal handler if you're using safe signals. Other signals can be blocked or unblocked reliably.
Synopsis:
sigsuspend(signal_mask)
Returns "undef" on failure.
Beware that in a UTF-8 locale, anything you pass to this function must be in UTF-8; and when not in a UTF-8 locale, anything passed must not be UTF-8 encoded.
Note also that it doesn't make sense for a string to be encoded in one locale (say, ISO-8859-6, Arabic) and to collate it based on another (like ISO-8859-7, Greek). The results will be essentially meaningless.
Synopsis:
strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
The month ("mon"), weekday ("wday"), and yearday ("yday") begin at zero, i.e., January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The year ("year") is given in years since 1900, i.e., the year 1995 is 95; the year 2001 is 101. Consult your system's "strftime()" manpage for details about these and the other arguments.
If you want your code to be portable, your format ("fmt") argument should use only the conversion specifiers defined by the ANSI C standard (C89, to play safe). These are "aAbBcdHIjmMpSUwWxXyYZ%". But even then, the results of some of the conversion specifiers are non-portable. For example, the specifiers "aAbBcpZ" change according to the locale settings of the user, and both how to set locales (the locale names) and what output to expect are non-standard. The specifier "c" changes according to the timezone settings of the user and the timezone computation rules of the operating system. The "Z" specifier is notoriously unportable since the names of timezones are non-standard. Sticking to the numeric specifiers is the safest route.
The given arguments are made consistent as though by calling "mktime()" before calling your system's "strftime()" function, except that the "isdst" value is not affected.
The string for Tuesday, December 12, 1995.
$str = POSIX::strftime( "%A, %B %d, %Y", 0, 0, 0, 12, 11, 95, 2 ); print "$str\n";
"strtod" respects any POSIX "setlocale()" "LC_NUMERIC" settings, regardless of whether or not it is called from Perl code that is within the scope of "use locale". Prior to Perl 5.28, or when operating in a non thread-safe environment, it should not be used in a threaded application unless it's certain that the underlying locale is C or POSIX. This is because it otherwise changes the locale, which globally affects all threads simultaneously.
To parse a string $str as a floating point number use
$! = 0; ($num, $n_unparsed) = POSIX::strtod($str);
The second returned item and $! can be used to check for valid input:
if (($str eq '') || ($n_unparsed != 0) || $!) { die "Non-numeric input $str" . ($! ? ": $!\n" : "\n"); }
When called in a scalar context "strtod" returns the parsed number.
"strtol" should respect any POSIX setlocale() settings.
To parse a string $str as a number in some base $base use
$! = 0; ($num, $n_unparsed) = POSIX::strtol($str, $base);
The base should be zero or between 2 and 36, inclusive. When the base is zero or omitted "strtol" will use the string itself to determine the base: a leading "0x" or "0X" means hexadecimal; a leading "0" means octal; any other leading characters mean decimal. Thus, "1234" is parsed as a decimal number, "01234" as an octal number, and "0x1234" as a hexadecimal number.
The second returned item and $! can be used to check for valid input:
if (($str eq '') || ($n_unparsed != 0) || !$!) { die "Non-numeric input $str" . $! ? ": $!\n" : "\n"; }
When called in a scalar context "strtol" returns the parsed number.
Note: Some vendors supply "strtod()" and "strtol()" but not "strtoul()". Other vendors that do supply "strtoul()" parse "-1" as a valid value.
$dst = POSIX::strxfrm( $src );
Used with "eq" or "cmp" as an alternative to "strcoll".
Not really needed since Perl can do this transparently, see perllocale.
Beware that in a UTF-8 locale, anything you pass to this function must be in UTF-8; and when not in a UTF-8 locale, anything passed must not be UTF-8 encoded.
The following will get the machine's clock speed.
$clock_ticks = POSIX::sysconf( &POSIX::_SC_CLK_TCK );
Returns "undef" on failure.
Returns "undef" on failure.
Returns "undef" on failure.
Returns "undef" on failure.
Returns "undef" on failure.
Returns "undef" on failure.
See also "lgamma".
($realtime, $user, $system, $cuser, $csystem) = POSIX::times();
Note: Perl's builtin "times()" function returns four values, measured in seconds.
See also "ceil", "floor", and "round".
POSIX::tzset(); ($std, $dst) = POSIX::tzname();
($sysname, $nodename, $release, $version, $machine) = POSIX::uname();
Note that the actual meanings of the various fields are not that well standardized, do not expect any great portability. The $sysname might be the name of the operating system, the $nodename might be the name of the host, the $release might be the (major) release number of the operating system, the $version might be the (minor) release number of the operating system, and the $machine might be a hardware identifier. Maybe.
$pid = POSIX::waitpid( -1, POSIX::WNOHANG ); print "status = ", ($? / 256), "\n";
See "mblen".
Core Perl does not have any support for wide and multibyte locales, except Unicode UTF-8 locales. This function, in conjunction with "mblen" and "mbtowc" may be used to roll your own decoding/encoding of other types of multi-byte locales.
Use "undef" as the first parameter to this function to get the effect of passing NULL as the first parameter to "wctomb". This resets any shift state to its initial value. The return value is undefined if "wcrtomb" was substituted, so you should never rely on it.
When the first parameter is a scalar, the code point contained in the scalar second parameter is converted into a multi-byte string and stored into the first parameter scalar. This is based on the locale that currently underlies the program, regardless of whether or not the function is called from Perl code that is within the scope of "use locale". The return value is the number of bytes stored; or negative if the code point isn't representable in the current locale. Perl makes no attempt at hiding from your code any differences in the "errno" setting between "wctomb" and "wcrtomb". It does set "errno" to 0 before calling them.
$fd = POSIX::open( "foo", &POSIX::O_WRONLY ); $buf = "hello"; $bytes = POSIX::write( $fd, $buf, 5 );
Returns "undef" on failure.
See also "syswrite" in perlfunc.
$sigset = POSIX::SigSet->new(SIGINT, SIGQUIT); $sigaction = POSIX::SigAction->new( \&handler, $sigset, &POSIX::SA_NOCLDSTOP );
This "POSIX::SigAction" object is intended for use with the "POSIX::sigaction()" function.
$sigset = $sigaction->mask; $sigaction->flags(&POSIX::SA_RESTART);
$sigaction->safe(1);
You may also examine the "safe" flag on the output action object which is filled in when given as the third parameter to "POSIX::sigaction()":
sigaction(SIGINT, $new_action, $old_action); if ($old_action->safe) { # previous SIGINT handler used safe signals }
You can set the %POSIX::SIGRT elements to set the POSIX realtime signal handlers, use "delete" and "exists" on the elements, and use "scalar" on the %POSIX::SIGRT to find out how many POSIX realtime signals there are available "(SIGRTMAX - SIGRTMIN + 1", the "SIGRTMAX" is a valid POSIX realtime signal).
Setting the %SIGRT elements is equivalent to calling this:
sub new { my ($rtsig, $handler, $flags) = @_; my $sigset = POSIX::SigSet($rtsig); my $sigact = POSIX::SigAction->new($handler,$sigset,$flags); sigaction($rtsig, $sigact); }
The flags default to zero, if you want something different you can either use "local" on $POSIX::SigRt::SIGACTION_FLAGS, or you can derive from POSIX::SigRt and define your own "new()" (the tied hash STORE method of the %SIGRT calls "new($rtsig, $handler, $SIGACTION_FLAGS)", where the $rtsig ranges from zero to "SIGRTMAX - SIGRTMIN + 1)".
Just as with any signal, you can use "sigaction($rtsig, undef, $oa)" to retrieve the installed signal handler (or, rather, the signal action).
NOTE: whether POSIX realtime signals really work in your system, or whether Perl has been compiled so that it works with them, is outside of this discussion.
Create an empty set.
$sigset = POSIX::SigSet->new;
Create a set with "SIGUSR1".
$sigset = POSIX::SigSet->new( &POSIX::SIGUSR1 );
Throws an error if any of the signals supplied cannot be added to the set.
$sigset->addset( &POSIX::SIGUSR2 );
Returns "undef" on failure.
$sigset->delset( &POSIX::SIGUSR2 );
Returns "undef" on failure.
$sigset->emptyset();
Returns "undef" on failure.
$sigset->fillset();
Returns "undef" on failure.
if( $sigset->ismember( &POSIX::SIGUSR1 ) ){ print "contains SIGUSR1\n"; }
$termios = POSIX::Termios->new;
Obtain the attributes for "stdin".
$termios->getattr( 0 ) # Recommended for clarity. $termios->getattr()
Obtain the attributes for stdout.
$termios->getattr( 1 )
Returns "undef" on failure.
$c_cc[1] = $termios->getcc(1);
$c_cflag = $termios->getcflag;
$c_iflag = $termios->getiflag;
$ispeed = $termios->getispeed;
$c_lflag = $termios->getlflag;
$c_oflag = $termios->getoflag;
$ospeed = $termios->getospeed;
Set attributes immediately for stdout.
$termios->setattr( 1, &POSIX::TCSANOW );
Returns "undef" on failure.
$termios->setcc( &POSIX::VEOF, 1 );
$termios->setcflag( $c_cflag | &POSIX::CLOCAL );
$termios->setiflag( $c_iflag | &POSIX::BRKINT );
$termios->setispeed( &POSIX::B9600 );
Returns "undef" on failure.
$termios->setlflag( $c_lflag | &POSIX::ECHO );
$termios->setoflag( $c_oflag | &POSIX::OPOST );
$termios->setospeed( &POSIX::B9600 );
Returns "undef" on failure.
Imported with the ":sys_resource_h" tag.
"PRIO_PROCESS" "PRIO_PGRP" "PRIO_USER"
Added in Perl v5.22:
"FP_ILOGB0" "FP_ILOGBNAN" "FP_INFINITE" "FP_NAN" "FP_NORMAL" "FP_SUBNORMAL" "FP_ZERO" "INFINITY" "NAN" "Inf" "NaN" "M_1_PI" "M_2_PI" "M_2_SQRTPI" "M_E" "M_LN10" "M_LN2" "M_LOG10E" "M_LOG2E" "M_PI" "M_PI_2" "M_PI_4" "M_SQRT1_2" "M_SQRT2" on systems with C99 support.
Added in Perl v5.24:
"ILL_ILLOPC" "ILL_ILLOPN" "ILL_ILLADR" "ILL_ILLTRP" "ILL_PRVOPC" "ILL_PRVREG" "ILL_COPROC" "ILL_BADSTK" "FPE_INTDIV" "FPE_INTOVF" "FPE_FLTDIV" "FPE_FLTOVF" "FPE_FLTUND" "FPE_FLTRES" "FPE_FLTINV" "FPE_FLTSUB" "SEGV_MAPERR" "SEGV_ACCERR" "BUS_ADRALN" "BUS_ADRERR" "BUS_OBJERR" "TRAP_BRKPT" "TRAP_TRACE" "CLD_EXITED" "CLD_KILLED" "CLD_DUMPED" "CLD_TRAPPED" "CLD_STOPPED" "CLD_CONTINUED" "POLL_IN" "POLL_OUT" "POLL_MSG" "POLL_ERR" "POLL_PRI" "POLL_HUP" "SI_USER" "SI_QUEUE" "SI_TIMER" "SI_ASYNCIO" "SI_MESGQ"
(Windows only.)
"WSAEINTR" "WSAEBADF" "WSAEACCES" "WSAEFAULT" "WSAEINVAL" "WSAEMFILE" "WSAEWOULDBLOCK" "WSAEINPROGRESS" "WSAEALREADY" "WSAENOTSOCK" "WSAEDESTADDRREQ" "WSAEMSGSIZE" "WSAEPROTOTYPE" "WSAENOPROTOOPT" "WSAEPROTONOSUPPORT" "WSAESOCKTNOSUPPORT" "WSAEOPNOTSUPP" "WSAEPFNOSUPPORT" "WSAEAFNOSUPPORT" "WSAEADDRINUSE" "WSAEADDRNOTAVAIL" "WSAENETDOWN" "WSAENETUNREACH" "WSAENETRESET" "WSAECONNABORTED" "WSAECONNRESET" "WSAENOBUFS" "WSAEISCONN" "WSAENOTCONN" "WSAESHUTDOWN" "WSAETOOMANYREFS" "WSAETIMEDOUT" "WSAECONNREFUSED" "WSAELOOP" "WSAENAMETOOLONG" "WSAEHOSTDOWN" "WSAEHOSTUNREACH" "WSAENOTEMPTY" "WSAEPROCLIM" "WSAEUSERS" "WSAEDQUOT" "WSAESTALE" "WSAEREMOTE" "WSAEDISCON" "WSAENOMORE" "WSAECANCELLED" "WSAEINVALIDPROCTABLE" "WSAEINVALIDPROVIDER" "WSAEPROVIDERFAILEDINIT" "WSAEREFUSED"
2022-02-19 | perl v5.34.1 |