I have a perl app that has a couple of functions which take a very long time to complete. I would like to be able to essentially throw these functions into the background (maybe not literally, but figuratively) and still be able to give periodic updates to another process (through a socket that I have open). This sounds kind of convoluted, so I'll give a simplified example. (Note, this isn't the actual app, so don't worry about specifics, typos or if the socket connection fails).
#!/usr/bin/perl -w use IO::Socket; use strict; #sock is my connection where I report what is going on my $sock = IO::Socket::INET->new(PeerAddr => 'hostname.org', PeerPort => '1234', Proto => 'tcp' ); my $return_value = long_running_function(); print $sock "$return_value\n"; close $sock;


Now, I'd like to be able to have the long_running_function run, while I still have the ability to communicate on the socket. I'm wanting to send an "I'm still here" to the other end of the socket every 2-3 minutes, while I'm waiting for the long_running_function to finish processing (which can take up to an hour to complete). I've been racking my brain on this, and cannot really figure out a clean way to do this. I thought about using fork, but I'm not sure there isn't a simpler way I'm just overlooking.

This app is running on the win32 platform, though the other end of the socket is FreeBSD (not that the other end should matter).

Any good ideas?

In reply to How to break up a long running process by markh

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.