Fellow Perlmonks,

I ask for your advise on how to make a script aware of itself (running as another process).

What I would like to archive is to make a script die when it knows it is already running in another process.

I thought up the following solutions, each having pitfalls though.

Solution a) Script 1 gets its own pid and writes it into a file. Script 2 checks for the file and pings the saved pid to see if the process is still running. If the pid is still existing Script 2 will die. (Script 1 will delete the file upon an error-free exit)
Pitfalls in a) WINDOWS (one of the environments the script has to run on) reuses pids.

Solution b) Do the same as in a) but don't save the PID, just some random piece of data.
Pitfalls in b) I wouldn't know if Script 1 exited in error and forgot to clean up after itself. I.e. Script 2 would always think Script 1 is running.

Does some perlmonk have a better idea of check for existance of a script in memory that would work across platforms???

thanks /neuroball/


In reply to Make a perl script self aware... by neuroball

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.