in reply to Persist shell app

I would write a socket server around the running instance of the application, and have my CGIs connect to that socket server on each request.

Managing which socket the CGI should connect to could be done through sessions/cookies/etc, so the problem just becomes one of killing off abandoned application instances.