… | |
… | |
2 | |
2 | |
3 | Proc::FastSpawn - fork+exec, or spawn, a subprocess as quickly as possible |
3 | Proc::FastSpawn - fork+exec, or spawn, a subprocess as quickly as possible |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use Proc::FastSpawn; |
7 | use Proc::FastSpawn; |
|
|
8 | |
|
|
9 | # simple use |
|
|
10 | my $pid = spawn "/bin/echo", ["echo", "hello, world"]; |
|
|
11 | ... |
|
|
12 | waitpid $pid, 0; |
|
|
13 | |
|
|
14 | # with environment |
|
|
15 | my $pid = spawn "/bin/echo", ["echo", "hello, world"], ["PATH=/bin", "HOME=/tmp"]; |
|
|
16 | |
|
|
17 | # inheriting file descriptors |
|
|
18 | pipe R, W or die; |
|
|
19 | fd_inherit fileno W; |
|
|
20 | my $pid = spawn "/bin/sh", ["sh", "-c", "echo a pipe >&" . fileno W]; |
|
|
21 | close W; |
|
|
22 | print <R>; |
8 | |
23 | |
9 | =head1 DESCRIPTION |
24 | =head1 DESCRIPTION |
10 | |
25 | |
11 | The purpose of this small (in scope and footprint) module is simple: |
26 | The purpose of this small (in scope and footprint) module is simple: |
12 | spawn a subprocess asynchronously as efficiently and/or fast as |
27 | spawn a subprocess asynchronously as efficiently and/or fast as |
… | |
… | |
66 | } |
81 | } |
67 | } |
82 | } |
68 | } |
83 | } |
69 | |
84 | |
70 | BEGIN { |
85 | BEGIN { |
71 | $VERSION = '0.1'; |
86 | $VERSION = '0.2'; |
72 | |
87 | |
73 | our @ISA = qw(Exporter); |
88 | our @ISA = qw(Exporter); |
74 | our @EXPORT = qw(spawn fd_inherit); |
89 | our @EXPORT = qw(spawn fd_inherit); |
75 | require Exporter; |
90 | require Exporter; |
76 | |
91 | |
… | |
… | |
94 | decided on a per file descriptor basis. This module does nothing to any |
109 | decided on a per file descriptor basis. This module does nothing to any |
95 | preexisting handles, but with this call, you can change the state of a |
110 | preexisting handles, but with this call, you can change the state of a |
96 | single file descriptor to either be inherited (C<$on> is true or missing) |
111 | single file descriptor to either be inherited (C<$on> is true or missing) |
97 | or not C<$on> is false). |
112 | or not C<$on> is false). |
98 | |
113 | |
|
|
114 | Free portability pro-tip: it seems native win32 perls ignore $^F and set |
|
|
115 | all file handles to be inherited by default - but this fucntino can switch |
|
|
116 | it off. |
|
|
117 | |
99 | =back |
118 | =back |
100 | |
119 | |
101 | =head1 PORTABILITY NOTES |
120 | =head1 PORTABILITY NOTES |
102 | |
121 | |
103 | On POSIX systems, this module currently calls vfork+exec, spawn, or |
122 | On POSIX systems, this module currently calls vfork+exec, spawn, or |
104 | fork+exec, depending on the platform. If your platform has a good vfork or |
123 | fork+exec, depending on the platform. If your platform has a good vfork or |
105 | spawn but is misdetected and falls back on slow fork+exec, drop me a note. |
124 | spawn but is misdetected and falls back to slow fork+exec, drop me a note. |
106 | |
125 | |
107 | On win32, the C<_spawn> family of functions is used, and the module tries |
126 | On win32, the C<_spawn> family of functions is used, and the module tries |
108 | hard to patch the new process into perl's internal pid table, so the pid |
127 | hard to patch the new process into perl's internal pid table, so the pid |
109 | returned should work with other perl functions such as waitpid. Also, |
128 | returned should work with other perl functions such as waitpid. Also, |
110 | win32 doesn't have a meaningful way to quote arguments containing |
129 | win32 doesn't have a meaningful way to quote arguments containing |
111 | "special" characters, so this module tries it's best to quote those |
130 | "special" characters, so this module tries it's best to quote those |
112 | strings itself. Other typical platform limitations (such as being able to |
131 | strings itself. Other typical platform limitations (such as being able to |
113 | only have 64 or so subprocesses) apply as well. |
132 | only have 64 or so subprocesses) are not worked around. |
114 | |
133 | |
115 | =head1 AUTHOR |
134 | =head1 AUTHOR |
116 | |
135 | |
117 | Marc Lehmann <schmorp@schmorp.de> |
136 | Marc Lehmann <schmorp@schmorp.de> |
118 | http://home.schmorp.de/ |
137 | http://home.schmorp.de/ |
119 | |
138 | |
120 | =cut |
139 | =cut |
121 | |
140 | |
122 | 1; |
141 | 1 |
123 | |
142 | |