
Scarrez
New User
Nov 19, 2012, 8:20 AM
Post #1 of 2
(727 views)
|
|
Pipe, Fork, Exec
|
Can't Post
|
|
Hi, 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.
use IO::Pipe; $pipe = IO::Pipe->new(); #system("java -jar minecraft_server.jar nogui"); #use strict; use warnings; my $child = fork; #defined $child or die "Can't fork: $!\n"; if ($child) { print "I'm parent ($0): $$\n"; $pipe->reader(); while (true) { $exists = kill 0, $child; if ($exists) { print "Child OK: $child\n"; } else { print "Child Dead\n"; } #print "Tick...\n"; sleep(4); } } else { print "I'm child ($0): $$\n"; $pipe->writer(); #print $pipe; #exec $^X, 'java -jar minecraft_server.jar nogui'; system("java -jar minecraft_server.jar nogui"); } All help is appreciated. Scarrez
|