--- loncom/lonmaxima 2006/03/03 23:47:55 1.6 +++ loncom/lonmaxima 2006/03/04 02:33:54 1.7 @@ -3,7 +3,7 @@ # The LearningOnline Network with CAPA # Connect to MAXIMA CAS # -# $Id: lonmaxima,v 1.6 2006/03/03 23:47:55 albertel Exp $ +# $Id: lonmaxima,v 1.7 2006/03/04 02:33:54 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -52,9 +52,10 @@ my $pidfile; # my $port; # path to UNIX socket file my %perlvar; # configuration file info my $lastlog; # last string that was logged - +my $maximapid; # PID of maxima process +my $selector; # open3's selector use vars qw($PREFORK $MAX_CLIENTS_PER_CHILD %children $children $status - $pidfile $port %perlvar $lastlog); + $pidfile $port %perlvar $lastlog $maximapid $selector); sub maximareply { my ($cmd) = @_; @@ -65,15 +66,20 @@ sub maximareply { unless ($cmd=~/\;\n$/) { $cmd.=";\n"; } my ($cmd_in, $cmd_out, $cmd_err); - my $pid = open3($cmd_in, $cmd_out, $cmd_err, 'maxima'); - $children{$pid} = 1; + $maximapid = open3($cmd_in, $cmd_out, $cmd_err, 'maxima'); + $children{$maximapid} = 1; print $cmd_in $cmd; close($cmd_in); &status("Command sent"); - my $selector = IO::Select->new(); + $SIG{ALRM} = sub { kill 9 => $maximapid; }; + alarm(5); + no strict 'refs'; + + $selector = IO::Select->new(); + $selector->add($cmd_err, $cmd_out); while (my @ready = $selector->can_read()) { @@ -90,8 +96,11 @@ sub maximareply { $selector->remove($fh) if eof($fh); } } + alarm(0); + $SIG{ALRM} = 'DEFAULT'; close($cmd_out); close($cmd_err); + use strict 'refs'; &status("Command processed"); return ($reply,$error,$exitstatus); } @@ -240,7 +249,6 @@ close(PIDSAVE); &status('Starting'); - # Fork off our children. for (1 .. $PREFORK) { &make_new_child($server);