How do I get the process ID of it at the first place?
Use the return value of fork, and exec PMEMD in the child. system will only return after the process it spawn has finished.
I know how to open a file and read it and analyze the output but how does the script know when the output file gets updated?
You tell us. Unless PMEMD cooperates in some way, there's no way of knowing. Oh, you can inspect the last modification time of the file and/or its size and/or a checksum, but that's neither foolproof, nor can you know whether PMEMD is done writing, or whether it was PMEMD writing to the file in the first place. And PMEMD may buffer output. Without knowing how PMEMD operates, the question cannot be answered in a meaningful way. Perhaps just doing a tail -f of the file works. Perhaps you need to communicate with PMEMD using a shared memory semaphore.
And how to kill the child process when certain criterion is satisfied?
I guess kill() is a way too obvious way. Perhaps you should disconnect the power? Smash the CPU with a hammer?

In reply to Re: How to monitor a child process from a perl script by JavaFan
in thread How to monitor a child process from a perl script by oscarjiao

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.