CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Pipe, Fork, Exec


New User

Nov 19, 2012, 8:20 AM

Post #1 of 2 (1886 views)
Pipe, Fork, Exec Can't Post


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";
while (true)
$exists = kill 0, $child;
if ($exists)
print "Child OK: $child\n";
print "Child Dead\n";
#print "Tick...\n";
print "I'm child ($0): $$\n";
#print $pipe;

#exec $^X, 'java -jar minecraft_server.jar nogui';
system("java -jar minecraft_server.jar nogui");

All help is appreciated.



Nov 21, 2012, 1:22 AM

Post #2 of 2 (1819 views)
Re: [Scarrez] Pipe, Fork, Exec [In reply to] Can't Post

exec waits for the server to finish

I guess you wanted to say: system waits for the server to finish....

In your case, you want to do fork+exec to have child and parent running concurrently. For the communication from the child to the parent, you could set up a pipe before doing the fork. Another possibility would be the usage of sockets, or of a file which is written by the child and monitored by the parent.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives