diff options
author | Eric Wong <e@80x24.org> | 2016-02-27 02:14:23 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-02-27 10:58:22 +0000 |
commit | ca885bd5905b7faa9ecb7b0eb02476de1d3a7f88 (patch) | |
tree | c4ae278dfb6825ae3e80eb4346c80fbab993c99e /lib/PublicInbox/SpawnPP.pm | |
parent | 2cc034627726da5c73c88d5ff7a8b136cc9ce759 (diff) | |
download | public-inbox-ca885bd5905b7faa9ecb7b0eb02476de1d3a7f88.tar.gz |
Under Linux, vfork maintains constant performance as parent process size increases. fork needs to prepare pages for copy-on-write, requiring a linear scan of the address space.
Diffstat (limited to 'lib/PublicInbox/SpawnPP.pm')
-rw-r--r-- | lib/PublicInbox/SpawnPP.pm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/PublicInbox/SpawnPP.pm b/lib/PublicInbox/SpawnPP.pm new file mode 100644 index 00000000..ae552dd8 --- /dev/null +++ b/lib/PublicInbox/SpawnPP.pm @@ -0,0 +1,33 @@ +# Copyright (C) 2016 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +package PublicInbox::SpawnPP; +use strict; +use warnings; +use POSIX qw(dup2); + +# Pure Perl implementation for folks that do not use Inline::C +sub public_inbox_fork_exec ($$$$$$) { + my ($in, $out, $err, $f, $cmd, $env) = @_; + my $pid = fork; + if ($pid == 0) { + if ($in != 0) { + dup2($in, 0) or die "dup2 failed for stdin: $!"; + } + if ($out != 1) { + dup2($out, 1) or die "dup2 failed for stdout: $!"; + } + if ($err != 2) { + dup2($err, 2) or die "dup2 failed for stderr$!"; + } + %ENV = (); + foreach my $e (@$env) { + my ($k, $v) = split('=', $e, 2); + $ENV{$k} = $v; + } + exec @$cmd; + exit 1; + } + $pid; +} + +1; |