1POSIX(3pm) Perl Programmers Reference Guide POSIX(3pm)
2
3
4
6 POSIX - Perl interface to IEEE Std 1003.1
7
9 use POSIX ();
10 use POSIX qw(setsid);
11 use POSIX qw(:errno_h :fcntl_h);
12
13 printf "EINTR is %d\n", EINTR;
14
15 $sess_id = POSIX::setsid();
16
17 $fd = POSIX::open($path, O_CREAT|O_EXCL|O_WRONLY, 0644);
18 # note: that's a filedescriptor, *NOT* a filehandle
19
21 The POSIX module permits you to access all (or nearly all) the standard
22 POSIX 1003.1 identifiers. Many of these identifiers have been given
23 Perl-ish interfaces.
24
25 Everything is exported by default with the exception of any POSIX
26 functions with the same name as a built-in Perl function, such as
27 "abs", "alarm", "rmdir", "write", etc.., which will be exported only if
28 you ask for them explicitly. This is an unfortunate backwards
29 compatibility feature. You can stop the exporting by saying "use POSIX
30 ()" and then use the fully qualified names (ie. "POSIX::SEEK_END"), or
31 by giving an explicit import list. If you do neither, and opt for the
32 default, "use POSIX;" has to import 553 symbols.
33
34 This document gives a condensed list of the features available in the
35 POSIX module. Consult your operating system's manpages for general
36 information on most features. Consult perlfunc for functions which are
37 noted as being identical to Perl's builtin functions.
38
39 The first section describes POSIX functions from the 1003.1
40 specification. The second section describes some classes for signal
41 objects, TTY objects, and other miscellaneous objects. The remaining
42 sections list various constants and macros in an organization which
43 roughly follows IEEE Std 1003.1b-1993.
44
46 A few functions are not implemented because they are C specific. If
47 you attempt to call these, they will print a message telling you that
48 they aren't implemented, and suggest using the Perl equivalent should
49 one exist. For example, trying to access the setjmp() call will elicit
50 the message "setjmp() is C-specific: use eval {} instead".
51
52 Furthermore, some evil vendors will claim 1003.1 compliance, but in
53 fact are not so: they will not pass the PCTS (POSIX Compliance Test
54 Suites). For example, one vendor may not define EDEADLK, or the
55 semantics of the errno values set by open(2) might not be quite right.
56 Perl does not attempt to verify POSIX compliance. That means you can
57 currently successfully say "use POSIX", and then later in your program
58 you find that your vendor has been lax and there's no usable ICANON
59 macro after all. This could be construed to be a bug.
60
62 _exit This is identical to the C function "_exit()". It exits the
63 program immediately which means among other things buffered I/O
64 is not flushed.
65
66 Note that when using threads and in Linux this is not a good
67 way to exit a thread because in Linux processes and threads are
68 kind of the same thing (Note: while this is the situation in
69 early 2003 there are projects under way to have threads with
70 more POSIXly semantics in Linux). If you want not to return
71 from a thread, detach the thread.
72
73 abort This is identical to the C function "abort()". It terminates
74 the process with a "SIGABRT" signal unless caught by a signal
75 handler or if the handler does not return normally (it e.g.
76 does a "longjmp").
77
78 abs This is identical to Perl's builtin "abs()" function, returning
79 the absolute value of its numerical argument.
80
81 access Determines the accessibility of a file.
82
83 if( POSIX::access( "/", &POSIX::R_OK ) ){
84 print "have read permission\n";
85 }
86
87 Returns "undef" on failure. Note: do not use "access()" for
88 security purposes. Between the "access()" call and the
89 operation you are preparing for the permissions might change: a
90 classic race condition.
91
92 acos This is identical to the C function "acos()", returning the
93 arcus cosine of its numerical argument. See also Math::Trig.
94
95 alarm This is identical to Perl's builtin "alarm()" function, either
96 for arming or disarming the "SIGARLM" timer.
97
98 asctime This is identical to the C function "asctime()". It returns a
99 string of the form
100
101 "Fri Jun 2 18:22:13 2000\n\0"
102
103 and it is called thusly
104
105 $asctime = asctime($sec, $min, $hour, $mday, $mon, $year,
106 $wday, $yday, $isdst);
107
108 The $mon is zero-based: January equals 0. The $year is
109 1900-based: 2001 equals 101. $wday and $yday default to zero
110 (and are usually ignored anyway), and $isdst defaults to -1.
111
112 asin This is identical to the C function "asin()", returning the
113 arcus sine of its numerical argument. See also Math::Trig.
114
115 assert Unimplemented, but you can use "die" in perlfunc and the Carp
116 module to achieve similar things.
117
118 atan This is identical to the C function "atan()", returning the
119 arcus tangent of its numerical argument. See also Math::Trig.
120
121 atan2 This is identical to Perl's builtin "atan2()" function,
122 returning the arcus tangent defined by its two numerical
123 arguments, the y coordinate and the x coordinate. See also
124 Math::Trig.
125
126 atexit atexit() is C-specific: use "END {}" instead, see perlsub.
127
128 atof atof() is C-specific. Perl converts strings to numbers
129 transparently. If you need to force a scalar to a number, add
130 a zero to it.
131
132 atoi atoi() is C-specific. Perl converts strings to numbers
133 transparently. If you need to force a scalar to a number, add
134 a zero to it. If you need to have just the integer part, see
135 "int" in perlfunc.
136
137 atol atol() is C-specific. Perl converts strings to numbers
138 transparently. If you need to force a scalar to a number, add
139 a zero to it. If you need to have just the integer part, see
140 "int" in perlfunc.
141
142 bsearch bsearch() not supplied. For doing binary search on wordlists,
143 see Search::Dict.
144
145 calloc calloc() is C-specific. Perl does memory management
146 transparently.
147
148 ceil This is identical to the C function "ceil()", returning the
149 smallest integer value greater than or equal to the given
150 numerical argument.
151
152 chdir This is identical to Perl's builtin "chdir()" function,
153 allowing one to change the working (default) directory, see
154 "chdir" in perlfunc.
155
156 chmod This is identical to Perl's builtin "chmod()" function,
157 allowing one to change file and directory permissions, see
158 "chmod" in perlfunc.
159
160 chown This is identical to Perl's builtin "chown()" function,
161 allowing one to change file and directory owners and groups,
162 see "chown" in perlfunc.
163
164 clearerr
165 Use the method "IO::Handle::clearerr()" instead, to reset the
166 error state (if any) and EOF state (if any) of the given
167 stream.
168
169 clock This is identical to the C function "clock()", returning the
170 amount of spent processor time in microseconds.
171
172 close Close the file. This uses file descriptors such as those
173 obtained by calling "POSIX::open".
174
175 $fd = POSIX::open( "foo", &POSIX::O_RDONLY );
176 POSIX::close( $fd );
177
178 Returns "undef" on failure.
179
180 See also "close" in perlfunc.
181
182 closedir
183 This is identical to Perl's builtin "closedir()" function for
184 closing a directory handle, see "closedir" in perlfunc.
185
186 cos This is identical to Perl's builtin "cos()" function, for
187 returning the cosine of its numerical argument, see "cos" in
188 perlfunc. See also Math::Trig.
189
190 cosh This is identical to the C function "cosh()", for returning the
191 hyperbolic cosine of its numeric argument. See also
192 Math::Trig.
193
194 creat Create a new file. This returns a file descriptor like the
195 ones returned by "POSIX::open". Use "POSIX::close" to close
196 the file.
197
198 $fd = POSIX::creat( "foo", 0611 );
199 POSIX::close( $fd );
200
201 See also "sysopen" in perlfunc and its "O_CREAT" flag.
202
203 ctermid Generates the path name for the controlling terminal.
204
205 $path = POSIX::ctermid();
206
207 ctime This is identical to the C function "ctime()" and equivalent to
208 "asctime(localtime(...))", see "asctime" and "localtime".
209
210 cuserid Get the login name of the owner of the current process.
211
212 $name = POSIX::cuserid();
213
214 difftime
215 This is identical to the C function "difftime()", for returning
216 the time difference (in seconds) between two times (as returned
217 by "time()"), see "time".
218
219 div div() is C-specific, use "int" in perlfunc on the usual "/"
220 division and the modulus "%".
221
222 dup This is similar to the C function "dup()", for duplicating a
223 file descriptor.
224
225 This uses file descriptors such as those obtained by calling
226 "POSIX::open".
227
228 Returns "undef" on failure.
229
230 dup2 This is similar to the C function "dup2()", for duplicating a
231 file descriptor to an another known file descriptor.
232
233 This uses file descriptors such as those obtained by calling
234 "POSIX::open".
235
236 Returns "undef" on failure.
237
238 errno Returns the value of errno.
239
240 $errno = POSIX::errno();
241
242 This identical to the numerical values of the $!, see "$ERRNO"
243 in perlvar.
244
245 execl execl() is C-specific, see "exec" in perlfunc.
246
247 execle execle() is C-specific, see "exec" in perlfunc.
248
249 execlp execlp() is C-specific, see "exec" in perlfunc.
250
251 execv execv() is C-specific, see "exec" in perlfunc.
252
253 execve execve() is C-specific, see "exec" in perlfunc.
254
255 execvp execvp() is C-specific, see "exec" in perlfunc.
256
257 exit This is identical to Perl's builtin "exit()" function for
258 exiting the program, see "exit" in perlfunc.
259
260 exp This is identical to Perl's builtin "exp()" function for
261 returning the exponent (e-based) of the numerical argument, see
262 "exp" in perlfunc.
263
264 fabs This is identical to Perl's builtin "abs()" function for
265 returning the absolute value of the numerical argument, see
266 "abs" in perlfunc.
267
268 fclose Use method "IO::Handle::close()" instead, or see "close" in
269 perlfunc.
270
271 fcntl This is identical to Perl's builtin "fcntl()" function, see
272 "fcntl" in perlfunc.
273
274 fdopen Use method "IO::Handle::new_from_fd()" instead, or see "open"
275 in perlfunc.
276
277 feof Use method "IO::Handle::eof()" instead, or see "eof" in
278 perlfunc.
279
280 ferror Use method "IO::Handle::error()" instead.
281
282 fflush Use method "IO::Handle::flush()" instead. See also
283 "$OUTPUT_AUTOFLUSH" in perlvar.
284
285 fgetc Use method "IO::Handle::getc()" instead, or see "read" in
286 perlfunc.
287
288 fgetpos Use method "IO::Seekable::getpos()" instead, or see "seek" in
289 perlfunc.
290
291 fgets Use method "IO::Handle::gets()" instead. Similar to <>, also
292 known as "readline" in perlfunc.
293
294 fileno Use method "IO::Handle::fileno()" instead, or see "fileno" in
295 perlfunc.
296
297 floor This is identical to the C function "floor()", returning the
298 largest integer value less than or equal to the numerical
299 argument.
300
301 fmod This is identical to the C function "fmod()".
302
303 $r = fmod($x, $y);
304
305 It returns the remainder "$r = $x - $n*$y", where "$n =
306 trunc($x/$y)". The $r has the same sign as $x and magnitude
307 (absolute value) less than the magnitude of $y.
308
309 fopen Use method "IO::File::open()" instead, or see "open" in
310 perlfunc.
311
312 fork This is identical to Perl's builtin "fork()" function for
313 duplicating the current process, see "fork" in perlfunc and
314 perlfork if you are in Windows.
315
316 fpathconf
317 Retrieves the value of a configurable limit on a file or
318 directory. This uses file descriptors such as those obtained
319 by calling "POSIX::open".
320
321 The following will determine the maximum length of the longest
322 allowable pathname on the filesystem which holds "/var/foo".
323
324 $fd = POSIX::open( "/var/foo", &POSIX::O_RDONLY );
325 $path_max = POSIX::fpathconf( $fd, &POSIX::_PC_PATH_MAX );
326
327 Returns "undef" on failure.
328
329 fprintf fprintf() is C-specific, see "printf" in perlfunc instead.
330
331 fputc fputc() is C-specific, see "print" in perlfunc instead.
332
333 fputs fputs() is C-specific, see "print" in perlfunc instead.
334
335 fread fread() is C-specific, see "read" in perlfunc instead.
336
337 free free() is C-specific. Perl does memory management
338 transparently.
339
340 freopen freopen() is C-specific, see "open" in perlfunc instead.
341
342 frexp Return the mantissa and exponent of a floating-point number.
343
344 ($mantissa, $exponent) = POSIX::frexp( 1.234e56 );
345
346 fscanf fscanf() is C-specific, use <> and regular expressions instead.
347
348 fseek Use method "IO::Seekable::seek()" instead, or see "seek" in
349 perlfunc.
350
351 fsetpos Use method "IO::Seekable::setpos()" instead, or seek "seek" in
352 perlfunc.
353
354 fstat Get file status. This uses file descriptors such as those
355 obtained by calling "POSIX::open". The data returned is
356 identical to the data from Perl's builtin "stat" function.
357
358 $fd = POSIX::open( "foo", &POSIX::O_RDONLY );
359 @stats = POSIX::fstat( $fd );
360
361 fsync Use method "IO::Handle::sync()" instead.
362
363 ftell Use method "IO::Seekable::tell()" instead, or see "tell" in
364 perlfunc.
365
366 fwrite fwrite() is C-specific, see "print" in perlfunc instead.
367
368 getc This is identical to Perl's builtin "getc()" function, see
369 "getc" in perlfunc.
370
371 getchar Returns one character from STDIN. Identical to Perl's
372 "getc()", see "getc" in perlfunc.
373
374 getcwd Returns the name of the current working directory. See also
375 Cwd.
376
377 getegid Returns the effective group identifier. Similar to Perl' s
378 builtin variable $(, see "$EGID" in perlvar.
379
380 getenv Returns the value of the specified environment variable. The
381 same information is available through the %ENV array.
382
383 geteuid Returns the effective user identifier. Identical to Perl's
384 builtin $> variable, see "$EUID" in perlvar.
385
386 getgid Returns the user's real group identifier. Similar to Perl's
387 builtin variable $), see "$GID" in perlvar.
388
389 getgrgid
390 This is identical to Perl's builtin "getgrgid()" function for
391 returning group entries by group identifiers, see "getgrgid" in
392 perlfunc.
393
394 getgrnam
395 This is identical to Perl's builtin "getgrnam()" function for
396 returning group entries by group names, see "getgrnam" in
397 perlfunc.
398
399 getgroups
400 Returns the ids of the user's supplementary groups. Similar to
401 Perl's builtin variable $), see "$GID" in perlvar.
402
403 getlogin
404 This is identical to Perl's builtin "getlogin()" function for
405 returning the user name associated with the current session,
406 see "getlogin" in perlfunc.
407
408 getpgrp This is identical to Perl's builtin "getpgrp()" function for
409 returning the process group identifier of the current process,
410 see "getpgrp" in perlfunc.
411
412 getpid Returns the process identifier. Identical to Perl's builtin
413 variable $$, see "$PID" in perlvar.
414
415 getppid This is identical to Perl's builtin "getppid()" function for
416 returning the process identifier of the parent process of the
417 current process , see "getppid" in perlfunc.
418
419 getpwnam
420 This is identical to Perl's builtin "getpwnam()" function for
421 returning user entries by user names, see "getpwnam" in
422 perlfunc.
423
424 getpwuid
425 This is identical to Perl's builtin "getpwuid()" function for
426 returning user entries by user identifiers, see "getpwuid" in
427 perlfunc.
428
429 gets Returns one line from "STDIN", similar to <>, also known as the
430 "readline()" function, see "readline" in perlfunc.
431
432 NOTE: if you have C programs that still use "gets()", be very
433 afraid. The "gets()" function is a source of endless grief
434 because it has no buffer overrun checks. It should never be
435 used. The "fgets()" function should be preferred instead.
436
437 getuid Returns the user's identifier. Identical to Perl's builtin $<
438 variable, see "$UID" in perlvar.
439
440 gmtime This is identical to Perl's builtin "gmtime()" function for
441 converting seconds since the epoch to a date in Greenwich Mean
442 Time, see "gmtime" in perlfunc.
443
444 isalnum This is identical to the C function, except that it can apply
445 to a single character or to a whole string. Note that locale
446 settings may affect what characters are considered "isalnum".
447 Does not work on Unicode characters code point 256 or higher.
448 Consider using regular expressions and the "/[[:alnum:]]/"
449 construct instead, or possibly the "/\w/" construct.
450
451 isalpha This is identical to the C function, except that it can apply
452 to a single character or to a whole string. Note that locale
453 settings may affect what characters are considered "isalpha".
454 Does not work on Unicode characters code point 256 or higher.
455 Consider using regular expressions and the "/[[:alpha:]]/"
456 construct instead.
457
458 isatty Returns a boolean indicating whether the specified filehandle
459 is connected to a tty. Similar to the "-t" operator, see "-X"
460 in perlfunc.
461
462 iscntrl This is identical to the C function, except that it can apply
463 to a single character or to a whole string. Note that locale
464 settings may affect what characters are considered "iscntrl".
465 Does not work on Unicode characters code point 256 or higher.
466 Consider using regular expressions and the "/[[:cntrl:]]/"
467 construct instead.
468
469 isdigit This is identical to the C function, except that it can apply
470 to a single character or to a whole string. Note that locale
471 settings may affect what characters are considered "isdigit"
472 (unlikely, but still possible). Does not work on Unicode
473 characters code point 256 or higher. Consider using regular
474 expressions and the "/[[:digit:]]/" construct instead, or the
475 "/\d/" construct.
476
477 isgraph This is identical to the C function, except that it can apply
478 to a single character or to a whole string. Note that locale
479 settings may affect what characters are considered "isgraph".
480 Does not work on Unicode characters code point 256 or higher.
481 Consider using regular expressions and the "/[[:graph:]]/"
482 construct instead.
483
484 islower This is identical to the C function, except that it can apply
485 to a single character or to a whole string. Note that locale
486 settings may affect what characters are considered "islower".
487 Does not work on Unicode characters code point 256 or higher.
488 Consider using regular expressions and the "/[[:lower:]]/"
489 construct instead. Do not use "/[a-z]/".
490
491 isprint This is identical to the C function, except that it can apply
492 to a single character or to a whole string. Note that locale
493 settings may affect what characters are considered "isprint".
494 Does not work on Unicode characters code point 256 or higher.
495 Consider using regular expressions and the "/[[:print:]]/"
496 construct instead.
497
498 ispunct This is identical to the C function, except that it can apply
499 to a single character or to a whole string. Note that locale
500 settings may affect what characters are considered "ispunct".
501 Does not work on Unicode characters code point 256 or higher.
502 Consider using regular expressions and the "/[[:punct:]]/"
503 construct instead.
504
505 isspace This is identical to the C function, except that it can apply
506 to a single character or to a whole string. Note that locale
507 settings may affect what characters are considered "isspace".
508 Does not work on Unicode characters code point 256 or higher.
509 Consider using regular expressions and the "/[[:space:]]/"
510 construct instead, or the "/\s/" construct. (Note that "/\s/"
511 and "/[[:space:]]/" are slightly different in that
512 "/[[:space:]]/" can normally match a vertical tab, while "/\s/"
513 does not.)
514
515 isupper This is identical to the C function, except that it can apply
516 to a single character or to a whole string. Note that locale
517 settings may affect what characters are considered "isupper".
518 Does not work on Unicode characters code point 256 or higher.
519 Consider using regular expressions and the "/[[:upper:]]/"
520 construct instead. Do not use "/[A-Z]/".
521
522 isxdigit
523 This is identical to the C function, except that it can apply
524 to a single character or to a whole string. Note that locale
525 settings may affect what characters are considered "isxdigit"
526 (unlikely, but still possible). Does not work on Unicode
527 characters code point 256 or higher. Consider using regular
528 expressions and the "/[[:xdigit:]]/" construct instead, or
529 simply "/[0-9a-f]/i".
530
531 kill This is identical to Perl's builtin "kill()" function for
532 sending signals to processes (often to terminate them), see
533 "kill" in perlfunc.
534
535 labs (For returning absolute values of long integers.) labs() is
536 C-specific, see "abs" in perlfunc instead.
537
538 lchown This is identical to the C function, except the order of
539 arguments is consistent with Perl's builtin "chown()" with the
540 added restriction of only one path, not an list of paths. Does
541 the same thing as the "chown()" function but changes the owner
542 of a symbolic link instead of the file the symbolic link points
543 to.
544
545 ldexp This is identical to the C function "ldexp()" for multiplying
546 floating point numbers with powers of two.
547
548 $x_quadrupled = POSIX::ldexp($x, 2);
549
550 ldiv (For computing dividends of long integers.) ldiv() is
551 C-specific, use "/" and "int()" instead.
552
553 link This is identical to Perl's builtin "link()" function for
554 creating hard links into files, see "link" in perlfunc.
555
556 localeconv
557 Get numeric formatting information. Returns a reference to a
558 hash containing the current locale formatting values.
559
560 Here is how to query the database for the de (Deutsch or
561 German) locale.
562
563 $loc = POSIX::setlocale( &POSIX::LC_ALL, "de" );
564 print "Locale = $loc\n";
565 $lconv = POSIX::localeconv();
566 print "decimal_point = ", $lconv->{decimal_point}, "\n";
567 print "thousands_sep = ", $lconv->{thousands_sep}, "\n";
568 print "grouping = ", $lconv->{grouping}, "\n";
569 print "int_curr_symbol = ", $lconv->{int_curr_symbol}, "\n";
570 print "currency_symbol = ", $lconv->{currency_symbol}, "\n";
571 print "mon_decimal_point = ", $lconv->{mon_decimal_point}, "\n";
572 print "mon_thousands_sep = ", $lconv->{mon_thousands_sep}, "\n";
573 print "mon_grouping = ", $lconv->{mon_grouping}, "\n";
574 print "positive_sign = ", $lconv->{positive_sign}, "\n";
575 print "negative_sign = ", $lconv->{negative_sign}, "\n";
576 print "int_frac_digits = ", $lconv->{int_frac_digits}, "\n";
577 print "frac_digits = ", $lconv->{frac_digits}, "\n";
578 print "p_cs_precedes = ", $lconv->{p_cs_precedes}, "\n";
579 print "p_sep_by_space = ", $lconv->{p_sep_by_space}, "\n";
580 print "n_cs_precedes = ", $lconv->{n_cs_precedes}, "\n";
581 print "n_sep_by_space = ", $lconv->{n_sep_by_space}, "\n";
582 print "p_sign_posn = ", $lconv->{p_sign_posn}, "\n";
583 print "n_sign_posn = ", $lconv->{n_sign_posn}, "\n";
584
585 localtime
586 This is identical to Perl's builtin "localtime()" function for
587 converting seconds since the epoch to a date see "localtime" in
588 perlfunc.
589
590 log This is identical to Perl's builtin "log()" function, returning
591 the natural (e-based) logarithm of the numerical argument, see
592 "log" in perlfunc.
593
594 log10 This is identical to the C function "log10()", returning the
595 10-base logarithm of the numerical argument. You can also use
596
597 sub log10 { log($_[0]) / log(10) }
598
599 or
600
601 sub log10 { log($_[0]) / 2.30258509299405 }
602
603 or
604
605 sub log10 { log($_[0]) * 0.434294481903252 }
606
607 longjmp longjmp() is C-specific: use "die" in perlfunc instead.
608
609 lseek Move the file's read/write position. This uses file
610 descriptors such as those obtained by calling "POSIX::open".
611
612 $fd = POSIX::open( "foo", &POSIX::O_RDONLY );
613 $off_t = POSIX::lseek( $fd, 0, &POSIX::SEEK_SET );
614
615 Returns "undef" on failure.
616
617 malloc malloc() is C-specific. Perl does memory management
618 transparently.
619
620 mblen This is identical to the C function "mblen()". Perl does not
621 have any support for the wide and multibyte characters of the C
622 standards, so this might be a rather useless function.
623
624 mbstowcs
625 This is identical to the C function "mbstowcs()". Perl does
626 not have any support for the wide and multibyte characters of
627 the C standards, so this might be a rather useless function.
628
629 mbtowc This is identical to the C function "mbtowc()". Perl does not
630 have any support for the wide and multibyte characters of the C
631 standards, so this might be a rather useless function.
632
633 memchr memchr() is C-specific, see "index" in perlfunc instead.
634
635 memcmp memcmp() is C-specific, use "eq" instead, see perlop.
636
637 memcpy memcpy() is C-specific, use "=", see perlop, or see "substr" in
638 perlfunc.
639
640 memmove memmove() is C-specific, use "=", see perlop, or see "substr"
641 in perlfunc.
642
643 memset memset() is C-specific, use "x" instead, see perlop.
644
645 mkdir This is identical to Perl's builtin "mkdir()" function for
646 creating directories, see "mkdir" in perlfunc.
647
648 mkfifo This is similar to the C function "mkfifo()" for creating FIFO
649 special files.
650
651 if (mkfifo($path, $mode)) { ....
652
653 Returns "undef" on failure. The $mode is similar to the mode
654 of "mkdir()", see "mkdir" in perlfunc, though for "mkfifo" you
655 must specify the $mode.
656
657 mktime Convert date/time info to a calendar time.
658
659 Synopsis:
660
661 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
662
663 The month ("mon"), weekday ("wday"), and yearday ("yday") begin
664 at zero. I.e. January is 0, not 1; Sunday is 0, not 1; January
665 1st is 0, not 1. The year ("year") is given in years since
666 1900. I.e. The year 1995 is 95; the year 2001 is 101. Consult
667 your system's "mktime()" manpage for details about these and
668 the other arguments.
669
670 Calendar time for December 12, 1995, at 10:30 am.
671
672 $time_t = POSIX::mktime( 0, 30, 10, 12, 11, 95 );
673 print "Date = ", POSIX::ctime($time_t);
674
675 Returns "undef" on failure.
676
677 modf Return the integral and fractional parts of a floating-point
678 number.
679
680 ($fractional, $integral) = POSIX::modf( 3.14 );
681
682 nice This is similar to the C function "nice()", for changing the
683 scheduling preference of the current process. Positive
684 arguments mean more polite process, negative values more needy
685 process. Normal user processes can only be more polite.
686
687 Returns "undef" on failure.
688
689 offsetof
690 offsetof() is C-specific, you probably want to see "pack" in
691 perlfunc instead.
692
693 open Open a file for reading for writing. This returns file
694 descriptors, not Perl filehandles. Use "POSIX::close" to close
695 the file.
696
697 Open a file read-only with mode 0666.
698
699 $fd = POSIX::open( "foo" );
700
701 Open a file for read and write.
702
703 $fd = POSIX::open( "foo", &POSIX::O_RDWR );
704
705 Open a file for write, with truncation.
706
707 $fd = POSIX::open( "foo", &POSIX::O_WRONLY | &POSIX::O_TRUNC );
708
709 Create a new file with mode 0640. Set up the file for writing.
710
711 $fd = POSIX::open( "foo", &POSIX::O_CREAT | &POSIX::O_WRONLY, 0640 );
712
713 Returns "undef" on failure.
714
715 See also "sysopen" in perlfunc.
716
717 opendir Open a directory for reading.
718
719 $dir = POSIX::opendir( "/var" );
720 @files = POSIX::readdir( $dir );
721 POSIX::closedir( $dir );
722
723 Returns "undef" on failure.
724
725 pathconf
726 Retrieves the value of a configurable limit on a file or
727 directory.
728
729 The following will determine the maximum length of the longest
730 allowable pathname on the filesystem which holds "/var".
731
732 $path_max = POSIX::pathconf( "/var", &POSIX::_PC_PATH_MAX );
733
734 Returns "undef" on failure.
735
736 pause This is similar to the C function "pause()", which suspends the
737 execution of the current process until a signal is received.
738
739 Returns "undef" on failure.
740
741 perror This is identical to the C function "perror()", which outputs
742 to the standard error stream the specified message followed by
743 ": " and the current error string. Use the "warn()" function
744 and the $! variable instead, see "warn" in perlfunc and
745 "$ERRNO" in perlvar.
746
747 pipe Create an interprocess channel. This returns file descriptors
748 like those returned by "POSIX::open".
749
750 my ($read, $write) = POSIX::pipe();
751 POSIX::write( $write, "hello", 5 );
752 POSIX::read( $read, $buf, 5 );
753
754 See also "pipe" in perlfunc.
755
756 pow Computes $x raised to the power $exponent.
757
758 $ret = POSIX::pow( $x, $exponent );
759
760 You can also use the "**" operator, see perlop.
761
762 printf Formats and prints the specified arguments to STDOUT. See also
763 "printf" in perlfunc.
764
765 putc putc() is C-specific, see "print" in perlfunc instead.
766
767 putchar putchar() is C-specific, see "print" in perlfunc instead.
768
769 puts puts() is C-specific, see "print" in perlfunc instead.
770
771 qsort qsort() is C-specific, see "sort" in perlfunc instead.
772
773 raise Sends the specified signal to the current process. See also
774 "kill" in perlfunc and the $$ in "$PID" in perlvar.
775
776 rand "rand()" is non-portable, see "rand" in perlfunc instead.
777
778 read Read from a file. This uses file descriptors such as those
779 obtained by calling "POSIX::open". If the buffer $buf is not
780 large enough for the read then Perl will extend it to make room
781 for the request.
782
783 $fd = POSIX::open( "foo", &POSIX::O_RDONLY );
784 $bytes = POSIX::read( $fd, $buf, 3 );
785
786 Returns "undef" on failure.
787
788 See also "sysread" in perlfunc.
789
790 readdir This is identical to Perl's builtin "readdir()" function for
791 reading directory entries, see "readdir" in perlfunc.
792
793 realloc realloc() is C-specific. Perl does memory management
794 transparently.
795
796 remove This is identical to Perl's builtin "unlink()" function for
797 removing files, see "unlink" in perlfunc.
798
799 rename This is identical to Perl's builtin "rename()" function for
800 renaming files, see "rename" in perlfunc.
801
802 rewind Seeks to the beginning of the file.
803
804 rewinddir
805 This is identical to Perl's builtin "rewinddir()" function for
806 rewinding directory entry streams, see "rewinddir" in perlfunc.
807
808 rmdir This is identical to Perl's builtin "rmdir()" function for
809 removing (empty) directories, see "rmdir" in perlfunc.
810
811 scanf scanf() is C-specific, use <> and regular expressions instead,
812 see perlre.
813
814 setgid Sets the real group identifier and the effective group
815 identifier for this process. Similar to assigning a value to
816 the Perl's builtin $) variable, see "$EGID" in perlvar, except
817 that the latter will change only the real user identifier, and
818 that the setgid() uses only a single numeric argument, as
819 opposed to a space-separated list of numbers.
820
821 setjmp "setjmp()" is C-specific: use "eval {}" instead, see "eval" in
822 perlfunc.
823
824 setlocale
825 Modifies and queries program's locale. The following examples
826 assume
827
828 use POSIX qw(setlocale LC_ALL LC_CTYPE);
829
830 has been issued.
831
832 The following will set the traditional UNIX system locale
833 behavior (the second argument "C").
834
835 $loc = setlocale( LC_ALL, "C" );
836
837 The following will query the current LC_CTYPE category. (No
838 second argument means 'query'.)
839
840 $loc = setlocale( LC_CTYPE );
841
842 The following will set the LC_CTYPE behaviour according to the
843 locale environment variables (the second argument ""). Please
844 see your systems setlocale(3) documentation for the locale
845 environment variables' meaning or consult perllocale.
846
847 $loc = setlocale( LC_CTYPE, "" );
848
849 The following will set the LC_COLLATE behaviour to Argentinian
850 Spanish. NOTE: The naming and availability of locales depends
851 on your operating system. Please consult perllocale for how to
852 find out which locales are available in your system.
853
854 $loc = setlocale( LC_COLLATE, "es_AR.ISO8859-1" );
855
856 setpgid This is similar to the C function "setpgid()" for setting the
857 process group identifier of the current process.
858
859 Returns "undef" on failure.
860
861 setsid This is identical to the C function "setsid()" for setting the
862 session identifier of the current process.
863
864 setuid Sets the real user identifier and the effective user identifier
865 for this process. Similar to assigning a value to the Perl's
866 builtin $< variable, see "$UID" in perlvar, except that the
867 latter will change only the real user identifier.
868
869 sigaction
870 Detailed signal management. This uses "POSIX::SigAction"
871 objects for the "action" and "oldaction" arguments (the
872 oldaction can also be just a hash reference). Consult your
873 system's "sigaction" manpage for details, see also
874 "POSIX::SigRt".
875
876 Synopsis:
877
878 sigaction(signal, action, oldaction = 0)
879
880 Returns "undef" on failure. The "signal" must be a number
881 (like SIGHUP), not a string (like "SIGHUP"), though Perl does
882 try hard to understand you.
883
884 If you use the SA_SIGINFO flag, the signal handler will in
885 addition to the first argument, the signal name, also receive a
886 second argument, a hash reference, inside which are the
887 following keys with the following semantics, as defined by
888 POSIX/SUSv3:
889
890 signo the signal number
891 errno the error number
892 code if this is zero or less, the signal was sent by
893 a user process and the uid and pid make sense,
894 otherwise the signal was sent by the kernel
895
896 The following are also defined by POSIX/SUSv3, but
897 unfortunately not very widely implemented:
898
899 pid the process id generating the signal
900 uid the uid of the process id generating the signal
901 status exit value or signal for SIGCHLD
902 band band event for SIGPOLL
903
904 A third argument is also passed to the handler, which contains
905 a copy of the raw binary contents of the siginfo structure: if
906 a system has some non-POSIX fields, this third argument is
907 where to unpack() them from.
908
909 Note that not all siginfo values make sense simultaneously
910 (some are valid only for certain signals, for example), and not
911 all values make sense from Perl perspective, you should to
912 consult your system's "sigaction" and possibly also "siginfo"
913 documentation.
914
915 siglongjmp
916 siglongjmp() is C-specific: use "die" in perlfunc instead.
917
918 sigpending
919 Examine signals that are blocked and pending. This uses
920 "POSIX::SigSet" objects for the "sigset" argument. Consult
921 your system's "sigpending" manpage for details.
922
923 Synopsis:
924
925 sigpending(sigset)
926
927 Returns "undef" on failure.
928
929 sigprocmask
930 Change and/or examine calling process's signal mask. This uses
931 "POSIX::SigSet" objects for the "sigset" and "oldsigset"
932 arguments. Consult your system's "sigprocmask" manpage for
933 details.
934
935 Synopsis:
936
937 sigprocmask(how, sigset, oldsigset = 0)
938
939 Returns "undef" on failure.
940
941 Note that you can't reliably block or unblock a signal from its
942 own signal handler if you're using safe signals. Other signals
943 can be blocked or unblocked reliably.
944
945 sigsetjmp
946 "sigsetjmp()" is C-specific: use "eval {}" instead, see "eval"
947 in perlfunc.
948
949 sigsuspend
950 Install a signal mask and suspend process until signal arrives.
951 This uses "POSIX::SigSet" objects for the "signal_mask"
952 argument. Consult your system's "sigsuspend" manpage for
953 details.
954
955 Synopsis:
956
957 sigsuspend(signal_mask)
958
959 Returns "undef" on failure.
960
961 sin This is identical to Perl's builtin "sin()" function for
962 returning the sine of the numerical argument, see "sin" in
963 perlfunc. See also Math::Trig.
964
965 sinh This is identical to the C function "sinh()" for returning the
966 hyperbolic sine of the numerical argument. See also
967 Math::Trig.
968
969 sleep This is functionally identical to Perl's builtin "sleep()"
970 function for suspending the execution of the current for
971 process for certain number of seconds, see "sleep" in perlfunc.
972 There is one significant difference, however: "POSIX::sleep()"
973 returns the number of unslept seconds, while the
974 "CORE::sleep()" returns the number of slept seconds.
975
976 sprintf This is similar to Perl's builtin "sprintf()" function for
977 returning a string that has the arguments formatted as
978 requested, see "sprintf" in perlfunc.
979
980 sqrt This is identical to Perl's builtin "sqrt()" function. for
981 returning the square root of the numerical argument, see "sqrt"
982 in perlfunc.
983
984 srand Give a seed the pseudorandom number generator, see "srand" in
985 perlfunc.
986
987 sscanf sscanf() is C-specific, use regular expressions instead, see
988 perlre.
989
990 stat This is identical to Perl's builtin "stat()" function for
991 returning information about files and directories.
992
993 strcat strcat() is C-specific, use ".=" instead, see perlop.
994
995 strchr strchr() is C-specific, see "index" in perlfunc instead.
996
997 strcmp strcmp() is C-specific, use "eq" or "cmp" instead, see perlop.
998
999 strcoll This is identical to the C function "strcoll()" for collating
1000 (comparing) strings transformed using the "strxfrm()" function.
1001 Not really needed since Perl can do this transparently, see
1002 perllocale.
1003
1004 strcpy strcpy() is C-specific, use "=" instead, see perlop.
1005
1006 strcspn strcspn() is C-specific, use regular expressions instead, see
1007 perlre.
1008
1009 strerror
1010 Returns the error string for the specified errno. Identical to
1011 the string form of the $!, see "$ERRNO" in perlvar.
1012
1013 strftime
1014 Convert date and time information to string. Returns the
1015 string.
1016
1017 Synopsis:
1018
1019 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1020
1021 The month ("mon"), weekday ("wday"), and yearday ("yday") begin
1022 at zero. I.e. January is 0, not 1; Sunday is 0, not 1; January
1023 1st is 0, not 1. The year ("year") is given in years since
1024 1900. I.e., the year 1995 is 95; the year 2001 is 101.
1025 Consult your system's "strftime()" manpage for details about
1026 these and the other arguments.
1027
1028 If you want your code to be portable, your format ("fmt")
1029 argument should use only the conversion specifiers defined by
1030 the ANSI C standard (C89, to play safe). These are
1031 "aAbBcdHIjmMpSUwWxXyYZ%". But even then, the results of some
1032 of the conversion specifiers are non-portable. For example,
1033 the specifiers "aAbBcpZ" change according to the locale
1034 settings of the user, and both how to set locales (the locale
1035 names) and what output to expect are non-standard. The
1036 specifier "c" changes according to the timezone settings of the
1037 user and the timezone computation rules of the operating
1038 system. The "Z" specifier is notoriously unportable since the
1039 names of timezones are non-standard. Sticking to the numeric
1040 specifiers is the safest route.
1041
1042 The given arguments are made consistent as though by calling
1043 "mktime()" before calling your system's "strftime()" function,
1044 except that the "isdst" value is not affected.
1045
1046 The string for Tuesday, December 12, 1995.
1047
1048 $str = POSIX::strftime( "%A, %B %d, %Y", 0, 0, 0, 12, 11, 95, 2 );
1049 print "$str\n";
1050
1051 strlen strlen() is C-specific, use "length()" instead, see "length" in
1052 perlfunc.
1053
1054 strncat strncat() is C-specific, use ".=" instead, see perlop.
1055
1056 strncmp strncmp() is C-specific, use "eq" instead, see perlop.
1057
1058 strncpy strncpy() is C-specific, use "=" instead, see perlop.
1059
1060 strpbrk strpbrk() is C-specific, use regular expressions instead, see
1061 perlre.
1062
1063 strrchr strrchr() is C-specific, see "rindex" in perlfunc instead.
1064
1065 strspn strspn() is C-specific, use regular expressions instead, see
1066 perlre.
1067
1068 strstr This is identical to Perl's builtin "index()" function, see
1069 "index" in perlfunc.
1070
1071 strtod String to double translation. Returns the parsed number and the
1072 number of characters in the unparsed portion of the string.
1073 Truly POSIX-compliant systems set $! ($ERRNO) to indicate a
1074 translation error, so clear $! before calling strtod. However,
1075 non-POSIX systems may not check for overflow, and therefore
1076 will never set $!.
1077
1078 strtod should respect any POSIX setlocale() settings.
1079
1080 To parse a string $str as a floating point number use
1081
1082 $! = 0;
1083 ($num, $n_unparsed) = POSIX::strtod($str);
1084
1085 The second returned item and $! can be used to check for valid
1086 input:
1087
1088 if (($str eq '') || ($n_unparsed != 0) || $!) {
1089 die "Non-numeric input $str" . ($! ? ": $!\n" : "\n");
1090 }
1091
1092 When called in a scalar context strtod returns the parsed
1093 number.
1094
1095 strtok strtok() is C-specific, use regular expressions instead, see
1096 perlre, or "split" in perlfunc.
1097
1098 strtol String to (long) integer translation. Returns the parsed
1099 number and the number of characters in the unparsed portion of
1100 the string. Truly POSIX-compliant systems set $! ($ERRNO) to
1101 indicate a translation error, so clear $! before calling
1102 strtol. However, non-POSIX systems may not check for overflow,
1103 and therefore will never set $!.
1104
1105 strtol should respect any POSIX setlocale() settings.
1106
1107 To parse a string $str as a number in some base $base use
1108
1109 $! = 0;
1110 ($num, $n_unparsed) = POSIX::strtol($str, $base);
1111
1112 The base should be zero or between 2 and 36, inclusive. When
1113 the base is zero or omitted strtol will use the string itself
1114 to determine the base: a leading "0x" or "0X" means
1115 hexadecimal; a leading "0" means octal; any other leading
1116 characters mean decimal. Thus, "1234" is parsed as a decimal
1117 number, "01234" as an octal number, and "0x1234" as a
1118 hexadecimal number.
1119
1120 The second returned item and $! can be used to check for valid
1121 input:
1122
1123 if (($str eq '') || ($n_unparsed != 0) || !$!) {
1124 die "Non-numeric input $str" . $! ? ": $!\n" : "\n";
1125 }
1126
1127 When called in a scalar context strtol returns the parsed
1128 number.
1129
1130 strtoul String to unsigned (long) integer translation. strtoul() is
1131 identical to strtol() except that strtoul() only parses
1132 unsigned integers. See "strtol" for details.
1133
1134 Note: Some vendors supply strtod() and strtol() but not
1135 strtoul(). Other vendors that do supply strtoul() parse "-1"
1136 as a valid value.
1137
1138 strxfrm String transformation. Returns the transformed string.
1139
1140 $dst = POSIX::strxfrm( $src );
1141
1142 Used in conjunction with the "strcoll()" function, see
1143 "strcoll".
1144
1145 Not really needed since Perl can do this transparently, see
1146 perllocale.
1147
1148 sysconf Retrieves values of system configurable variables.
1149
1150 The following will get the machine's clock speed.
1151
1152 $clock_ticks = POSIX::sysconf( &POSIX::_SC_CLK_TCK );
1153
1154 Returns "undef" on failure.
1155
1156 system This is identical to Perl's builtin "system()" function, see
1157 "system" in perlfunc.
1158
1159 tan This is identical to the C function "tan()", returning the
1160 tangent of the numerical argument. See also Math::Trig.
1161
1162 tanh This is identical to the C function "tanh()", returning the
1163 hyperbolic tangent of the numerical argument. See also
1164 Math::Trig.
1165
1166 tcdrain This is similar to the C function "tcdrain()" for draining the
1167 output queue of its argument stream.
1168
1169 Returns "undef" on failure.
1170
1171 tcflow This is similar to the C function "tcflow()" for controlling
1172 the flow of its argument stream.
1173
1174 Returns "undef" on failure.
1175
1176 tcflush This is similar to the C function "tcflush()" for flushing the
1177 I/O buffers of its argument stream.
1178
1179 Returns "undef" on failure.
1180
1181 tcgetpgrp
1182 This is identical to the C function "tcgetpgrp()" for returning
1183 the process group identifier of the foreground process group of
1184 the controlling terminal.
1185
1186 tcsendbreak
1187 This is similar to the C function "tcsendbreak()" for sending a
1188 break on its argument stream.
1189
1190 Returns "undef" on failure.
1191
1192 tcsetpgrp
1193 This is similar to the C function "tcsetpgrp()" for setting the
1194 process group identifier of the foreground process group of the
1195 controlling terminal.
1196
1197 Returns "undef" on failure.
1198
1199 time This is identical to Perl's builtin "time()" function for
1200 returning the number of seconds since the epoch (whatever it is
1201 for the system), see "time" in perlfunc.
1202
1203 times The times() function returns elapsed realtime since some point
1204 in the past (such as system startup), user and system times for
1205 this process, and user and system times used by child
1206 processes. All times are returned in clock ticks.
1207
1208 ($realtime, $user, $system, $cuser, $csystem) = POSIX::times();
1209
1210 Note: Perl's builtin "times()" function returns four values,
1211 measured in seconds.
1212
1213 tmpfile Use method "IO::File::new_tmpfile()" instead, or see
1214 File::Temp.
1215
1216 tmpnam Returns a name for a temporary file.
1217
1218 $tmpfile = POSIX::tmpnam();
1219
1220 For security reasons, which are probably detailed in your
1221 system's documentation for the C library tmpnam() function,
1222 this interface should not be used; instead see File::Temp.
1223
1224 tolower This is identical to the C function, except that it can apply
1225 to a single character or to a whole string. Consider using the
1226 "lc()" function, see "lc" in perlfunc, or the equivalent "\L"
1227 operator inside doublequotish strings.
1228
1229 toupper This is identical to the C function, except that it can apply
1230 to a single character or to a whole string. Consider using the
1231 "uc()" function, see "uc" in perlfunc, or the equivalent "\U"
1232 operator inside doublequotish strings.
1233
1234 ttyname This is identical to the C function "ttyname()" for returning
1235 the name of the current terminal.
1236
1237 tzname Retrieves the time conversion information from the "tzname"
1238 variable.
1239
1240 POSIX::tzset();
1241 ($std, $dst) = POSIX::tzname();
1242
1243 tzset This is identical to the C function "tzset()" for setting the
1244 current timezone based on the environment variable "TZ", to be
1245 used by "ctime()", "localtime()", "mktime()", and "strftime()"
1246 functions.
1247
1248 umask This is identical to Perl's builtin "umask()" function for
1249 setting (and querying) the file creation permission mask, see
1250 "umask" in perlfunc.
1251
1252 uname Get name of current operating system.
1253
1254 ($sysname, $nodename, $release, $version, $machine) = POSIX::uname();
1255
1256 Note that the actual meanings of the various fields are not
1257 that well standardized, do not expect any great portability.
1258 The $sysname might be the name of the operating system, the
1259 $nodename might be the name of the host, the $release might be
1260 the (major) release number of the operating system, the
1261 $version might be the (minor) release number of the operating
1262 system, and the $machine might be a hardware identifier.
1263 Maybe.
1264
1265 ungetc Use method "IO::Handle::ungetc()" instead.
1266
1267 unlink This is identical to Perl's builtin "unlink()" function for
1268 removing files, see "unlink" in perlfunc.
1269
1270 utime This is identical to Perl's builtin "utime()" function for
1271 changing the time stamps of files and directories, see "utime"
1272 in perlfunc.
1273
1274 vfprintf
1275 vfprintf() is C-specific, see "printf" in perlfunc instead.
1276
1277 vprintf vprintf() is C-specific, see "printf" in perlfunc instead.
1278
1279 vsprintf
1280 vsprintf() is C-specific, see "sprintf" in perlfunc instead.
1281
1282 wait This is identical to Perl's builtin "wait()" function, see
1283 "wait" in perlfunc.
1284
1285 waitpid Wait for a child process to change state. This is identical to
1286 Perl's builtin "waitpid()" function, see "waitpid" in perlfunc.
1287
1288 $pid = POSIX::waitpid( -1, POSIX::WNOHANG );
1289 print "status = ", ($? / 256), "\n";
1290
1291 wcstombs
1292 This is identical to the C function "wcstombs()". Perl does
1293 not have any support for the wide and multibyte characters of
1294 the C standards, so this might be a rather useless function.
1295
1296 wctomb This is identical to the C function "wctomb()". Perl does not
1297 have any support for the wide and multibyte characters of the C
1298 standards, so this might be a rather useless function.
1299
1300 write Write to a file. This uses file descriptors such as those
1301 obtained by calling "POSIX::open".
1302
1303 $fd = POSIX::open( "foo", &POSIX::O_WRONLY );
1304 $buf = "hello";
1305 $bytes = POSIX::write( $fd, $buf, 5 );
1306
1307 Returns "undef" on failure.
1308
1309 See also "syswrite" in perlfunc.
1310
1312 POSIX::SigAction
1313 new Creates a new "POSIX::SigAction" object which corresponds to
1314 the C "struct sigaction". This object will be destroyed
1315 automatically when it is no longer needed. The first parameter
1316 is the handler, a sub reference. The second parameter is a
1317 "POSIX::SigSet" object, it defaults to the empty set. The
1318 third parameter contains the "sa_flags", it defaults to 0.
1319
1320 $sigset = POSIX::SigSet->new(SIGINT, SIGQUIT);
1321 $sigaction = POSIX::SigAction->new( \&handler, $sigset, &POSIX::SA_NOCLDSTOP );
1322
1323 This "POSIX::SigAction" object is intended for use with the
1324 "POSIX::sigaction()" function.
1325
1326 handler
1327 mask
1328 flags accessor functions to get/set the values of a SigAction object.
1329
1330 $sigset = $sigaction->mask;
1331 $sigaction->flags(&POSIX::SA_RESTART);
1332
1333 safe accessor function for the "safe signals" flag of a SigAction
1334 object; see perlipc for general information on safe (a.k.a.
1335 "deferred") signals. If you wish to handle a signal safely,
1336 use this accessor to set the "safe" flag in the
1337 "POSIX::SigAction" object:
1338
1339 $sigaction->safe(1);
1340
1341 You may also examine the "safe" flag on the output action
1342 object which is filled in when given as the third parameter to
1343 "POSIX::sigaction()":
1344
1345 sigaction(SIGINT, $new_action, $old_action);
1346 if ($old_action->safe) {
1347 # previous SIGINT handler used safe signals
1348 }
1349
1350 POSIX::SigRt
1351 %SIGRT A hash of the POSIX realtime signal handlers. It is an
1352 extension of the standard %SIG, the $POSIX::SIGRT{SIGRTMIN} is
1353 roughly equivalent to $SIG{SIGRTMIN}, but the right POSIX moves
1354 (see below) are made with the POSIX::SigSet and
1355 POSIX::sigaction instead of accessing the %SIG.
1356
1357 You can set the %POSIX::SIGRT elements to set the POSIX
1358 realtime signal handlers, use "delete" and "exists" on the
1359 elements, and use "scalar" on the %POSIX::SIGRT to find out how
1360 many POSIX realtime signals there are available (SIGRTMAX -
1361 SIGRTMIN + 1, the SIGRTMAX is a valid POSIX realtime signal).
1362
1363 Setting the %SIGRT elements is equivalent to calling this:
1364
1365 sub new {
1366 my ($rtsig, $handler, $flags) = @_;
1367 my $sigset = POSIX::SigSet($rtsig);
1368 my $sigact = POSIX::SigAction->new($handler, $sigset, $flags);
1369 sigaction($rtsig, $sigact);
1370 }
1371
1372 The flags default to zero, if you want something different you
1373 can either use "local" on $POSIX::SigRt::SIGACTION_FLAGS, or
1374 you can derive from POSIX::SigRt and define your own "new()"
1375 (the tied hash STORE method of the %SIGRT calls "new($rtsig,
1376 $handler, $SIGACTION_FLAGS)", where the $rtsig ranges from zero
1377 to SIGRTMAX - SIGRTMIN + 1).
1378
1379 Just as with any signal, you can use sigaction($rtsig, undef,
1380 $oa) to retrieve the installed signal handler (or, rather, the
1381 signal action).
1382
1383 NOTE: whether POSIX realtime signals really work in your
1384 system, or whether Perl has been compiled so that it works with
1385 them, is outside of this discussion.
1386
1387 SIGRTMIN
1388 Return the minimum POSIX realtime signal number available, or
1389 "undef" if no POSIX realtime signals are available.
1390
1391 SIGRTMAX
1392 Return the maximum POSIX realtime signal number available, or
1393 "undef" if no POSIX realtime signals are available.
1394
1395 POSIX::SigSet
1396 new Create a new SigSet object. This object will be destroyed
1397 automatically when it is no longer needed. Arguments may be
1398 supplied to initialize the set.
1399
1400 Create an empty set.
1401
1402 $sigset = POSIX::SigSet->new;
1403
1404 Create a set with SIGUSR1.
1405
1406 $sigset = POSIX::SigSet->new( &POSIX::SIGUSR1 );
1407
1408 addset Add a signal to a SigSet object.
1409
1410 $sigset->addset( &POSIX::SIGUSR2 );
1411
1412 Returns "undef" on failure.
1413
1414 delset Remove a signal from the SigSet object.
1415
1416 $sigset->delset( &POSIX::SIGUSR2 );
1417
1418 Returns "undef" on failure.
1419
1420 emptyset
1421 Initialize the SigSet object to be empty.
1422
1423 $sigset->emptyset();
1424
1425 Returns "undef" on failure.
1426
1427 fillset Initialize the SigSet object to include all signals.
1428
1429 $sigset->fillset();
1430
1431 Returns "undef" on failure.
1432
1433 ismember
1434 Tests the SigSet object to see if it contains a specific
1435 signal.
1436
1437 if( $sigset->ismember( &POSIX::SIGUSR1 ) ){
1438 print "contains SIGUSR1\n";
1439 }
1440
1441 POSIX::Termios
1442 new Create a new Termios object. This object will be destroyed
1443 automatically when it is no longer needed. A Termios object
1444 corresponds to the termios C struct. new() mallocs a new one,
1445 getattr() fills it from a file descriptor, and setattr() sets a
1446 file descriptor's parameters to match Termios' contents.
1447
1448 $termios = POSIX::Termios->new;
1449
1450 getattr Get terminal control attributes.
1451
1452 Obtain the attributes for stdin.
1453
1454 $termios->getattr( 0 ) # Recommended for clarity.
1455 $termios->getattr()
1456
1457 Obtain the attributes for stdout.
1458
1459 $termios->getattr( 1 )
1460
1461 Returns "undef" on failure.
1462
1463 getcc Retrieve a value from the c_cc field of a termios object. The
1464 c_cc field is an array so an index must be specified.
1465
1466 $c_cc[1] = $termios->getcc(1);
1467
1468 getcflag
1469 Retrieve the c_cflag field of a termios object.
1470
1471 $c_cflag = $termios->getcflag;
1472
1473 getiflag
1474 Retrieve the c_iflag field of a termios object.
1475
1476 $c_iflag = $termios->getiflag;
1477
1478 getispeed
1479 Retrieve the input baud rate.
1480
1481 $ispeed = $termios->getispeed;
1482
1483 getlflag
1484 Retrieve the c_lflag field of a termios object.
1485
1486 $c_lflag = $termios->getlflag;
1487
1488 getoflag
1489 Retrieve the c_oflag field of a termios object.
1490
1491 $c_oflag = $termios->getoflag;
1492
1493 getospeed
1494 Retrieve the output baud rate.
1495
1496 $ospeed = $termios->getospeed;
1497
1498 setattr Set terminal control attributes.
1499
1500 Set attributes immediately for stdout.
1501
1502 $termios->setattr( 1, &POSIX::TCSANOW );
1503
1504 Returns "undef" on failure.
1505
1506 setcc Set a value in the c_cc field of a termios object. The c_cc
1507 field is an array so an index must be specified.
1508
1509 $termios->setcc( &POSIX::VEOF, 1 );
1510
1511 setcflag
1512 Set the c_cflag field of a termios object.
1513
1514 $termios->setcflag( $c_cflag | &POSIX::CLOCAL );
1515
1516 setiflag
1517 Set the c_iflag field of a termios object.
1518
1519 $termios->setiflag( $c_iflag | &POSIX::BRKINT );
1520
1521 setispeed
1522 Set the input baud rate.
1523
1524 $termios->setispeed( &POSIX::B9600 );
1525
1526 Returns "undef" on failure.
1527
1528 setlflag
1529 Set the c_lflag field of a termios object.
1530
1531 $termios->setlflag( $c_lflag | &POSIX::ECHO );
1532
1533 setoflag
1534 Set the c_oflag field of a termios object.
1535
1536 $termios->setoflag( $c_oflag | &POSIX::OPOST );
1537
1538 setospeed
1539 Set the output baud rate.
1540
1541 $termios->setospeed( &POSIX::B9600 );
1542
1543 Returns "undef" on failure.
1544
1545 Baud rate values
1546 B38400 B75 B200 B134 B300 B1800 B150 B0 B19200 B1200 B9600 B600
1547 B4800 B50 B2400 B110
1548
1549 Terminal interface values
1550 TCSADRAIN TCSANOW TCOON TCIOFLUSH TCOFLUSH TCION TCIFLUSH
1551 TCSAFLUSH TCIOFF TCOOFF
1552
1553 c_cc field values
1554 VEOF VEOL VERASE VINTR VKILL VQUIT VSUSP VSTART VSTOP VMIN
1555 VTIME NCCS
1556
1557 c_cflag field values
1558 CLOCAL CREAD CSIZE CS5 CS6 CS7 CS8 CSTOPB HUPCL PARENB PARODD
1559
1560 c_iflag field values
1561 BRKINT ICRNL IGNBRK IGNCR IGNPAR INLCR INPCK ISTRIP IXOFF IXON
1562 PARMRK
1563
1564 c_lflag field values
1565 ECHO ECHOE ECHOK ECHONL ICANON IEXTEN ISIG NOFLSH TOSTOP
1566
1567 c_oflag field values
1568 OPOST
1569
1571 Constants
1572 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON _PC_MAX_INPUT
1573 _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX _PC_PIPE_BUF
1574 _PC_VDISABLE
1575
1577 Constants
1578 _POSIX_ARG_MAX _POSIX_CHILD_MAX _POSIX_CHOWN_RESTRICTED
1579 _POSIX_JOB_CONTROL _POSIX_LINK_MAX _POSIX_MAX_CANON
1580 _POSIX_MAX_INPUT _POSIX_NAME_MAX _POSIX_NGROUPS_MAX
1581 _POSIX_NO_TRUNC _POSIX_OPEN_MAX _POSIX_PATH_MAX _POSIX_PIPE_BUF
1582 _POSIX_SAVED_IDS _POSIX_SSIZE_MAX _POSIX_STREAM_MAX
1583 _POSIX_TZNAME_MAX _POSIX_VDISABLE _POSIX_VERSION
1584
1586 Constants
1587 _SC_ARG_MAX _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
1588 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_PAGESIZE _SC_SAVED_IDS
1589 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
1590
1592 Constants
1593 E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT EAGAIN
1594 EALREADY EBADF EBUSY ECHILD ECONNABORTED ECONNREFUSED
1595 ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT EEXIST EFAULT EFBIG
1596 EHOSTDOWN EHOSTUNREACH EINPROGRESS EINTR EINVAL EIO EISCONN
1597 EISDIR ELOOP EMFILE EMLINK EMSGSIZE ENAMETOOLONG ENETDOWN
1598 ENETRESET ENETUNREACH ENFILE ENOBUFS ENODEV ENOENT ENOEXEC
1599 ENOLCK ENOMEM ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN
1600 ENOTDIR ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
1601 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE ERANGE
1602 EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT ESPIPE ESRCH
1603 ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY EUSERS EWOULDBLOCK EXDEV
1604
1606 Constants
1607 FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_OK F_RDLCK F_SETFD
1608 F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK O_ACCMODE O_APPEND
1609 O_CREAT O_EXCL O_NOCTTY O_NONBLOCK O_RDONLY O_RDWR O_TRUNC
1610 O_WRONLY
1611
1613 Constants
1614 DBL_DIG DBL_EPSILON DBL_MANT_DIG DBL_MAX DBL_MAX_10_EXP
1615 DBL_MAX_EXP DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP FLT_DIG
1616 FLT_EPSILON FLT_MANT_DIG FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
1617 FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP FLT_RADIX FLT_ROUNDS
1618 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG LDBL_MAX LDBL_MAX_10_EXP
1619 LDBL_MAX_EXP LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP
1620
1622 Constants
1623 ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX INT_MAX INT_MIN
1624 LINK_MAX LONG_MAX LONG_MIN MAX_CANON MAX_INPUT MB_LEN_MAX
1625 NAME_MAX NGROUPS_MAX OPEN_MAX PATH_MAX PIPE_BUF SCHAR_MAX
1626 SCHAR_MIN SHRT_MAX SHRT_MIN SSIZE_MAX STREAM_MAX TZNAME_MAX
1627 UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX
1628
1630 Constants
1631 LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME
1632
1634 Constants
1635 HUGE_VAL
1636
1638 Constants
1639 SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK SA_RESETHAND
1640 SA_RESTART SA_SIGINFO SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE
1641 SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV SIGSTOP
1642 SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2 SIG_BLOCK
1643 SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK
1644
1646 Constants
1647 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU S_ISGID S_ISUID
1648 S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
1649
1650 Macros S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG
1651
1653 Constants
1654 EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX RAND_MAX
1655
1657 Constants
1658 BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid L_tmpname TMP_MAX
1659
1661 Constants
1662 CLK_TCK CLOCKS_PER_SEC
1663
1665 Constants
1666 R_OK SEEK_CUR SEEK_END SEEK_SET STDIN_FILENO STDOUT_FILENO
1667 STDERR_FILENO W_OK X_OK
1668
1670 Constants
1671 WNOHANG WUNTRACED
1672
1673 WNOHANG Do not suspend the calling process until a
1674 child process changes state but instead return
1675 immediately.
1676
1677 WUNTRACED Catch stopped child processes.
1678
1679 Macros WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG WIFSTOPPED WSTOPSIG
1680
1681 WIFEXITED WIFEXITED(${^CHILD_ERROR_NATIVE}) returns true
1682 if the child process exited normally ("exit()"
1683 or by falling off the end of "main()")
1684
1685 WEXITSTATUS WEXITSTATUS(${^CHILD_ERROR_NATIVE}) returns the
1686 normal exit status of the child process (only
1687 meaningful if WIFEXITED(${^CHILD_ERROR_NATIVE})
1688 is true)
1689
1690 WIFSIGNALED WIFSIGNALED(${^CHILD_ERROR_NATIVE}) returns
1691 true if the child process terminated because of
1692 a signal
1693
1694 WTERMSIG WTERMSIG(${^CHILD_ERROR_NATIVE}) returns the
1695 signal the child process terminated for (only
1696 meaningful if
1697 WIFSIGNALED(${^CHILD_ERROR_NATIVE}) is true)
1698
1699 WIFSTOPPED WIFSTOPPED(${^CHILD_ERROR_NATIVE}) returns true
1700 if the child process is currently stopped (can
1701 happen only if you specified the WUNTRACED flag
1702 to waitpid())
1703
1704 WSTOPSIG WSTOPSIG(${^CHILD_ERROR_NATIVE}) returns the
1705 signal the child process was stopped for (only
1706 meaningful if
1707 WIFSTOPPED(${^CHILD_ERROR_NATIVE}) is true)
1708
1709
1710
1711perl v5.16.3 2013-03-04 POSIX(3pm)