This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Trouble with perl fork() and exec()


I have a cygwin installation under which I'm running the Net::Server::Fork daemon "munin-node". For those not aware, munin is a monitoring system which is really easy to use and configure (

That said, it's not working properly.

Here's the trouble I'm having - maybe somebody has seen it before and can push me in the right direction?

The basic flow of the daemon is:

<start munin-node which attaches to a port and runs fine>
<connect from other machine1>
<machine1 request plugin>
<server forks() and then exec() the 'plugin' to gather data>
<plugin returns data to parent via STDIN>
<plugin exits>
<parent returns data to machine1>
<sing songs, drink beer>

Now, this is breaking unfortunately, so I never get to sing songs and drink beer.

What seems to happen is the child gets fork()ed and then the plugin code exec()'d. The data then comes back up the line via the STDIN to the parent, however, despite the child finishing execution (I've made sure all sockets are closed and even tried a die()) it never exits.

I've made the sure the data is actually coming back by putting a print in the while loop and that shows that it's coming back from the child. All the data makes it back, but the while loop doesn't finish and the timeout alarm hits, so the child gets reaped. When it's reaped it returns "Interrupted system call".

Ive tried replacing the exec() with a dirty hack of system();exit(); but exactly the same thing happens.

The relevant code which does the running of the plugin is below:

(Full code:

print "# Forking .. \n" if $DEBUG;
if ($child = open (CHILD, "-|")) {
eval {
local $SIG{ALRM} = sub { $timed_out=1; die "$!\n"};
while(<CHILD>) {
#last if $_ eq "# DONE";
if ($_ eq "# DONE") { close(CHILD); }
push @lines,$_;
print "#DEBUG CHILD: $_" if $DEBUG;
print "# Finished gathering data from Child\n" if $DEBUG;
if( $timed_out ) {
print "# Child timed out - calling reap_children $@ \n" if $DEBUG;
reap_children($child, "$service $command: $@");
close (CHILD);
return ();
unless (close CHILD)
if ($!)
# If Net::Server::Fork is currently taking care of reaping,
# we get false errors. Filter them out.
unless (defined $autoreap and $autoreap)
logger ("Error while executing plugin \"$service\": $!");
logger ("Plugin \"$service\" exited with status $?. --@lines--");
else {
if ($child == 0) {
my $timenow = localtime();
print "# Child forked as $$ - $timenow\n" if $DEBUG;
# New process group...

        <child stuff here>

            print "# Execing $servicedir/$service $command\n" if $DEBUG;
            exec ("$servicedir/$service", $command);


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]