I do not think you need another state variable while SQLite already has that information. Check out
. Using a file for this purpose may break things in the future. Still you may store the PID of the process in that file and check if it is still around before bailing out. In that case you need to trap kill signal and the like to make things smoother. But using a file is not the best way to go.