ok.
one quick one.
hope it helps you
create one file at the start of the script.
write "app started" like something .
and while closing write "app stopped"
and every time you run the script check for the above text .
i m hoping this solution should be feasible...