I need to have a perl script create a new process, and exit while it's child process continues running. I first tried with fork() which doesn't work because perlfork only creates a new psuedo-process (i.e., only creates a new thread), and the parent can't exit until the child returns.
if (my $ChildPid = fork) { # Parent - create lock and exit my $Lock = Childlck->new($ResName); $Lock->lock_mk($ChildPid); exit 0; } else { # Child - continue as G daemon exec $CMD, $CMDLineArgs, @ARGV; }
Next I tried with Win32::Process::Create, and it also exhibits the same problem...the parent doesn't "exit 0", until the child dies.
Win32::Process::Create($ChildProc, $CMD, $CMDLine, 0, 0, $CWD) || +LOG_MSG("E", "Could not spawn child: $!", 52099); $ChildPID = $ChildProc->GetProcessID(); LOG_MSG("I", "ChildPID = $ChildPID", 52099, $ChildPID); my $Lock = Glck->new($ResName); $Lock->lock_mk($ChildPID); LOG_MSG("I", "Online.pl is about to exit with 0.", 52099); exit (0);
Then I tried using system() to create a new perl process, but it also doesn't return from the parent script until the child dies.
system($CMDLine); my $Lock = Glck->new($ResName); LOG_MSG("I", "Online.pl is about to exit with 0.", 52099); exit (0);
How can I create a process and have the parent process return while the child process continues running?

In reply to Can't get Win32::Create::Process() parent to exit before it's children by AlphaGrey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.