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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |