📄 posix.pod
字号:
=head1 NAMEPOSIX - Perl interface to IEEE Std 1003.1=head1 SYNOPSIS 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=head1 DESCRIPTIONThe POSIX module permits you to access all (or nearly all) the standardPOSIX 1003.1 identifiers. Many of these identifiers have been given Perl-ishinterfaces. Things which are C<#defines> in C, like EINTR or O_NDELAY, areautomatically exported into your namespace. All functions are only exportedif you ask for them explicitly. Most likely people will prefer to use thefully-qualified function names.This document gives a condensed list of the features available in the POSIXmodule. Consult your operating system's manpages for general information onmost features. Consult L<perlfunc> for functions which are noted as beingidentical 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 variousconstants and macros in an organization which roughly follows IEEE Std1003.1b-1993.=head1 NOTEThe POSIX module is probably the most complex Perl module supplied withthe standard distribution. It incorporates autoloading, namespace games,and dynamic loading of code that's in Perl, C, or both. It's a greatsource of wisdom.=head1 CAVEATS A few functions are not implemented because they are C specific. If youattempt to call these, they will print a message telling you that theyaren't implemented, and suggest using the Perl equivalent should oneexist. For example, trying to access the setjmp() call will elicit themessage "setjmp() is C-specific: use eval {} instead".Furthermore, some evil vendors will claim 1003.1 compliance, but in factare not so: they will not pass the PCTS (POSIX Compliance Test Suites).For example, one vendor may not define EDEADLK, or the semantics of theerrno values set by open(2) might not be quite right. Perl does notattempt to verify POSIX compliance. That means you can currentlysuccessfully say "use POSIX", and then later in your program you findthat your vendor has been lax and there's no usable ICANON macro afterall. This could be construed to be a bug.=head1 FUNCTIONS=over 8=item _exitThis is identical to the C function C<_exit()>. It exits the programimmediately which means among other things buffered I/O is B<not> flushed.=item abortThis is identical to the C function C<abort()>. It terminates theprocess with a C<SIGABRT> signal unless caught by a signal handler orif the handler does not return normally (it e.g. does a C<longjmp>).=item absThis is identical to Perl's builtin C<abs()> function, returningthe absolute value of its numerical argument.=item accessDetermines the accessibility of a file. if( POSIX::access( "/", &POSIX::R_OK ) ){ print "have read permission\n"; }Returns C<undef> on failure. Note: do not use C<access()> forsecurity purposes. Between the C<access()> call and the operationyou are preparing for the permissions might change: a classicI<race condition>.=item acosThis is identical to the C function C<acos()>, returningthe arcus cosine of its numerical argument. See also L<Math::Trig>.=item alarmThis is identical to Perl's builtin C<alarm()> function,either for arming or disarming the C<SIGARLM> timer.=item asctimeThis is identical to the C function C<asctime()>. It returnsa string of the form "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 C<$mon> is zero-based: January equals C<0>. The C<$year> is1900-based: 2001 equals C<101>. The C<$wday>, C<$yday>, and C<$isdst>default to zero (and the first two are usually ignored anyway).=item asinThis is identical to the C function C<asin()>, returningthe arcus sine of its numerical argument. See also L<Math::Trig>.=item assertUnimplemented, but you can use L<perlfunc/die> and the L<Carp> moduleto achieve similar things.=item atanThis is identical to the C function C<atan()>, returning thearcus tangent of its numerical argument. See also L<Math::Trig>.=item atan2This is identical to Perl's builtin C<atan2()> function, returningthe arcus tangent defined by its two numerical arguments, the I<y>coordinate and the I<x> coordinate. See also L<Math::Trig>.=item atexitatexit() is C-specific: use C<END {}> instead, see L<perlsub>.=item atofatof() is C-specific. Perl converts strings to numbers transparently.If you need to force a scalar to a number, add a zero to it.=item atoiatoi() is C-specific. Perl converts strings to numbers transparently.If you need to force a scalar to a number, add a zero to it.If you need to have just the integer part, see L<perlfunc/int>.=item atolatol() is C-specific. Perl converts strings to numbers transparently.If you need to force a scalar to a number, add a zero to it.If you need to have just the integer part, see L<perlfunc/int>.=item bsearchbsearch() not supplied. For doing binary search on wordlists,see L<Search::Dict>.=item calloccalloc() is C-specific. Perl does memory management transparently.=item ceilThis is identical to the C function C<ceil()>, returning the smallestinteger value greater than or equal to the given numerical argument.=item chdirThis is identical to Perl's builtin C<chdir()> function, allowingone to change the working (default) directory, see L<perlfunc/chdir>.=item chmodThis is identical to Perl's builtin C<chmod()> function, allowingone to change file and directory permissions, see L<perlfunc/chmod>.=item chownThis is identical to Perl's builtin C<chown()> function, allowing oneto change file and directory owners and groups, see L<perlfunc/chown>.=item clearerrUse the method L<IO::Handle::clearerr()> instead, to reset the errorstate (if any) and EOF state (if any) of the given stream.=item clockThis is identical to the C function C<clock()>, returning theamount of spent processor time in microseconds.=item closeClose the file. This uses file descriptors such as those obtained by callingC<POSIX::open>. $fd = POSIX::open( "foo", &POSIX::O_RDONLY ); POSIX::close( $fd );Returns C<undef> on failure.See also L<perlfunc/close>.=item closedirThis is identical to Perl's builtin C<closedir()> function for closinga directory handle, see L<perlfunc/closedir>.=item cosThis is identical to Perl's builtin C<cos()> function, for returningthe cosine of its numerical argument, see L<perlfunc/cos>.See also L<Math::Trig>.=item coshThis is identical to the C function C<cosh()>, for returningthe hyperbolic cosine of its numeric argument. See also L<Math::Trig>.=item creatCreate a new file. This returns a file descriptor like the ones returned byC<POSIX::open>. Use C<POSIX::close> to close the file. $fd = POSIX::creat( "foo", 0611 ); POSIX::close( $fd );See also L<perlfunc/sysopen> and its C<O_CREAT> flag.=item ctermidGenerates the path name for the controlling terminal. $path = POSIX::ctermid();=item ctimeThis is identical to the C function C<ctime()> and equivalentto C<asctime(localtime(...))>, see L</asctime> and L</localtime>.=item cuseridGet the login name of the owner of the current process. $name = POSIX::cuserid();=item difftimeThis is identical to the C function C<difftime()>, for returningthe time difference (in seconds) between two times (as returnedby C<time()>), see L</time>.=item divdiv() is C-specific, use L<perlfunc/int> on the usual C</> division andthe modulus C<%>.=item dupThis is similar to the C function C<dup()>, for duplicating a filedescriptor.This uses file descriptors such as those obtained by callingC<POSIX::open>.Returns C<undef> on failure.=item dup2This is similar to the C function C<dup2()>, for duplicating a filedescriptor to an another known file descriptor.This uses file descriptors such as those obtained by callingC<POSIX::open>.Returns C<undef> on failure.=item errnoReturns the value of errno. $errno = POSIX::errno();This identical to the numerical values of the C<$!>, see L<perlvar/$ERRNO>.=item execlexecl() is C-specific, see L<perlfunc/exec>.=item execleexecle() is C-specific, see L<perlfunc/exec>.=item execlpexeclp() is C-specific, see L<perlfunc/exec>.=item execvexecv() is C-specific, see L<perlfunc/exec>.=item execveexecve() is C-specific, see L<perlfunc/exec>.=item execvpexecvp() is C-specific, see L<perlfunc/exec>.=item exitThis is identical to Perl's builtin C<exit()> function for exiting theprogram, see L<perlfunc/exit>.=item expThis is identical to Perl's builtin C<exp()> function forreturning the exponent (I<e>-based) of the numerical argument,see L<perlfunc/exp>.=item fabsThis is identical to Perl's builtin C<abs()> function for returningthe absolute value of the numerical argument, see L<perlfunc/abs>.=item fcloseUse method C<IO::Handle::close()> instead, or see L<perlfunc/close>.=item fcntlThis is identical to Perl's builtin C<fcntl()> function,see L<perlfunc/fcntl>.=item fdopenUse method C<IO::Handle::new_from_fd()> instead, or see L<perlfunc/open>.=item feofUse method C<IO::Handle::eof()> instead, or see L<perlfunc/eof>.=item ferrorUse method C<IO::Handle::error()> instead.=item fflushUse method C<IO::Handle::flush()> instead.See also L<perlvar/$OUTPUT_AUTOFLUSH>.=item fgetcUse method C<IO::Handle::getc()> instead, or see L<perlfunc/read>.=item fgetposUse method C<IO::Seekable::getpos()> instead, or see L<L/seek>.=item fgetsUse method C<IO::Handle::gets()> instead. Similar to E<lt>E<gt>, also knownas L<perlfunc/readline>.=item filenoUse method C<IO::Handle::fileno()> instead, or see L<perlfunc/fileno>.=item floorThis is identical to the C function C<floor()>, returning the largestinteger value less than or equal to the numerical argument.=item fmodThis is identical to the C function C<fmod()>. $r = modf($x, $y);It returns the remainder C<$r = $x - $n*$y>, where C<$n = trunc($x/$y)>.The C<$r> has the same sign as C<$x> and magnitude (absolute value)less than the magnitude of C<$y>.=item fopenUse method C<IO::File::open()> instead, or see L<perlfunc/open>.=item forkThis is identical to Perl's builtin C<fork()> functionfor duplicating the current process, see L<perlfunc/fork>and L<perlfork> if you are in Windows.=item fpathconfRetrieves the value of a configurable limit on a file or directory. Thisuses file descriptors such as those obtained by calling C<POSIX::open>.The following will determine the maximum length of the longest allowablepathname on the filesystem which holds C</tmp/foo>. $fd = POSIX::open( "/tmp/foo", &POSIX::O_RDONLY ); $path_max = POSIX::fpathconf( $fd, &POSIX::_PC_PATH_MAX );Returns C<undef> on failure.=item fprintffprintf() is C-specific, see L<perlfunc/printf> instead.=item fputcfputc() is C-specific, see L<perlfunc/print> instead.=item fputsfputs() is C-specific, see L<perlfunc/print> instead.=item freadfread() is C-specific, see L<perlfunc/read> instead.=item freefree() is C-specific. Perl does memory management transparently.=item freopenfreopen() is C-specific, see L<perlfunc/open> instead.=item frexpReturn the mantissa and exponent of a floating-point number. ($mantissa, $exponent) = POSIX::frexp( 1.234e56 );=item fscanffscanf() is C-specific, use E<lt>E<gt> and regular expressions instead.=item fseekUse method C<IO::Seekable::seek()> instead, or see L<perlfunc/seek>.=item fsetposUse method C<IO::Seekable::setpos()> instead, or seek L<perlfunc/seek>.=item fstatGet file status. This uses file descriptors such as those obtained bycalling C<POSIX::open>. The data returned is identical to the data fromPerl's builtin C<stat> function. $fd = POSIX::open( "foo", &POSIX::O_RDONLY ); @stats = POSIX::fstat( $fd );=item ftellUse method C<IO::Seekable::tell()> instead, or see L<perlfunc/tell>.=item fwritefwrite() is C-specific, see L<perlfunc/print> instead.=item getcThis is identical to Perl's builtin C<getc()> function,see L<perlfunc/getc>.=item getcharReturns one character from STDIN. Identical to Perl's C<getc()>,see L<perlfunc/getc>.=item getcwdReturns the name of the current working directory.See also L<Cwd>.=item getegidReturns the effective group identifier. Similar to Perl' s builtinvariable C<$(>, see L<perlvar/$EGID>.=item getenv
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -