<?xml version="1.0" encoding="windows-1252"?>
<node id="671051" title="Re: Launch process, get PID" created="2008-02-28 18:26:43" updated="2008-02-28 13:26:43">
<type id="11">
note</type>
<author id="647878">
pc88mxer</author>
<data>
<field name="doctext">
You're executing &lt;c&gt;command&lt;/c&gt; in the background, so the pid you are getting back is the pid of the shell that's spawning &lt;c&gt;command&lt;/c&gt; and not of &lt;c&gt;command&lt;/c&gt; itself. Just want to make sure you're aware of that.

&lt;p&gt;If you just want to launch &lt;c&gt;command&lt;/c&gt; and not worry about it, just use &lt;c&gt;fork&lt;/c&gt; and &lt;c&gt;exec&lt;/c&gt; directly:

&lt;P&gt;&lt;c&gt;
my $pid = fork();
die "unable to fork: $!" unless defined($pid);
if (!$pid) {  # child
    exec('command...');
    die "unable to exec: $!";
}
# parent continues here, pid of child is in $pid
&lt;/c&gt;

&lt;p&gt;In the exec, perhaps you'll want to redirect the child's output to either /dev/null or  a file.

&lt;p&gt;Another option is to 'daemonize' the child which involves detaching it from the parent's process group. For an example, have a look at &lt;A HREF="http://snippets.dzone.com/posts/show/359"&gt;http://snippets.dzone.com/posts/show/359&lt;/a&gt;, and I'm sure there's code on CPAN to do it, too.

&lt;p&gt;In your original code, I think you were getting broken pipes because you were closing &lt;c&gt;$handle&lt;/c&gt; and the child was still writing to its STDOUT.
</field>
<field name="root_node">
671047</field>
<field name="parent_node">
671047</field>
</data>
</node>
