http://qs321.pair.com?node_id=485337


in reply to making a perl script TSR? (on linux)

Have a look at the module Net::Server, it has pretty much all you need to write a network server daemon.

Should you want to kill your daemon cleanly, create a signal handler in the daemon that does a graceful shutdown, and have the program, when you run with '-k' flag, to send a signal to the daemon, which then initiates the shutdown procedure.

You may also want to look at modules like Unix::Process (really just ps -ef) to discover the PID of the daemon process.

You can also create a /var/lock/myserver.lock file as well when the server first goes TSR, that contains the PID of the server process. The program later (in kill mode) will read this file to get the PID, validate the PID using Unix::Process to make sure it is still running, then send the kill signal to the server to initiate a clean shutdown.

  • Comment on Re: making a perl script TSR? (on linux)