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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



Scarrez
New User

Nov 19, 2012, 8:20 AM

Post #1 of 2 (1064 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.


Code
	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


rovf
Veteran

Nov 21, 2012, 1:22 AM

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


Quote
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