# assigns a job to a worker process. # :param 0: job. # :return: sub assign_job { my ($job) = @_; my $pid = open my $pipe => "-|"; # create worker process and connect it using a pipe. Debug::dlog("spawned process : $pid"); die "Failed to fork: $!" unless defined $pid; # check that creation was successfull. my $routine = $job->get_routine(); # get routine to execute. my $params = $job->get_params(); # get parameters to pass. unless ($pid) { # the following code is only executed in the worker process: $ENV{"PATH"} = "/usr/bin"; # delete context. my $return = $routine->(@$params); # execute routine. my $dump = Dumper($return); # serialize the returned object. print($dump); # print data string to pipe. Debug::dlog("process ".$$." dumped ".length($dump)." chars"); exit; # terminate process. } else { # only in parent process: my $worker = new Worker($pipe, $pid); # construct new worker object. push(@Dispatcher::workers, $worker); # save worker object. } }