See my reply to this question: Checking the status of a process on Linux/Windows - #2 by JohnnyBBravo