2 .\" This file and its contents are supplied under the terms of the
3 .\" Common Development and Distribution License ("CDDL"), version 1.0.
4 .\" You may only use this file in accordance with the terms of version
7 .\" A full copy of the text of the CDDL should have accompanied this
8 .\" source. A copy of the CDDL is also available via the Internet at
9 .\" http://www.illumos.org/license/CDDL.
12 .\" Copyright 2015 Joyent, Inc.
15 .Dt PROC_INITSTDIO 3PROC
21 .Nd stdio buffering functions
43 functions are utilities provided to aid with the possibility of deadlock
44 while doing I/O operations.
45 If a process is trying to do I/O, but holding the process handle that would
46 consume that I/O, then eventually the program holding the process handle will
47 block as none of its I/O has been drained.
48 However, because it is holding a process handle to that process, it will never
51 Consider, for example, the following invocation:
52 .Li pfiles `pgrep xterm`
53 where the command was launched from a shell on an xterm.
54 Because the xterm is stopped, it will not be able to write out any of the
55 standard out that gets passed to it, leading to a deadlock.
58 program cannot release the
60 process because it still has pending I/O, but the I/O cannot be drained
63 To address this, these functions duplicate the standard output and
64 standard error of the process to temporary files and then flushes it out
65 to the original file descriptors and streams later.
66 When finished, the original file descriptors are restored as standard out and
71 function initializes a new standard out and standard error file
72 descriptors and retains the originals.
76 functions flushes all of the cached data from the temporary standard out
77 and standard error back to the underlying ones.
78 This function should only be called after all process handles have been
80 For example, if iterating on multiple processes, calling this after handling
85 flushes any outstanding I/O and restores the original standard output
90 function must not be called again until a successful call to
93 Upon successful completion, the
102 is returned to indicate failure.
103 .Sh INTERFACE STABILITY