Nov 19, 2012, 8:20 AM
Post #1 of 2
Pipe, Fork, Exec
I writing a wrapper/handler script to monitor my game server, want to do it myself for learning purposes but I have hit a road block.
I've got the initial script going but when I execute the server on the child I can't figure out a way to transmit data to the child from the parent since exec waits for the server to finish.
Also I want to be able to check if the Child (Game Server) is still alive but my method just doesn't seem to work and I can't figure out why.
As you can see below I have attempted to use pipe but I don't quite know what I'm doing.
$pipe = IO::Pipe->new();
#system("java -jar minecraft_server.jar nogui");
my $child = fork;
#defined $child or die "Can't fork: $!\n";
print "I'm parent ($0): $$\n";
$exists = kill 0, $child;
print "Child OK: $child\n";
print "Child Dead\n";
print "I'm child ($0): $$\n";
#exec $^X, 'java -jar minecraft_server.jar nogui';
system("java -jar minecraft_server.jar nogui");
All help is appreciated.