I've got a rather large (~1000 lines) program that runs continually. However, it is "event driven" and doesnt actually do anything until it getts a specific kind of input, or I prod it in some fashion. I have lately been wanting to include a sort of "memo" or "reminder" function into it.

I figure it would require forking off a sub that wasnt event driven. In other words, a specific event would drive a fork in the middle of a sub that was _not_ event driven, like so:

sub non_event_driven { if (fork()) { # i'm the parent! return 1; } else { # i'm the child! for (;;) if (time() == $waiting_epoch) { # ta-da! play an mp3 and wake up our user # or whatever exit 0; # safe for shell, and we're done anyways } } } return 0; }
the problem is, since fork() creates a _copy_ of the program youre running, and your current program is 50mb in memory, you could *seriously* hurt the host machine if you had, say, twenty of them running... as I might well do with a reminder sub.

any suggestions?

thanks,
brother dep

--
Laziness, Impatience, Hubris, and Generosity.


In reply to creative forking (code) by deprecated

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.