Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Problems w/ system calls

by Zaxo (Archbishop)
on Jun 02, 2004 at 03:56 UTC ( [id://359128]=note: print w/replies, xml ) Need Help??


in reply to Problems w/ system calls

You don't want system for this; it doesn't return until the called process exits. You can do what you're trying with fork.

Here's one way of writing it,

$SIG{CHLD} = 'IGNORE'; # or arrange to wait at end # Start the server my $server_path = $bin . $server; my $spid = fork; die $! unless defined $spid; exec $server_path or die $! unless $spid; # Start up the client my $client_path = $bin . $client; my $cpid = fork; die $! unless defined $cpid; exec $client_path or die $! unless $cpid;

Update: GaijinPunch, 'Killed' is what the kernel prints when it destroys a process for violating something or other - most often seen in perl when you run the system out of memory. I think robartes suggestion of the cause as bad socket allocation is as good as any, though you should look at memory use as well. muntfish, that usage depends on exec calling a utility through the shell instead of directly. That obscures error handling and is often fragile. The code above should have more than one argument to exec (or an indirect object) just to make sure that the server and client are called directly, but I didn't want to confuse the issue with bogus arguments.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Problems w/ system calls
by muntfish (Chaplain) on Jun 02, 2004 at 08:07 UTC

    Regarding system - I've always used

    system "blah &";

    (rather than fork) to start stuff in the "background". I believe this works because of the & - system recognises this as a shell character and passes the whole string to /bin/sh.

    Any comments/potential problems with this approach? (other than lack of portability, of course...)

    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&;
Re: Re: Problems w/ system calls
by GaijinPunch (Pilgrim) on Jun 02, 2004 at 05:04 UTC
    Thanks for the reply. I actually broke off the dust from my Learning Perl book, and noted the brief page on Fork. I thought that might be a solution, but figured I'd check here first.

    I've played around w/ the above code, to no avail. I simly says "Killed" in the terminal after running it. I guess I should dig around a bit more on fork and see what the issue is.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://359128]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 18:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found