3 POSIX - Perl interface to IEEE Std 1003.1
9 use POSIX qw(:errno_h :fcntl_h);
11 printf "EINTR is %d\n", EINTR;
13 $sess_id = POSIX::setsid();
15 $fd = POSIX::open($path, O_CREAT|O_EXCL|O_WRONLY, 0644);
16 # note: that's a filedescriptor, *NOT* a filehandle
20 The POSIX module permits you to access all (or nearly all) the standard
21 POSIX 1003.1 identifiers. Many of these identifiers have been given Perl-ish
24 I<Everything is exported by default> with the exception of any POSIX
25 functions with the same name as a built-in Perl function, such as
26 C<abs>, C<alarm>, C<rmdir>, C<write>, etc.., which will be exported
27 only if you ask for them explicitly. This is an unfortunate backwards
28 compatibility feature. You can stop the exporting by saying S<C<use
29 POSIX ()>> and then use the fully qualified names (I<e.g.>, C<POSIX::SEEK_END>),
30 or by giving an explicit import list. If you do neither, and opt for the
31 default, S<C<use POSIX;>> has to import I<553 symbols>.
33 This document gives a condensed list of the features available in the POSIX
34 module. Consult your operating system's manpages for general information on
35 most features. Consult L<perlfunc> for functions which are noted as being
36 identical to Perl's builtin functions.
38 The first section describes POSIX functions from the 1003.1 specification.
39 The second section describes some classes for signal objects, TTY objects,
40 and other miscellaneous objects. The remaining sections list various
41 constants and macros in an organization which roughly follows IEEE Std
46 A few functions are not implemented because they are C specific. If you
47 attempt to call these, they will print a message telling you that they
48 aren't implemented, and suggest using the Perl equivalent, should one
49 exist. For example, trying to access the C<setjmp()> call will elicit the
50 message "C<setjmp() is C-specific: use eval {} instead>".
52 Furthermore, some evil vendors will claim 1003.1 compliance, but in fact
53 are not so: they will not pass the PCTS (POSIX Compliance Test Suites).
54 For example, one vendor may not define C<EDEADLK>, or the semantics of the
55 errno values set by C<open(2)> might not be quite right. Perl does not
56 attempt to verify POSIX compliance. That means you can currently
57 successfully say "use POSIX", and then later in your program you find
58 that your vendor has been lax and there's no usable C<ICANON> macro after
59 all. This could be construed to be a bug.
67 This is identical to the C function C<_exit()>. It exits the program
68 immediately which means among other things buffered I/O is B<not> flushed.
70 Note that when using threads and in Linux this is B<not> a good way to
71 exit a thread because in Linux processes and threads are kind of the
72 same thing (Note: while this is the situation in early 2003 there are
73 projects under way to have threads with more POSIXly semantics in Linux).
74 If you want not to return from a thread, detach the thread.
78 This is identical to the C function C<abort()>. It terminates the
79 process with a C<SIGABRT> signal unless caught by a signal handler or
80 if the handler does not return normally (it e.g. does a C<longjmp>).
84 This is identical to Perl's builtin C<abs()> function, returning
85 the absolute value of its numerical argument.
89 Determines the accessibility of a file.
91 if( POSIX::access( "/", &POSIX::R_OK ) ){
92 print "have read permission\n";
95 Returns C<undef> on failure. Note: do not use C<access()> for
96 security purposes. Between the C<access()> call and the operation
97 you are preparing for the permissions might change: a classic
102 This is identical to the C function C<acos()>, returning
103 the arcus cosine of its numerical argument. See also L<Math::Trig>.
107 This is identical to Perl's builtin C<alarm()> function,
108 either for arming or disarming the C<SIGARLM> timer.
112 This is identical to the C function C<asctime()>. It returns
115 "Fri Jun 2 18:22:13 2000\n\0"
117 and it is called thusly
119 $asctime = asctime($sec, $min, $hour, $mday, $mon,
120 $year, $wday, $yday, $isdst);
122 The C<$mon> is zero-based: January equals C<0>. The C<$year> is
123 1900-based: 2001 equals C<101>. C<$wday> and C<$yday> default to zero
124 (and are usually ignored anyway), and C<$isdst> defaults to -1.
128 This is identical to the C function C<asin()>, returning
129 the arcus sine of its numerical argument. See also L<Math::Trig>.
133 Unimplemented, but you can use L<perlfunc/die> and the L<Carp> module
134 to achieve similar things.
138 This is identical to the C function C<atan()>, returning the
139 arcus tangent of its numerical argument. See also L<Math::Trig>.
143 This is identical to Perl's builtin C<atan2()> function, returning
144 the arcus tangent defined by its two numerical arguments, the I<y>
145 coordinate and the I<x> coordinate. See also L<Math::Trig>.
149 C<atexit()> is C-specific: use C<END {}> instead, see L<perlsub>.
153 C<atof()> is C-specific. Perl converts strings to numbers transparently.
154 If you need to force a scalar to a number, add a zero to it.
158 C<atoi()> is C-specific. Perl converts strings to numbers transparently.
159 If you need to force a scalar to a number, add a zero to it.
160 If you need to have just the integer part, see L<perlfunc/int>.
164 C<atol()> is C-specific. Perl converts strings to numbers transparently.
165 If you need to force a scalar to a number, add a zero to it.
166 If you need to have just the integer part, see L<perlfunc/int>.
170 C<bsearch()> not supplied. For doing binary search on wordlists,
175 C<calloc()> is C-specific. Perl does memory management transparently.
179 This is identical to the C function C<ceil()>, returning the smallest
180 integer value greater than or equal to the given numerical argument.
184 This is identical to Perl's builtin C<chdir()> function, allowing
185 one to change the working (default) directory, see L<perlfunc/chdir>.
189 This is identical to Perl's builtin C<chmod()> function, allowing
190 one to change file and directory permissions, see L<perlfunc/chmod>.
194 This is identical to Perl's builtin C<chown()> function, allowing one
195 to change file and directory owners and groups, see L<perlfunc/chown>.
199 Use the method C<IO::Handle::clearerr()> instead, to reset the error
200 state (if any) and EOF state (if any) of the given stream.
204 This is identical to the C function C<clock()>, returning the
205 amount of spent processor time in microseconds.
209 Close the file. This uses file descriptors such as those obtained by calling
212 $fd = POSIX::open( "foo", &POSIX::O_RDONLY );
215 Returns C<undef> on failure.
217 See also L<perlfunc/close>.
221 This is identical to Perl's builtin C<closedir()> function for closing
222 a directory handle, see L<perlfunc/closedir>.
226 This is identical to Perl's builtin C<cos()> function, for returning
227 the cosine of its numerical argument, see L<perlfunc/cos>.
228 See also L<Math::Trig>.
232 This is identical to the C function C<cosh()>, for returning
233 the hyperbolic cosine of its numeric argument. See also L<Math::Trig>.
237 Create a new file. This returns a file descriptor like the ones returned by
238 C<POSIX::open>. Use C<POSIX::close> to close the file.
240 $fd = POSIX::creat( "foo", 0611 );
243 See also L<perlfunc/sysopen> and its C<O_CREAT> flag.
247 Generates the path name for the controlling terminal.
249 $path = POSIX::ctermid();
253 This is identical to the C function C<ctime()> and equivalent
254 to C<asctime(localtime(...))>, see L</asctime> and L</localtime>.
258 Get the login name of the owner of the current process.
260 $name = POSIX::cuserid();
264 This is identical to the C function C<difftime()>, for returning
265 the time difference (in seconds) between two times (as returned
266 by C<time()>), see L</time>.
270 C<div()> is C-specific, use L<perlfunc/int> on the usual C</> division and
275 This is similar to the C function C<dup()>, for duplicating a file
278 This uses file descriptors such as those obtained by calling
281 Returns C<undef> on failure.
285 This is similar to the C function C<dup2()>, for duplicating a file
286 descriptor to an another known file descriptor.
288 This uses file descriptors such as those obtained by calling
291 Returns C<undef> on failure.
295 Returns the value of errno.
297 $errno = POSIX::errno();
299 This identical to the numerical values of the C<$!>, see L<perlvar/$ERRNO>.
303 C<execl()> is C-specific, see L<perlfunc/exec>.
307 C<execle()> is C-specific, see L<perlfunc/exec>.
311 C<execlp()> is C-specific, see L<perlfunc/exec>.
315 C<execv()> is C-specific, see L<perlfunc/exec>.
319 C<execve()> is C-specific, see L<perlfunc/exec>.
323 C<execvp()> is C-specific, see L<perlfunc/exec>.
327 This is identical to Perl's builtin C<exit()> function for exiting the
328 program, see L<perlfunc/exit>.
332 This is identical to Perl's builtin C<exp()> function for
333 returning the exponent (I<e>-based) of the numerical argument,
338 This is identical to Perl's builtin C<abs()> function for returning
339 the absolute value of the numerical argument, see L<perlfunc/abs>.
343 Use method C<IO::Handle::close()> instead, or see L<perlfunc/close>.
347 This is identical to Perl's builtin C<fcntl()> function,
348 see L<perlfunc/fcntl>.
352 Use method C<IO::Handle::new_from_fd()> instead, or see L<perlfunc/open>.
356 Use method C<IO::Handle::eof()> instead, or see L<perlfunc/eof>.
360 Use method C<IO::Handle::error()> instead.
364 Use method C<IO::Handle::flush()> instead.
365 See also C<L<perlvar/$OUTPUT_AUTOFLUSH>>.
369 Use method C<IO::Handle::getc()> instead, or see L<perlfunc/read>.
373 Use method C<IO::Seekable::getpos()> instead, or see L<perlfunc/seek>.
377 Use method C<IO::Handle::gets()> instead. Similar to E<lt>E<gt>, also known
378 as L<perlfunc/readline>.
382 Use method C<IO::Handle::fileno()> instead, or see L<perlfunc/fileno>.
386 This is identical to the C function C<floor()>, returning the largest
387 integer value less than or equal to the numerical argument.
391 This is identical to the C function C<fmod()>.
395 It returns the remainder C<$r = $x - $n*$y>, where C<$n = trunc($x/$y)>.
396 The C<$r> has the same sign as C<$x> and magnitude (absolute value)
397 less than the magnitude of C<$y>.
401 Use method C<IO::File::open()> instead, or see L<perlfunc/open>.
405 This is identical to Perl's builtin C<fork()> function
406 for duplicating the current process, see L<perlfunc/fork>
407 and L<perlfork> if you are in Windows.
411 Retrieves the value of a configurable limit on a file or directory. This
412 uses file descriptors such as those obtained by calling C<POSIX::open>.
414 The following will determine the maximum length of the longest allowable
415 pathname on the filesystem which holds F</var/foo>.
417 $fd = POSIX::open( "/var/foo", &POSIX::O_RDONLY );
418 $path_max = POSIX::fpathconf($fd, &POSIX::_PC_PATH_MAX);
420 Returns C<undef> on failure.
424 C<fprintf()> is C-specific, see L<perlfunc/printf> instead.
428 C<fputc()> is C-specific, see L<perlfunc/print> instead.
432 C<fputs()> is C-specific, see L<perlfunc/print> instead.
436 C<fread()> is C-specific, see L<perlfunc/read> instead.
440 C<free()> is C-specific. Perl does memory management transparently.
444 C<freopen()> is C-specific, see L<perlfunc/open> instead.
448 Return the mantissa and exponent of a floating-point number.
450 ($mantissa, $exponent) = POSIX::frexp( 1.234e56 );
454 C<fscanf()> is C-specific, use E<lt>E<gt> and regular expressions instead.
458 Use method C<IO::Seekable::seek()> instead, or see L<perlfunc/seek>.
462 Use method C<IO::Seekable::setpos()> instead, or seek L<perlfunc/seek>.
466 Get file status. This uses file descriptors such as those obtained by
467 calling C<POSIX::open>. The data returned is identical to the data from
468 Perl's builtin C<stat> function.
470 $fd = POSIX::open( "foo", &POSIX::O_RDONLY );
471 @stats = POSIX::fstat( $fd );
475 Use method C<IO::Handle::sync()> instead.
479 Use method C<IO::Seekable::tell()> instead, or see L<perlfunc/tell>.
483 C<fwrite()> is C-specific, see L<perlfunc/print> instead.
487 This is identical to Perl's builtin C<getc()> function,
488 see L<perlfunc/getc>.
492 Returns one character from STDIN. Identical to Perl's C<getc()>,
493 see L<perlfunc/getc>.
497 Returns the name of the current working directory.
502 Returns the effective group identifier. Similar to Perl' s builtin
503 variable C<$(>, see L<perlvar/$EGID>.
507 Returns the value of the specified environment variable.
508 The same information is available through the C<%ENV> array.
512 Returns the effective user identifier. Identical to Perl's builtin C<$E<gt>>
513 variable, see L<perlvar/$EUID>.
517 Returns the user's real group identifier. Similar to Perl's builtin
518 variable C<$)>, see L<perlvar/$GID>.
522 This is identical to Perl's builtin C<getgrgid()> function for
523 returning group entries by group identifiers, see
524 L<perlfunc/getgrgid>.
528 This is identical to Perl's builtin C<getgrnam()> function for
529 returning group entries by group names, see L<perlfunc/getgrnam>.
533 Returns the ids of the user's supplementary groups. Similar to Perl's
534 builtin variable C<$)>, see L<perlvar/$GID>.
538 This is identical to Perl's builtin C<getlogin()> function for
539 returning the user name associated with the current session, see
540 L<perlfunc/getlogin>.
544 This is identical to Perl's builtin C<getpgrp()> function for
545 returning the process group identifier of the current process, see
550 Returns the process identifier. Identical to Perl's builtin
551 variable C<$$>, see L<perlvar/$PID>.
555 This is identical to Perl's builtin C<getppid()> function for
556 returning the process identifier of the parent process of the current
557 process , see L<perlfunc/getppid>.
561 This is identical to Perl's builtin C<getpwnam()> function for
562 returning user entries by user names, see L<perlfunc/getpwnam>.
566 This is identical to Perl's builtin C<getpwuid()> function for
567 returning user entries by user identifiers, see L<perlfunc/getpwuid>.
571 Returns one line from C<STDIN>, similar to E<lt>E<gt>, also known
572 as the C<readline()> function, see L<perlfunc/readline>.
574 B<NOTE>: if you have C programs that still use C<gets()>, be very
575 afraid. The C<gets()> function is a source of endless grief because
576 it has no buffer overrun checks. It should B<never> be used. The
577 C<fgets()> function should be preferred instead.
581 Returns the user's identifier. Identical to Perl's builtin C<$E<lt>> variable,
586 This is identical to Perl's builtin C<gmtime()> function for
587 converting seconds since the epoch to a date in Greenwich Mean Time,
588 see L<perlfunc/gmtime>.
592 Deprecated function whose use raises a warning, and which is slated to
593 be removed in a future Perl version. It is very similar to matching
594 against S<C<qr/ ^ [[:alnum:]]+ $ /x>>, which you should convert to use
595 instead. The function is deprecated because 1) it doesn't handle UTF-8
596 encoded strings properly; and 2) it returns C<TRUE> even if the input is
597 the empty string. The function return is always based on the current
598 locale, whereas using locale rules is optional with the regular
599 expression, based on pragmas in effect and pattern modifiers (see
600 L<perlre/Character set modifiers> and L<perlre/Which character set
601 modifier is in effect?>).
603 The function returns C<TRUE> if the input string is empty, or if the
604 corresponding C function returns C<TRUE> for every byte in the string.
606 You may want to use the C<L<E<sol>\wE<sol>|perlrecharclass/Word
607 characters>> construct instead.
611 Deprecated function whose use raises a warning, and which is slated to
612 be removed in a future Perl version. It is very similar to matching
613 against S<C<qr/ ^ [[:alpha:]]+ $ /x>>, which you should convert to use
614 instead. The function is deprecated because 1) it doesn't handle UTF-8
615 encoded strings properly; and 2) it returns C<TRUE> even if the input is
616 the empty string. The function return is always based on the current
617 locale, whereas using locale rules is optional with the regular
618 expression, based on pragmas in effect and pattern modifiers (see
619 L<perlre/Character set modifiers> and L<perlre/Which character set
620 modifier is in effect?>).
622 The function returns C<TRUE> if the input string is empty, or if the
623 corresponding C function returns C<TRUE> for every byte in the string.
627 Returns a boolean indicating whether the specified filehandle is connected
628 to a tty. Similar to the C<-t> operator, see L<perlfunc/-X>.
632 Deprecated function whose use raises a warning, and which is slated to
633 be removed in a future Perl version. It is very similar to matching
634 against S<C<qr/ ^ [[:cntrl:]]+ $ /x>>, which you should convert to use
635 instead. The function is deprecated because 1) it doesn't handle UTF-8
636 encoded strings properly; and 2) it returns C<TRUE> even if the input is
637 the empty string. The function return is always based on the current
638 locale, whereas using locale rules is optional with the regular
639 expression, based on pragmas in effect and pattern modifiers (see
640 L<perlre/Character set modifiers> and L<perlre/Which character set
641 modifier is in effect?>).
643 The function returns C<TRUE> if the input string is empty, or if the
644 corresponding C function returns C<TRUE> for every byte in the string.
648 Deprecated function whose use raises a warning, and which is slated to
649 be removed in a future Perl version. It is very similar to matching
650 against S<C<qr/ ^ [[:digit:]]+ $ /x>>, which you should convert to use
651 instead. The function is deprecated because 1) it doesn't handle UTF-8
652 encoded strings properly; and 2) it returns C<TRUE> even if the input is
653 the empty string. The function return is always based on the current
654 locale, whereas using locale rules is optional with the regular
655 expression, based on pragmas in effect and pattern modifiers (see
656 L<perlre/Character set modifiers> and L<perlre/Which character set
657 modifier is in effect?>).
659 The function returns C<TRUE> if the input string is empty, or if the
660 corresponding C function returns C<TRUE> for every byte in the string.
662 You may want to use the C<L<E<sol>\dE<sol>|perlrecharclass/Digits>>
667 Deprecated function whose use raises a warning, and which is slated to
668 be removed in a future Perl version. It is very similar to matching
669 against S<C<qr/ ^ [[:graph:]]+ $ /x>>, which you should convert to use
670 instead. The function is deprecated because 1) it doesn't handle UTF-8
671 encoded strings properly; and 2) it returns C<TRUE> even if the input is
672 the empty string. The function return is always based on the current
673 locale, whereas using locale rules is optional with the regular
674 expression, based on pragmas in effect and pattern modifiers (see
675 L<perlre/Character set modifiers> and L<perlre/Which character set
676 modifier is in effect?>).
678 The function returns C<TRUE> if the input string is empty, or if the
679 corresponding C function returns C<TRUE> for every byte in the string.
683 Deprecated function whose use raises a warning, and which is slated to
684 be removed in a future Perl version. It is very similar to matching
685 against S<C<qr/ ^ [[:lower:]]+ $ /x>>, which you should convert to use
686 instead. The function is deprecated because 1) it doesn't handle UTF-8
687 encoded strings properly; and 2) it returns C<TRUE> even if the input is
688 the empty string. The function return is always based on the current
689 locale, whereas using locale rules is optional with the regular
690 expression, based on pragmas in effect and pattern modifiers (see
691 L<perlre/Character set modifiers> and L<perlre/Which character set
692 modifier is in effect?>).
694 The function returns C<TRUE> if the input string is empty, or if the
695 corresponding C function returns C<TRUE> for every byte in the string.
697 Do B<not> use C</[a-z]/> unless you don't care about the current locale.
701 Deprecated function whose use raises a warning, and which is slated to
702 be removed in a future Perl version. It is very similar to matching
703 against S<C<qr/ ^ [[:print:]]+ $ /x>>, which you should convert to use
704 instead. The function is deprecated because 1) it doesn't handle UTF-8
705 encoded strings properly; and 2) it returns C<TRUE> even if the input is
706 the empty string. The function return is always based on the current
707 locale, whereas using locale rules is optional with the regular
708 expression, based on pragmas in effect and pattern modifiers (see
709 L<perlre/Character set modifiers> and L<perlre/Which character set
710 modifier is in effect?>).
712 The function returns C<TRUE> if the input string is empty, or if the
713 corresponding C function returns C<TRUE> for every byte in the string.
717 Deprecated function whose use raises a warning, and which is slated to
718 be removed in a future Perl version. It is very similar to matching
719 against S<C<qr/ ^ [[:punct:]]+ $ /x>>, which you should convert to use
720 instead. The function is deprecated because 1) it doesn't handle UTF-8
721 encoded strings properly; and 2) it returns C<TRUE> even if the input is
722 the empty string. The function return is always based on the current
723 locale, whereas using locale rules is optional with the regular
724 expression, based on pragmas in effect and pattern modifiers (see
725 L<perlre/Character set modifiers> and L<perlre/Which character set
726 modifier is in effect?>).
728 The function returns C<TRUE> if the input string is empty, or if the
729 corresponding C function returns C<TRUE> for every byte in the string.
733 Deprecated function whose use raises a warning, and which is slated to
734 be removed in a future Perl version. It is very similar to matching
735 against S<C<qr/ ^ [[:space:]]+ $ /x>>, which you should convert to use
736 instead. The function is deprecated because 1) it doesn't handle UTF-8
737 encoded strings properly; and 2) it returns C<TRUE> even if the input is
738 the empty string. The function return is always based on the current
739 locale, whereas using locale rules is optional with the regular
740 expression, based on pragmas in effect and pattern modifiers (see
741 L<perlre/Character set modifiers> and L<perlre/Which character set
742 modifier is in effect?>).
744 The function returns C<TRUE> if the input string is empty, or if the
745 corresponding C function returns C<TRUE> for every byte in the string.
747 You may want to use the C<L<E<sol>\sE<sol>|perlrecharclass/Whitespace>>
752 Deprecated function whose use raises a warning, and which is slated to
753 be removed in a future Perl version. It is very similar to matching
754 against S<C<qr/ ^ [[:upper:]]+ $ /x>>, which you should convert to use
755 instead. The function is deprecated because 1) it doesn't handle UTF-8
756 encoded strings properly; and 2) it returns C<TRUE> even if the input is
757 the empty string. The function return is always based on the current
758 locale, whereas using locale rules is optional with the regular
759 expression, based on pragmas in effect and pattern modifiers (see
760 L<perlre/Character set modifiers> and L<perlre/Which character set
761 modifier is in effect?>).
763 The function returns C<TRUE> if the input string is empty, or if the
764 corresponding C function returns C<TRUE> for every byte in the string.
766 Do B<not> use C</[A-Z]/> unless you don't care about the current locale.
770 Deprecated function whose use raises a warning, and which is slated to
771 be removed in a future Perl version. It is very similar to matching
772 against S<C<qr/ ^ [[:xdigit:]]+ $ /x>>, which you should convert to use
773 instead. The function is deprecated because 1) it doesn't handle UTF-8
774 encoded strings properly; and 2) it returns C<TRUE> even if the input is
775 the empty string. The function return is always based on the current
776 locale, whereas using locale rules is optional with the regular
777 expression, based on pragmas in effect and pattern modifiers (see
778 L<perlre/Character set modifiers> and L<perlre/Which character set
779 modifier is in effect?>).
781 The function returns C<TRUE> if the input string is empty, or if the
782 corresponding C function returns C<TRUE> for every byte in the string.
786 This is identical to Perl's builtin C<kill()> function for sending
787 signals to processes (often to terminate them), see L<perlfunc/kill>.
791 (For returning absolute values of long integers.)
792 C<labs()> is C-specific, see L<perlfunc/abs> instead.
796 This is identical to the C function, except the order of arguments is
797 consistent with Perl's builtin C<chown()> with the added restriction
798 of only one path, not an list of paths. Does the same thing as the
799 C<chown()> function but changes the owner of a symbolic link instead
800 of the file the symbolic link points to.
804 This is identical to the C function C<ldexp()>
805 for multiplying floating point numbers with powers of two.
807 $x_quadrupled = POSIX::ldexp($x, 2);
811 (For computing dividends of long integers.)
812 C<ldiv()> is C-specific, use C</> and C<int()> instead.
816 This is identical to Perl's builtin C<link()> function
817 for creating hard links into files, see L<perlfunc/link>.
821 Get numeric formatting information. Returns a reference to a hash
822 containing the current underlying locale's formatting values. Users of this function
823 should also read L<perllocale>, which provides a comprehensive
824 discussion of Perl locale handling, including
825 L<a section devoted to this function|perllocale/The localeconv function>.
827 Here is how to query the database for the B<de> (Deutsch or German) locale.
829 my $loc = POSIX::setlocale( &POSIX::LC_ALL, "de" );
830 print "Locale: \"$loc\"\n";
831 my $lconv = POSIX::localeconv();
832 foreach my $property (qw(
853 printf qq(%s: "%s",\n),
854 $property, $lconv->{$property};
859 This is identical to Perl's builtin C<localtime()> function for
860 converting seconds since the epoch to a date see L<perlfunc/localtime>.
864 This is identical to Perl's builtin C<log()> function,
865 returning the natural (I<e>-based) logarithm of the numerical argument,
870 This is identical to the C function C<log10()>,
871 returning the 10-base logarithm of the numerical argument.
874 sub log10 { log($_[0]) / log(10) }
878 sub log10 { log($_[0]) / 2.30258509299405 }
882 sub log10 { log($_[0]) * 0.434294481903252 }
886 C<longjmp()> is C-specific: use L<perlfunc/die> instead.
890 Move the file's read/write position. This uses file descriptors such as
891 those obtained by calling C<POSIX::open>.
893 $fd = POSIX::open( "foo", &POSIX::O_RDONLY );
894 $off_t = POSIX::lseek( $fd, 0, &POSIX::SEEK_SET );
896 Returns C<undef> on failure.
900 C<malloc()> is C-specific. Perl does memory management transparently.
904 This is identical to the C function C<mblen()>.
905 Perl does not have any support for the wide and multibyte
906 characters of the C standards, so this might be a rather
911 This is identical to the C function C<mbstowcs()>.
912 Perl does not have any support for the wide and multibyte
913 characters of the C standards, so this might be a rather
918 This is identical to the C function C<mbtowc()>.
919 Perl does not have any support for the wide and multibyte
920 characters of the C standards, so this might be a rather
925 C<memchr()> is C-specific, see L<perlfunc/index> instead.
929 C<memcmp()> is C-specific, use C<eq> instead, see L<perlop>.
933 C<memcpy()> is C-specific, use C<=>, see L<perlop>, or see L<perlfunc/substr>.
937 C<memmove()> is C-specific, use C<=>, see L<perlop>, or see L<perlfunc/substr>.
941 C<memset()> is C-specific, use C<x> instead, see L<perlop>.
945 This is identical to Perl's builtin C<mkdir()> function
946 for creating directories, see L<perlfunc/mkdir>.
950 This is similar to the C function C<mkfifo()> for creating
953 if (mkfifo($path, $mode)) { ....
955 Returns C<undef> on failure. The C<$mode> is similar to the
956 mode of C<mkdir()>, see L<perlfunc/mkdir>, though for C<mkfifo>
957 you B<must> specify the C<$mode>.
961 Convert date/time info to a calendar time.
965 mktime(sec, min, hour, mday, mon, year, wday = 0,
966 yday = 0, isdst = -1)
968 The month (C<mon>), weekday (C<wday>), and yearday (C<yday>) begin at zero.
969 I.e. January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The
970 year (C<year>) is given in years since 1900. I.e. The year 1995 is 95; the
971 year 2001 is 101. Consult your system's C<mktime()> manpage for details
972 about these and the other arguments.
974 Calendar time for December 12, 1995, at 10:30 am.
976 $time_t = POSIX::mktime( 0, 30, 10, 12, 11, 95 );
977 print "Date = ", POSIX::ctime($time_t);
979 Returns C<undef> on failure.
983 Return the integral and fractional parts of a floating-point number.
985 ($fractional, $integral) = POSIX::modf( 3.14 );
989 This is similar to the C function C<nice()>, for changing
990 the scheduling preference of the current process. Positive
991 arguments mean more polite process, negative values more
992 needy process. Normal user processes can only be more polite.
994 Returns C<undef> on failure.
998 C<offsetof()> is C-specific, you probably want to see L<perlfunc/pack> instead.
1002 Open a file for reading for writing. This returns file descriptors, not
1003 Perl filehandles. Use C<POSIX::close> to close the file.
1005 Open a file read-only with mode 0666.
1007 $fd = POSIX::open( "foo" );
1009 Open a file for read and write.
1011 $fd = POSIX::open( "foo", &POSIX::O_RDWR );
1013 Open a file for write, with truncation.
1016 "foo", &POSIX::O_WRONLY | &POSIX::O_TRUNC
1019 Create a new file with mode 0640. Set up the file for writing.
1022 "foo", &POSIX::O_CREAT | &POSIX::O_WRONLY, 0640
1025 Returns C<undef> on failure.
1027 See also L<perlfunc/sysopen>.
1031 Open a directory for reading.
1033 $dir = POSIX::opendir( "/var" );
1034 @files = POSIX::readdir( $dir );
1035 POSIX::closedir( $dir );
1037 Returns C<undef> on failure.
1041 Retrieves the value of a configurable limit on a file or directory.
1043 The following will determine the maximum length of the longest allowable
1044 pathname on the filesystem which holds C</var>.
1046 $path_max = POSIX::pathconf( "/var",
1047 &POSIX::_PC_PATH_MAX );
1049 Returns C<undef> on failure.
1053 This is similar to the C function C<pause()>, which suspends
1054 the execution of the current process until a signal is received.
1056 Returns C<undef> on failure.
1060 This is identical to the C function C<perror()>, which outputs to the
1061 standard error stream the specified message followed by C<": "> and the
1062 current error string. Use the C<warn()> function and the C<$!>
1063 variable instead, see L<perlfunc/warn> and L<perlvar/$ERRNO>.
1067 Create an interprocess channel. This returns file descriptors like those
1068 returned by C<POSIX::open>.
1070 my ($read, $write) = POSIX::pipe();
1071 POSIX::write( $write, "hello", 5 );
1072 POSIX::read( $read, $buf, 5 );
1074 See also L<perlfunc/pipe>.
1078 Computes C<$x> raised to the power C<$exponent>.
1080 $ret = POSIX::pow( $x, $exponent );
1082 You can also use the C<**> operator, see L<perlop>.
1086 Formats and prints the specified arguments to STDOUT.
1087 See also L<perlfunc/printf>.
1091 C<putc()> is C-specific, see L<perlfunc/print> instead.
1095 C<putchar()> is C-specific, see L<perlfunc/print> instead.
1099 C<puts()> is C-specific, see L<perlfunc/print> instead.
1103 C<qsort()> is C-specific, see L<perlfunc/sort> instead.
1107 Sends the specified signal to the current process.
1108 See also L<perlfunc/kill> and the C<$$> in L<perlvar/$PID>.
1112 C<rand()> is non-portable, see L<perlfunc/rand> instead.
1116 Read from a file. This uses file descriptors such as those obtained by
1117 calling C<POSIX::open>. If the buffer C<$buf> is not large enough for the
1118 read then Perl will extend it to make room for the request.
1120 $fd = POSIX::open( "foo", &POSIX::O_RDONLY );
1121 $bytes = POSIX::read( $fd, $buf, 3 );
1123 Returns C<undef> on failure.
1125 See also L<perlfunc/sysread>.
1129 This is identical to Perl's builtin C<readdir()> function
1130 for reading directory entries, see L<perlfunc/readdir>.
1134 C<realloc()> is C-specific. Perl does memory management transparently.
1138 This is identical to Perl's builtin C<unlink()> function
1139 for removing files, see L<perlfunc/unlink>.
1143 This is identical to Perl's builtin C<rename()> function
1144 for renaming files, see L<perlfunc/rename>.
1148 Seeks to the beginning of the file.
1152 This is identical to Perl's builtin C<rewinddir()> function for
1153 rewinding directory entry streams, see L<perlfunc/rewinddir>.
1157 This is identical to Perl's builtin C<rmdir()> function
1158 for removing (empty) directories, see L<perlfunc/rmdir>.
1162 C<scanf()> is C-specific, use E<lt>E<gt> and regular expressions instead,
1167 Sets the real group identifier and the effective group identifier for
1168 this process. Similar to assigning a value to the Perl's builtin
1169 C<$)> variable, see L<perlvar/$EGID>, except that the latter
1170 will change only the real user identifier, and that the setgid()
1171 uses only a single numeric argument, as opposed to a space-separated
1176 C<setjmp()> is C-specific: use C<eval {}> instead,
1177 see L<perlfunc/eval>.
1181 Modifies and queries the program's underlying locale. Users of this
1182 function should read L<perllocale>, whch provides a comprehensive
1183 discussion of Perl locale handling, knowledge of which is necessary to
1184 properly use this function. It contains
1185 L<a section devoted to this function|perllocale/The setlocale function>.
1186 The discussion here is merely a summary reference for C<setlocale()>.
1187 Note that Perl itself is almost entirely unaffected by the locale
1188 except within the scope of S<C<"use locale">>. (Exceptions are listed
1189 in L<perllocale/Not within the scope of any "use locale" variant>.)
1191 The following examples assume
1193 use POSIX qw(setlocale LC_ALL LC_CTYPE);
1197 The following will set the traditional UNIX system locale behavior
1198 (the second argument C<"C">).
1200 $loc = setlocale( LC_ALL, "C" );
1202 The following will query the current C<LC_CTYPE> category. (No second
1203 argument means 'query'.)
1205 $loc = setlocale( LC_CTYPE );
1207 The following will set the C<LC_CTYPE> behaviour according to the locale
1208 environment variables (the second argument C<"">).
1209 Please see your system's C<setlocale(3)> documentation for the locale
1210 environment variables' meaning or consult L<perllocale>.
1212 $loc = setlocale( LC_CTYPE, "" );
1214 The following will set the C<LC_COLLATE> behaviour to Argentinian
1215 Spanish. B<NOTE>: The naming and availability of locales depends on
1216 your operating system. Please consult L<perllocale> for how to find
1217 out which locales are available in your system.
1219 $loc = setlocale( LC_COLLATE, "es_AR.ISO8859-1" );
1223 This is similar to the C function C<setpgid()> for
1224 setting the process group identifier of the current process.
1226 Returns C<undef> on failure.
1230 This is identical to the C function C<setsid()> for
1231 setting the session identifier of the current process.
1235 Sets the real user identifier and the effective user identifier for
1236 this process. Similar to assigning a value to the Perl's builtin
1237 C<$E<lt>> variable, see L<perlvar/$UID>, except that the latter
1238 will change only the real user identifier.
1242 Detailed signal management. This uses C<POSIX::SigAction> objects for
1243 the C<action> and C<oldaction> arguments (the oldaction can also be
1244 just a hash reference). Consult your system's C<sigaction> manpage
1245 for details, see also C<POSIX::SigRt>.
1249 sigaction(signal, action, oldaction = 0)
1251 Returns C<undef> on failure. The C<signal> must be a number (like
1252 C<SIGHUP>), not a string (like C<"SIGHUP">), though Perl does try hard
1255 If you use the C<SA_SIGINFO> flag, the signal handler will in addition to
1256 the first argument, the signal name, also receive a second argument, a
1257 hash reference, inside which are the following keys with the following
1258 semantics, as defined by POSIX/SUSv3:
1260 signo the signal number
1261 errno the error number
1262 code if this is zero or less, the signal was sent by
1263 a user process and the uid and pid make sense,
1264 otherwise the signal was sent by the kernel
1266 The following are also defined by POSIX/SUSv3, but unfortunately
1267 not very widely implemented:
1269 pid the process id generating the signal
1270 uid the uid of the process id generating the signal
1271 status exit value or signal for SIGCHLD
1272 band band event for SIGPOLL
1274 A third argument is also passed to the handler, which contains a copy
1275 of the raw binary contents of the C<siginfo> structure: if a system has
1276 some non-POSIX fields, this third argument is where to C<unpack()> them
1279 Note that not all C<siginfo> values make sense simultaneously (some are
1280 valid only for certain signals, for example), and not all values make
1281 sense from Perl perspective, you should to consult your system's
1282 C<sigaction> and possibly also C<siginfo> documentation.
1286 C<siglongjmp()> is C-specific: use L<perlfunc/die> instead.
1290 Examine signals that are blocked and pending. This uses C<POSIX::SigSet>
1291 objects for the C<sigset> argument. Consult your system's C<sigpending>
1292 manpage for details.
1298 Returns C<undef> on failure.
1300 =item C<sigprocmask>
1302 Change and/or examine calling process's signal mask. This uses
1303 C<POSIX::SigSet> objects for the C<sigset> and C<oldsigset> arguments.
1304 Consult your system's C<sigprocmask> manpage for details.
1308 sigprocmask(how, sigset, oldsigset = 0)
1310 Returns C<undef> on failure.
1312 Note that you can't reliably block or unblock a signal from its own signal
1313 handler if you're using safe signals. Other signals can be blocked or unblocked
1318 C<sigsetjmp()> is C-specific: use C<eval {}> instead,
1319 see L<perlfunc/eval>.
1323 Install a signal mask and suspend process until signal arrives. This uses
1324 C<POSIX::SigSet> objects for the C<signal_mask> argument. Consult your
1325 system's C<sigsuspend> manpage for details.
1329 sigsuspend(signal_mask)
1331 Returns C<undef> on failure.
1335 This is identical to Perl's builtin C<sin()> function
1336 for returning the sine of the numerical argument,
1337 see L<perlfunc/sin>. See also L<Math::Trig>.
1341 This is identical to the C function C<sinh()>
1342 for returning the hyperbolic sine of the numerical argument.
1343 See also L<Math::Trig>.
1347 This is functionally identical to Perl's builtin C<sleep()> function
1348 for suspending the execution of the current for process for certain
1349 number of seconds, see L<perlfunc/sleep>. There is one significant
1350 difference, however: C<POSIX::sleep()> returns the number of
1351 B<unslept> seconds, while the C<CORE::sleep()> returns the
1352 number of slept seconds.
1356 This is similar to Perl's builtin C<sprintf()> function
1357 for returning a string that has the arguments formatted as requested,
1358 see L<perlfunc/sprintf>.
1362 This is identical to Perl's builtin C<sqrt()> function.
1363 for returning the square root of the numerical argument,
1364 see L<perlfunc/sqrt>.
1368 Give a seed the pseudorandom number generator, see L<perlfunc/srand>.
1372 C<sscanf()> is C-specific, use regular expressions instead,
1377 This is identical to Perl's builtin C<stat()> function
1378 for returning information about files and directories.
1382 C<strcat()> is C-specific, use C<.=> instead, see L<perlop>.
1386 C<strchr()> is C-specific, see L<perlfunc/index> instead.
1390 C<strcmp()> is C-specific, use C<eq> or C<cmp> instead, see L<perlop>.
1394 This is identical to the C function C<strcoll()>
1395 for collating (comparing) strings transformed using
1396 the C<strxfrm()> function. Not really needed since
1397 Perl can do this transparently, see L<perllocale>.
1401 C<strcpy()> is C-specific, use C<=> instead, see L<perlop>.
1405 C<strcspn()> is C-specific, use regular expressions instead,
1410 Returns the error string for the specified errno.
1411 Identical to the string form of the C<$!>, see L<perlvar/$ERRNO>.
1415 Convert date and time information to string. Returns the string.
1419 strftime(fmt, sec, min, hour, mday, mon, year,
1420 wday = -1, yday = -1, isdst = -1)
1422 The month (C<mon>), weekday (C<wday>), and yearday (C<yday>) begin at zero.
1423 I.e. January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The
1424 year (C<year>) is given in years since 1900. I.e., the year 1995 is 95; the
1425 year 2001 is 101. Consult your system's C<strftime()> manpage for details
1426 about these and the other arguments.
1428 If you want your code to be portable, your format (C<fmt>) argument
1429 should use only the conversion specifiers defined by the ANSI C
1430 standard (C89, to play safe). These are C<aAbBcdHIjmMpSUwWxXyYZ%>.
1431 But even then, the B<results> of some of the conversion specifiers are
1432 non-portable. For example, the specifiers C<aAbBcpZ> change according
1433 to the locale settings of the user, and both how to set locales (the
1434 locale names) and what output to expect are non-standard.
1435 The specifier C<c> changes according to the timezone settings of the
1436 user and the timezone computation rules of the operating system.
1437 The C<Z> specifier is notoriously unportable since the names of
1438 timezones are non-standard. Sticking to the numeric specifiers is the
1441 The given arguments are made consistent as though by calling
1442 C<mktime()> before calling your system's C<strftime()> function,
1443 except that the C<isdst> value is not affected.
1445 The string for Tuesday, December 12, 1995.
1447 $str = POSIX::strftime( "%A, %B %d, %Y",
1448 0, 0, 0, 12, 11, 95, 2 );
1453 C<strlen()> is C-specific, use C<length()> instead, see L<perlfunc/length>.
1457 C<strncat()> is C-specific, use C<.=> instead, see L<perlop>.
1461 C<strncmp()> is C-specific, use C<eq> instead, see L<perlop>.
1465 C<strncpy()> is C-specific, use C<=> instead, see L<perlop>.
1469 C<strpbrk()> is C-specific, use regular expressions instead,
1474 C<strrchr()> is C-specific, see L<perlfunc/rindex> instead.
1478 C<strspn()> is C-specific, use regular expressions instead,
1483 This is identical to Perl's builtin C<index()> function,
1484 see L<perlfunc/index>.
1488 String to double translation. Returns the parsed number and the number
1489 of characters in the unparsed portion of the string. Truly
1490 POSIX-compliant systems set C<$!> (C<$ERRNO>) to indicate a translation
1491 error, so clear C<$!> before calling strtod. However, non-POSIX systems
1492 may not check for overflow, and therefore will never set C<$!>.
1494 strtod respects any POSIX I<setlocale()> C<LC_TIME> settings,
1495 regardless of whether or not it is called from Perl code that is within
1496 the scope of S<C<use locale>>.
1498 To parse a string C<$str> as a floating point number use
1501 ($num, $n_unparsed) = POSIX::strtod($str);
1503 The second returned item and C<$!> can be used to check for valid input:
1505 if (($str eq '') || ($n_unparsed != 0) || $!) {
1506 die "Non-numeric input $str" . ($! ? ": $!\n" : "\n");
1509 When called in a scalar context strtod returns the parsed number.
1513 C<strtok()> is C-specific, use regular expressions instead, see
1514 L<perlre>, or L<perlfunc/split>.
1518 String to (long) integer translation. Returns the parsed number and
1519 the number of characters in the unparsed portion of the string. Truly
1520 POSIX-compliant systems set C<$!> (C<$ERRNO>) to indicate a translation
1521 error, so clear C<$!> before calling C<strtol>. However, non-POSIX systems
1522 may not check for overflow, and therefore will never set C<$!>.
1524 C<strtol> should respect any POSIX I<setlocale()> settings.
1526 To parse a string C<$str> as a number in some base C<$base> use
1529 ($num, $n_unparsed) = POSIX::strtol($str, $base);
1531 The base should be zero or between 2 and 36, inclusive. When the base
1532 is zero or omitted strtol will use the string itself to determine the
1533 base: a leading "0x" or "0X" means hexadecimal; a leading "0" means
1534 octal; any other leading characters mean decimal. Thus, "1234" is
1535 parsed as a decimal number, "01234" as an octal number, and "0x1234"
1536 as a hexadecimal number.
1538 The second returned item and C<$!> can be used to check for valid input:
1540 if (($str eq '') || ($n_unparsed != 0) || !$!) {
1541 die "Non-numeric input $str" . $! ? ": $!\n" : "\n";
1544 When called in a scalar context strtol returns the parsed number.
1548 String to unsigned (long) integer translation. C<strtoul()> is identical
1549 to C<strtol()> except that C<strtoul()> only parses unsigned integers. See
1550 L</strtol> for details.
1552 Note: Some vendors supply C<strtod()> and C<strtol()> but not C<strtoul()>.
1553 Other vendors that do supply C<strtoul()> parse "-1" as a valid value.
1557 String transformation. Returns the transformed string.
1559 $dst = POSIX::strxfrm( $src );
1561 Used in conjunction with the C<strcoll()> function, see L</strcoll>.
1563 Not really needed since Perl can do this transparently, see
1568 Retrieves values of system configurable variables.
1570 The following will get the machine's clock speed.
1572 $clock_ticks = POSIX::sysconf( &POSIX::_SC_CLK_TCK );
1574 Returns C<undef> on failure.
1578 This is identical to Perl's builtin C<system()> function, see
1583 This is identical to the C function C<tan()>, returning the
1584 tangent of the numerical argument. See also L<Math::Trig>.
1588 This is identical to the C function C<tanh()>, returning the
1589 hyperbolic tangent of the numerical argument. See also L<Math::Trig>.
1593 This is similar to the C function C<tcdrain()> for draining
1594 the output queue of its argument stream.
1596 Returns C<undef> on failure.
1600 This is similar to the C function C<tcflow()> for controlling
1601 the flow of its argument stream.
1603 Returns C<undef> on failure.
1607 This is similar to the C function C<tcflush()> for flushing
1608 the I/O buffers of its argument stream.
1610 Returns C<undef> on failure.
1614 This is identical to the C function C<tcgetpgrp()> for returning the
1615 process group identifier of the foreground process group of the controlling
1618 =item C<tcsendbreak>
1620 This is similar to the C function C<tcsendbreak()> for sending
1621 a break on its argument stream.
1623 Returns C<undef> on failure.
1627 This is similar to the C function C<tcsetpgrp()> for setting the
1628 process group identifier of the foreground process group of the controlling
1631 Returns C<undef> on failure.
1635 This is identical to Perl's builtin C<time()> function
1636 for returning the number of seconds since the epoch
1637 (whatever it is for the system), see L<perlfunc/time>.
1641 The C<times()> function returns elapsed realtime since some point in the past
1642 (such as system startup), user and system times for this process, and user
1643 and system times used by child processes. All times are returned in clock
1646 ($realtime, $user, $system, $cuser, $csystem)
1649 Note: Perl's builtin C<times()> function returns four values, measured in
1654 Use method C<IO::File::new_tmpfile()> instead, or see L<File::Temp>.
1658 Returns a name for a temporary file.
1660 $tmpfile = POSIX::tmpnam();
1662 For security reasons, which are probably detailed in your system's
1663 documentation for the C library C<tmpnam()> function, this interface
1664 should not be used; instead see L<File::Temp>.
1668 This is identical to the C function, except that it can apply to a single
1669 character or to a whole string. Consider using the C<lc()> function,
1670 see L<perlfunc/lc>, or the equivalent C<\L> operator inside doublequotish
1675 This is identical to the C function, except that it can apply to a single
1676 character or to a whole string. Consider using the C<uc()> function,
1677 see L<perlfunc/uc>, or the equivalent C<\U> operator inside doublequotish
1682 This is identical to the C function C<ttyname()> for returning the
1683 name of the current terminal.
1687 Retrieves the time conversion information from the C<tzname> variable.
1690 ($std, $dst) = POSIX::tzname();
1694 This is identical to the C function C<tzset()> for setting
1695 the current timezone based on the environment variable C<TZ>,
1696 to be used by C<ctime()>, C<localtime()>, C<mktime()>, and C<strftime()>
1701 This is identical to Perl's builtin C<umask()> function
1702 for setting (and querying) the file creation permission mask,
1703 see L<perlfunc/umask>.
1707 Get name of current operating system.
1709 ($sysname, $nodename, $release, $version, $machine)
1712 Note that the actual meanings of the various fields are not
1713 that well standardized, do not expect any great portability.
1714 The C<$sysname> might be the name of the operating system,
1715 the C<$nodename> might be the name of the host, the C<$release>
1716 might be the (major) release number of the operating system,
1717 the C<$version> might be the (minor) release number of the
1718 operating system, and the C<$machine> might be a hardware identifier.
1723 Use method C<IO::Handle::ungetc()> instead.
1727 This is identical to Perl's builtin C<unlink()> function
1728 for removing files, see L<perlfunc/unlink>.
1732 This is identical to Perl's builtin C<utime()> function
1733 for changing the time stamps of files and directories,
1734 see L<perlfunc/utime>.
1738 C<vfprintf()> is C-specific, see L<perlfunc/printf> instead.
1742 C<vprintf()> is C-specific, see L<perlfunc/printf> instead.
1746 C<vsprintf()> is C-specific, see L<perlfunc/sprintf> instead.
1750 This is identical to Perl's builtin C<wait()> function,
1751 see L<perlfunc/wait>.
1755 Wait for a child process to change state. This is identical to Perl's
1756 builtin C<waitpid()> function, see L<perlfunc/waitpid>.
1758 $pid = POSIX::waitpid( -1, POSIX::WNOHANG );
1759 print "status = ", ($? / 256), "\n";
1763 This is identical to the C function C<wcstombs()>.
1764 Perl does not have any support for the wide and multibyte
1765 characters of the C standards, so this might be a rather
1770 This is identical to the C function C<wctomb()>.
1771 Perl does not have any support for the wide and multibyte
1772 characters of the C standards, so this might be a rather
1777 Write to a file. This uses file descriptors such as those obtained by
1778 calling C<POSIX::open>.
1780 $fd = POSIX::open( "foo", &POSIX::O_WRONLY );
1782 $bytes = POSIX::write( $fd, $buf, 5 );
1784 Returns C<undef> on failure.
1786 See also L<perlfunc/syswrite>.
1792 =head2 C<POSIX::SigAction>
1798 Creates a new C<POSIX::SigAction> object which corresponds to the C
1799 C<struct sigaction>. This object will be destroyed automatically when
1800 it is no longer needed. The first parameter is the handler, a sub
1801 reference. The second parameter is a C<POSIX::SigSet> object, it
1802 defaults to the empty set. The third parameter contains the
1803 C<sa_flags>, it defaults to 0.
1805 $sigset = POSIX::SigSet->new(SIGINT, SIGQUIT);
1806 $sigaction = POSIX::SigAction->new(
1807 \&handler, $sigset, &POSIX::SA_NOCLDSTOP
1810 This C<POSIX::SigAction> object is intended for use with the C<POSIX::sigaction()>
1823 accessor functions to get/set the values of a SigAction object.
1825 $sigset = $sigaction->mask;
1826 $sigaction->flags(&POSIX::SA_RESTART);
1830 accessor function for the "safe signals" flag of a SigAction object; see
1831 L<perlipc> for general information on safe (a.k.a. "deferred") signals. If
1832 you wish to handle a signal safely, use this accessor to set the "safe" flag
1833 in the C<POSIX::SigAction> object:
1835 $sigaction->safe(1);
1837 You may also examine the "safe" flag on the output action object which is
1838 filled in when given as the third parameter to C<POSIX::sigaction()>:
1840 sigaction(SIGINT, $new_action, $old_action);
1841 if ($old_action->safe) {
1842 # previous SIGINT handler used safe signals
1847 =head2 C<POSIX::SigRt>
1853 A hash of the POSIX realtime signal handlers. It is an extension of
1854 the standard C<%SIG>, the C<$POSIX::SIGRT{SIGRTMIN}> is roughly equivalent
1855 to C<$SIG{SIGRTMIN}>, but the right POSIX moves (see below) are made with
1856 the C<POSIX::SigSet> and C<POSIX::sigaction> instead of accessing the C<%SIG>.
1858 You can set the C<%POSIX::SIGRT> elements to set the POSIX realtime
1859 signal handlers, use C<delete> and C<exists> on the elements, and use
1860 C<scalar> on the C<%POSIX::SIGRT> to find out how many POSIX realtime
1861 signals there are available S<C<(SIGRTMAX - SIGRTMIN + 1>>, the C<SIGRTMAX> is
1862 a valid POSIX realtime signal).
1864 Setting the C<%SIGRT> elements is equivalent to calling this:
1867 my ($rtsig, $handler, $flags) = @_;
1868 my $sigset = POSIX::SigSet($rtsig);
1869 my $sigact = POSIX::SigAction->new($handler,$sigset,$flags);
1870 sigaction($rtsig, $sigact);
1873 The flags default to zero, if you want something different you can
1874 either use C<local> on C<$POSIX::SigRt::SIGACTION_FLAGS>, or you can
1875 derive from POSIX::SigRt and define your own C<new()> (the tied hash
1876 STORE method of the C<%SIGRT> calls C<new($rtsig, $handler, $SIGACTION_FLAGS)>,
1877 where the C<$rtsig> ranges from zero to S<C<SIGRTMAX - SIGRTMIN + 1)>>.
1879 Just as with any signal, you can use C<sigaction($rtsig, undef, $oa)> to
1880 retrieve the installed signal handler (or, rather, the signal action).
1882 B<NOTE:> whether POSIX realtime signals really work in your system, or
1883 whether Perl has been compiled so that it works with them, is outside
1888 Return the minimum POSIX realtime signal number available, or C<undef>
1889 if no POSIX realtime signals are available.
1893 Return the maximum POSIX realtime signal number available, or C<undef>
1894 if no POSIX realtime signals are available.
1898 =head2 C<POSIX::SigSet>
1904 Create a new SigSet object. This object will be destroyed automatically
1905 when it is no longer needed. Arguments may be supplied to initialize the
1908 Create an empty set.
1910 $sigset = POSIX::SigSet->new;
1912 Create a set with C<SIGUSR1>.
1914 $sigset = POSIX::SigSet->new( &POSIX::SIGUSR1 );
1918 Add a signal to a SigSet object.
1920 $sigset->addset( &POSIX::SIGUSR2 );
1922 Returns C<undef> on failure.
1926 Remove a signal from the SigSet object.
1928 $sigset->delset( &POSIX::SIGUSR2 );
1930 Returns C<undef> on failure.
1934 Initialize the SigSet object to be empty.
1936 $sigset->emptyset();
1938 Returns C<undef> on failure.
1942 Initialize the SigSet object to include all signals.
1946 Returns C<undef> on failure.
1950 Tests the SigSet object to see if it contains a specific signal.
1952 if( $sigset->ismember( &POSIX::SIGUSR1 ) ){
1953 print "contains SIGUSR1\n";
1958 =head2 C<POSIX::Termios>
1964 Create a new Termios object. This object will be destroyed automatically
1965 when it is no longer needed. A Termios object corresponds to the termios
1966 C struct. C<new()> mallocs a new one, C<getattr()> fills it from a file descriptor,
1967 and C<setattr()> sets a file descriptor's parameters to match Termios' contents.
1969 $termios = POSIX::Termios->new;
1973 Get terminal control attributes.
1975 Obtain the attributes for stdin.
1977 $termios->getattr( 0 ) # Recommended for clarity.
1980 Obtain the attributes for stdout.
1982 $termios->getattr( 1 )
1984 Returns C<undef> on failure.
1988 Retrieve a value from the c_cc field of a termios object. The c_cc field is
1989 an array so an index must be specified.
1991 $c_cc[1] = $termios->getcc(1);
1995 Retrieve the c_cflag field of a termios object.
1997 $c_cflag = $termios->getcflag;
2001 Retrieve the c_iflag field of a termios object.
2003 $c_iflag = $termios->getiflag;
2007 Retrieve the input baud rate.
2009 $ispeed = $termios->getispeed;
2013 Retrieve the c_lflag field of a termios object.
2015 $c_lflag = $termios->getlflag;
2019 Retrieve the c_oflag field of a termios object.
2021 $c_oflag = $termios->getoflag;
2025 Retrieve the output baud rate.
2027 $ospeed = $termios->getospeed;
2031 Set terminal control attributes.
2033 Set attributes immediately for stdout.
2035 $termios->setattr( 1, &POSIX::TCSANOW );
2037 Returns C<undef> on failure.
2041 Set a value in the c_cc field of a termios object. The c_cc field is an
2042 array so an index must be specified.
2044 $termios->setcc( &POSIX::VEOF, 1 );
2048 Set the c_cflag field of a termios object.
2050 $termios->setcflag( $c_cflag | &POSIX::CLOCAL );
2054 Set the c_iflag field of a termios object.
2056 $termios->setiflag( $c_iflag | &POSIX::BRKINT );
2060 Set the input baud rate.
2062 $termios->setispeed( &POSIX::B9600 );
2064 Returns C<undef> on failure.
2068 Set the c_lflag field of a termios object.
2070 $termios->setlflag( $c_lflag | &POSIX::ECHO );
2074 Set the c_oflag field of a termios object.
2076 $termios->setoflag( $c_oflag | &POSIX::OPOST );
2080 Set the output baud rate.
2082 $termios->setospeed( &POSIX::B9600 );
2084 Returns C<undef> on failure.
2086 =item Baud rate values
2088 C<B38400> C<B75> C<B200> C<B134> C<B300> C<B1800> C<B150> C<B0> C<B19200> C<B1200> C<B9600> C<B600> C<B4800> C<B50> C<B2400> C<B110>
2090 =item Terminal interface values
2092 C<TCSADRAIN> C<TCSANOW> C<TCOON> C<TCIOFLUSH> C<TCOFLUSH> C<TCION> C<TCIFLUSH> C<TCSAFLUSH> C<TCIOFF> C<TCOOFF>
2094 =item C<c_cc> field values
2096 C<VEOF> C<VEOL> C<VERASE> C<VINTR> C<VKILL> C<VQUIT> C<VSUSP> C<VSTART> C<VSTOP> C<VMIN> C<VTIME> C<NCCS>
2098 =item C<c_cflag> field values
2100 C<CLOCAL> C<CREAD> C<CSIZE> C<CS5> C<CS6> C<CS7> C<CS8> C<CSTOPB> C<HUPCL> C<PARENB> C<PARODD>
2102 =item C<c_iflag> field values
2104 C<BRKINT> C<ICRNL> C<IGNBRK> C<IGNCR> C<IGNPAR> C<INLCR> C<INPCK> C<ISTRIP> C<IXOFF> C<IXON> C<PARMRK>
2106 =item C<c_lflag> field values
2108 C<ECHO> C<ECHOE> C<ECHOK> C<ECHONL> C<ICANON> C<IEXTEN> C<ISIG> C<NOFLSH> C<TOSTOP>
2110 =item C<c_oflag> field values
2116 =head1 PATHNAME CONSTANTS
2122 C<_PC_CHOWN_RESTRICTED> C<_PC_LINK_MAX> C<_PC_MAX_CANON> C<_PC_MAX_INPUT> C<_PC_NAME_MAX>
2123 C<_PC_NO_TRUNC> C<_PC_PATH_MAX> C<_PC_PIPE_BUF> C<_PC_VDISABLE>
2127 =head1 POSIX CONSTANTS
2133 C<_POSIX_ARG_MAX> C<_POSIX_CHILD_MAX> C<_POSIX_CHOWN_RESTRICTED> C<_POSIX_JOB_CONTROL>
2134 C<_POSIX_LINK_MAX> C<_POSIX_MAX_CANON> C<_POSIX_MAX_INPUT> C<_POSIX_NAME_MAX>
2135 C<_POSIX_NGROUPS_MAX> C<_POSIX_NO_TRUNC> C<_POSIX_OPEN_MAX> C<_POSIX_PATH_MAX>
2136 C<_POSIX_PIPE_BUF> C<_POSIX_SAVED_IDS> C<_POSIX_SSIZE_MAX> C<_POSIX_STREAM_MAX>
2137 C<_POSIX_TZNAME_MAX> C<_POSIX_VDISABLE> C<_POSIX_VERSION>
2141 =head1 SYSTEM CONFIGURATION
2147 C<_SC_ARG_MAX> C<_SC_CHILD_MAX> C<_SC_CLK_TCK> C<_SC_JOB_CONTROL> C<_SC_NGROUPS_MAX>
2148 C<_SC_OPEN_MAX> C<_SC_PAGESIZE> C<_SC_SAVED_IDS> C<_SC_STREAM_MAX> C<_SC_TZNAME_MAX>
2159 C<E2BIG> C<EACCES> C<EADDRINUSE> C<EADDRNOTAVAIL> C<EAFNOSUPPORT> C<EAGAIN> C<EALREADY> C<EBADF> C<EBADMSG>
2160 C<EBUSY> C<ECANCELED> C<ECHILD> C<ECONNABORTED> C<ECONNREFUSED> C<ECONNRESET> C<EDEADLK> C<EDESTADDRREQ>
2161 C<EDOM> C<EDQUOT> C<EEXIST> C<EFAULT> C<EFBIG> C<EHOSTDOWN> C<EHOSTUNREACH> C<EIDRM> C<EILSEQ> C<EINPROGRESS>
2162 C<EINTR> C<EINVAL> C<EIO> C<EISCONN> C<EISDIR> C<ELOOP> C<EMFILE> C<EMLINK> C<EMSGSIZE> C<ENAMETOOLONG>
2163 C<ENETDOWN> C<ENETRESET> C<ENETUNREACH> C<ENFILE> C<ENOBUFS> C<ENODATA> C<ENODEV> C<ENOENT> C<ENOEXEC>
2164 C<ENOLCK> C<ENOLINK> C<ENOMEM> C<ENOMSG> C<ENOPROTOOPT> C<ENOSPC> C<ENOSR> C<ENOSTR> C<ENOSYS> C<ENOTBLK>
2165 C<ENOTCONN> C<ENOTDIR> C<ENOTEMPTY> C<ENOTRECOVERABLE> C<ENOTSOCK> C<ENOTSUP> C<ENOTTY> C<ENXIO>
2166 C<EOPNOTSUPP> C<EOTHER> C<EOVERFLOW> C<EOWNERDEAD> C<EPERM> C<EPFNOSUPPORT> C<EPIPE> C<EPROCLIM> C<EPROTO>
2167 C<EPROTONOSUPPORT> C<EPROTOTYPE> C<ERANGE> C<EREMOTE> C<ERESTART> C<EROFS> C<ESHUTDOWN>
2168 C<ESOCKTNOSUPPORT> C<ESPIPE> C<ESRCH> C<ESTALE> C<ETIME> C<ETIMEDOUT> C<ETOOMANYREFS> C<ETXTBSY> C<EUSERS>
2169 C<EWOULDBLOCK> C<EXDEV>
2179 C<FD_CLOEXEC> C<F_DUPFD> C<F_GETFD> C<F_GETFL> C<F_GETLK> C<F_OK> C<F_RDLCK> C<F_SETFD> C<F_SETFL> C<F_SETLK>
2180 C<F_SETLKW> C<F_UNLCK> C<F_WRLCK> C<O_ACCMODE> C<O_APPEND> C<O_CREAT> C<O_EXCL> C<O_NOCTTY> C<O_NONBLOCK>
2181 C<O_RDONLY> C<O_RDWR> C<O_TRUNC> C<O_WRONLY>
2191 C<DBL_DIG> C<DBL_EPSILON> C<DBL_MANT_DIG> C<DBL_MAX> C<DBL_MAX_10_EXP> C<DBL_MAX_EXP> C<DBL_MIN>
2192 C<DBL_MIN_10_EXP> C<DBL_MIN_EXP> C<FLT_DIG> C<FLT_EPSILON> C<FLT_MANT_DIG> C<FLT_MAX>
2193 C<FLT_MAX_10_EXP> C<FLT_MAX_EXP> C<FLT_MIN> C<FLT_MIN_10_EXP> C<FLT_MIN_EXP> C<FLT_RADIX>
2194 C<FLT_ROUNDS> C<LDBL_DIG> C<LDBL_EPSILON> C<LDBL_MANT_DIG> C<LDBL_MAX> C<LDBL_MAX_10_EXP>
2195 C<LDBL_MAX_EXP> C<LDBL_MIN> C<LDBL_MIN_10_EXP> C<LDBL_MIN_EXP>
2205 C<ARG_MAX> C<CHAR_BIT> C<CHAR_MAX> C<CHAR_MIN> C<CHILD_MAX> C<INT_MAX> C<INT_MIN> C<LINK_MAX> C<LONG_MAX>
2206 C<LONG_MIN> C<MAX_CANON> C<MAX_INPUT> C<MB_LEN_MAX> C<NAME_MAX> C<NGROUPS_MAX> C<OPEN_MAX> C<PATH_MAX>
2207 C<PIPE_BUF> C<SCHAR_MAX> C<SCHAR_MIN> C<SHRT_MAX> C<SHRT_MIN> C<SSIZE_MAX> C<STREAM_MAX> C<TZNAME_MAX>
2208 C<UCHAR_MAX> C<UINT_MAX> C<ULONG_MAX> C<USHRT_MAX>
2218 C<LC_ALL> C<LC_COLLATE> C<LC_CTYPE> C<LC_MONETARY> C<LC_NUMERIC> C<LC_TIME>
2238 C<SA_NOCLDSTOP> C<SA_NOCLDWAIT> C<SA_NODEFER> C<SA_ONSTACK> C<SA_RESETHAND> C<SA_RESTART>
2239 C<SA_SIGINFO> C<SIGABRT> C<SIGALRM> C<SIGCHLD> C<SIGCONT> C<SIGFPE> C<SIGHUP> C<SIGILL> C<SIGINT>
2240 C<SIGKILL> C<SIGPIPE> C<SIGQUIT> C<SIGSEGV> C<SIGSTOP> C<SIGTERM> C<SIGTSTP> C<SIGTTIN> C<SIGTTOU>
2241 C<SIGUSR1> C<SIGUSR2> C<SIG_BLOCK> C<SIG_DFL> C<SIG_ERR> C<SIG_IGN> C<SIG_SETMASK>
2252 C<S_IRGRP> C<S_IROTH> C<S_IRUSR> C<S_IRWXG> C<S_IRWXO> C<S_IRWXU> C<S_ISGID> C<S_ISUID> C<S_IWGRP> C<S_IWOTH>
2253 C<S_IWUSR> C<S_IXGRP> C<S_IXOTH> C<S_IXUSR>
2257 C<S_ISBLK> C<S_ISCHR> C<S_ISDIR> C<S_ISFIFO> C<S_ISREG>
2267 C<EXIT_FAILURE> C<EXIT_SUCCESS> C<MB_CUR_MAX> C<RAND_MAX>
2277 C<BUFSIZ> C<EOF> C<FILENAME_MAX> C<L_ctermid> C<L_cuserid> C<L_tmpname> C<TMP_MAX>
2287 C<CLK_TCK> C<CLOCKS_PER_SEC>
2297 C<R_OK> C<SEEK_CUR> C<SEEK_END> C<SEEK_SET> C<STDIN_FILENO> C<STDOUT_FILENO> C<STDERR_FILENO> C<W_OK> C<X_OK>
2307 C<WNOHANG> C<WUNTRACED>
2313 Do not suspend the calling process until a child process
2314 changes state but instead return immediately.
2318 Catch stopped child processes.
2324 C<WIFEXITED> C<WEXITSTATUS> C<WIFSIGNALED> C<WTERMSIG> C<WIFSTOPPED> C<WSTOPSIG>
2330 C<WIFEXITED(${^CHILD_ERROR_NATIVE})> returns true if the child process
2331 exited normally (C<exit()> or by falling off the end of C<main()>)
2333 =item C<WEXITSTATUS>
2335 C<WEXITSTATUS(${^CHILD_ERROR_NATIVE})> returns the normal exit status of
2336 the child process (only meaningful if C<WIFEXITED(${^CHILD_ERROR_NATIVE})>
2339 =item C<WIFSIGNALED>
2341 C<WIFSIGNALED(${^CHILD_ERROR_NATIVE})> returns true if the child process
2342 terminated because of a signal
2346 C<WTERMSIG(${^CHILD_ERROR_NATIVE})> returns the signal the child process
2347 terminated for (only meaningful if
2348 C<WIFSIGNALED(${^CHILD_ERROR_NATIVE})>
2353 C<WIFSTOPPED(${^CHILD_ERROR_NATIVE})> returns true if the child process is
2354 currently stopped (can happen only if you specified the WUNTRACED flag
2359 C<WSTOPSIG(${^CHILD_ERROR_NATIVE})> returns the signal the child process
2360 was stopped for (only meaningful if
2361 C<WIFSTOPPED(${^CHILD_ERROR_NATIVE})>