1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
# Fork.pm
# Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
package TestApp::Controller::Fork;
use strict;
use warnings;
use base 'Catalyst::Controller';
use JSON::MaybeXS qw(encode_json);
sub system : Local {
my ($self, $c, $ls) = @_;
my ($result, $code) = (undef, 1);
if(!-e $ls || !-x _){
$result = 'skip';
}
else {
$result = system($ls, $ls, $ls);
$result = $! if $result != 0;
}
$c->response->body(encode_json({result => $result}));
}
sub backticks : Local {
my ($self, $c, $ls) = @_;
my ($result, $code) = (undef, 1);
if(!-e $ls || !-x _){
$result = 'skip';
$code = 0;
}
else {
$result = `$ls $ls $ls` || $!;
$code = $?;
}
$c->response->body(encode_json({result => $result, code => $code}));
}
sub fork : Local {
my ($self, $c) = @_;
my $pid;
my $x = 0;
if($pid = fork()){
$x = "ok";
}
else {
exit(0);
}
waitpid $pid,0 or die;
$c->response->body(encode_json({pid => $pid, result => $x}));
}
1;
|