J
Jon
How do I get the return value of a child process? Take this example:
====================================
sub my_function {
return 10;
}
my $return=0;
my $child_pid=0;
if (!defined($child_pid = fork())) {
die "cannot fork: $!";
} elsif ($child_pid) {
# I'm the parent
} else {
# I'm the child
$return = my_function();
print("return is $return\n");
exit 0;
}
my $pid = wait;
print("return is $return\n")
==========================================
Output is:
return is 10
return is 0
The wait() function returns the pid and what I really want is the
return code from that pid. I would like to pass the return code of a
function I ran in the child back to the parent...Is there a simple way
to do this? I *think* there might be a way to do this with pipes, but
I have no clue as to how to do that.
Thanks for any help,
Jon
====================================
sub my_function {
return 10;
}
my $return=0;
my $child_pid=0;
if (!defined($child_pid = fork())) {
die "cannot fork: $!";
} elsif ($child_pid) {
# I'm the parent
} else {
# I'm the child
$return = my_function();
print("return is $return\n");
exit 0;
}
my $pid = wait;
print("return is $return\n")
==========================================
Output is:
return is 10
return is 0
The wait() function returns the pid and what I really want is the
return code from that pid. I would like to pass the return code of a
function I ran in the child back to the parent...Is there a simple way
to do this? I *think* there might be a way to do this with pipes, but
I have no clue as to how to do that.
Thanks for any help,
Jon