Hello monks,

I'm having one heck of a time getting this to work. I need to be able to have a perl script (running in a unix environment) start up some process in the background and then exit.

The problem I'm running into is that no matter what I do, either 1) Perl hangs and waits until the background process completes, or 2) The background process dies when perl dies.

So far, the only thing that I've found that actually works the way I want it to, is something like this:

system('run_my_program.sh');
This is followed up by a shell script like this:
#!/bin/sh my_program &

That works great. Whenever it is the shell script that sticks the process in the background it runs just the way I want it to. However, a Perl command like this

system( "my_program &" );
does not. Using the perl fork() command also does not work. As soon as my main perl script dies, all of the children processes get reaped.

I would imagine that if it is possible to have perl make a system call to a one line shell script that does what I want, that it must be possible to bypass the shell script all together and just make perl stick the process in the background on it's own. Any advice would really be appreciated.


In reply to Starting a process in the background that lives after perl dies. by ehdonhon

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.