Explorar o código

Fork when speaking

Zachary Kotlarek %!s(int64=13) %!d(string=hai) anos
pai
achega
38a3d07e94
Modificáronse 1 ficheiros con 12 adicións e 2 borrados
  1. 12 2
      dmx/projectorPower.pl

+ 12 - 2
dmx/projectorPower.pl

@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 use strict;
 use warnings;
-use POSIX qw(ceil floor);
+use POSIX;
 
 # Local modules
 use Cwd qw(abs_path);
@@ -58,6 +58,9 @@ my $color        = $COLOR_LOW;
 # Loop forever
 while (1) {
 
+	# Reap zombie children
+	while (waitpid(-1, WNOHANG) > 0) { }
+
 	# State is calculated; use newState to gather data
 	my $newState = $state;
 
@@ -264,7 +267,14 @@ sub say($) {
 	if ($DEBUG) {
 		print STDERR 'Say: ' . $str . "\n";
 	}
-	system('say', $str);
+
+	my $pid = fork();
+	if (!defined($pid)) {
+		die('Unable to fork: ' . $! . "\n");
+	}
+	if (!$pid) {
+		exec('say', $str);
+	}
 }
 
 sub sayShutdown($) {