I am trying to use fork to run a process in the background while the parent process continues running its own code. What I have is:

Neils Program:

#!/usr/local/bin/perl # some code if ($pid = fork ) { print "this is the parent\n"; } else { print "this is the child\n"; exec `some unix command that does not terminate`; } # more of Neils code exit;

It is my goal to run neil's program, kick off the unix command in background mode then continue running more of Neil's code. When I run this program and do a ps -ef on my solaris 9 machine I get:

What I want to happen is if I do a ps -ef, then I should get one copy of Neil's main program and one copy of Neil's child process. Furthermore, if I kill Neil's Main program, the child should die. I have tried the examples of fork in the Perl Cookbook with similar results.

Finally, the reason that I do not use a pipe to an open statement is that using this process prevents my child process from communicating to its license server. So I am trying a different approach using fork.

thanks for any suggestions

W3NTP
neil


In reply to how to run a process in background mode by w3ntp

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.