diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1999-05-09 22:47:39 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-05-09 22:47:39 +0000 |
commit | 45bc920620377d5a7720d3d562c48df1eb0c2e68 (patch) | |
tree | ddf80cf0881964ffc19fe3b1f195ebfb7cc09284 /pod | |
parent | 46a8855a50eb32c89dd161fbf5c3956ca0e452d8 (diff) | |
download | perl-45bc920620377d5a7720d3d562c48df1eb0c2e68.tar.gz |
flush all open output buffers before fork(), exec(), system, qx//
and pipe open() operations, simplifying buffering headaches faced
by users; uses fflush(NULL), which may need Configure test
p4raw-id: //depot/perl@3352
Diffstat (limited to 'pod')
-rw-r--r-- | pod/perldelta.pod | 8 | ||||
-rw-r--r-- | pod/perlfunc.pod | 20 | ||||
-rw-r--r-- | pod/perlipc.pod | 4 |
3 files changed, 16 insertions, 16 deletions
diff --git a/pod/perldelta.pod b/pod/perldelta.pod index edef071da4..9fb0819cf8 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -217,6 +217,14 @@ Parsing of here documents used to be flawed when they appeared as the replacement expression in C<eval 's/.../.../e'>. This has been fixed. +=head2 Automatic flushing of output buffers + +fork(), exec(), system(), qx// and pipe open()s now flush the buffers +of all files that were opened for output at the time the operation +was attempted. The mostly eliminates the often confusing effects of +buffering mishaps suffered by users unaware of how Perl internally +handled I/O. + =head1 Supported Platforms =over 4 diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index a65e3e3e46..4d25fef4b5 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -1311,12 +1311,9 @@ the argument is checked for shell metacharacters, and if there are any, the entire argument is passed to the system's command shell for parsing (this is C</bin/sh -c> on Unix platforms, but varies on other platforms). If there are no shell metacharacters in the argument, it is split into -words and passed directly to C<execvp()>, which is more efficient. Note: -C<exec()> and C<system()> do not flush your output buffer, so you may need to -set C<$|> to avoid lost output. Examples: +words and passed directly to C<execvp()>, which is more efficient. - exec '/bin/echo', 'Your arguments are: ', @ARGV; - exec "sort $outfile | uniq"; +All files opened for output are flushed before attempting the exec(). If you don't really want to execute the first argument, but want to lie to the program you are executing about its own name, you can specify @@ -1542,9 +1539,7 @@ fork(), great care has gone into making it extremely efficient (for example, using copy-on-write technology on data pages), making it the dominant paradigm for multitasking over the last few decades. -Note: unflushed buffers remain unflushed in both processes, which means -you may need to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> -method of C<IO::Handle> to avoid duplicate output. +All files opened for output are flushed before forking the child process. If you C<fork()> without ever waiting on your children, you will accumulate zombies. On some systems, you can avoid this by setting @@ -2527,11 +2522,10 @@ The following pairs are more or less equivalent: See L<perlipc/"Safe Pipe Opens"> for more examples of this. -NOTE: On any operation that may do a fork, any unflushed buffers remain -unflushed in both processes, which means you may need to set C<$|> to -avoid duplicate output. On systems that support a close-on-exec flag on -files, the flag will be set for the newly opened file descriptor as -determined by the value of $^F. See L<perlvar/$^F>. +NOTE: On any operation that may do a fork, all files opened for output +are flushed before the fork is attempted. On systems that support a +close-on-exec flag on files, the flag will be set for the newly opened +file descriptor as determined by the value of $^F. See L<perlvar/$^F>. Closing any piped filehandle causes the parent process to wait for the child to finish, and returns the status value in C<$?>. diff --git a/pod/perlipc.pod b/pod/perlipc.pod index 2f99d10e23..1492ccfc31 100644 --- a/pod/perlipc.pod +++ b/pod/perlipc.pod @@ -307,8 +307,7 @@ To catch it, you could use this: Both the main process and any child processes it forks share the same STDIN, STDOUT, and STDERR filehandles. If both processes try to access -them at once, strange things can happen. You'll certainly want to any -stdio flush output buffers before forking. You may also want to close +them at once, strange things can happen. You may also want to close or reopen the filehandles for the child. You can get around this by opening your pipe with open(), but on some systems this means that the child process cannot outlive the parent. @@ -473,7 +472,6 @@ Here's an example of using open2(): use FileHandle; use IPC::Open2; $pid = open2(*Reader, *Writer, "cat -u -n" ); - Writer->autoflush(); # default here, actually print Writer "stuff\n"; $got = <Reader>; |