A process can kill itself without user activity. The easiest way to exchange variables in another thread is with a file. Suppose the client browser is still open, the javascript timer raises Ajax requests, which writes the timestamp to the server to the file. Your task also periodically reads the file, and when the timestamp is too old, the process kills itself. The activity timeout value that you can select of your choice.
Boris Gappov
source share