Shutting down a server
Posted: Thu Apr 28, 2005 6:30 am
How exactly do servers shut themselves down?
For e.g. a Web server it just keeps waiting for clients in a infinite loop. So how is it supposed to actually exit itself.
One way I can think of is by using a signal handler. I mean when the server is started initially it "takes over" a certain port after this if we try to start the same server again we will be unable to do so as the port will be occupied. This lets us know that our(?) server is already running.
Now if I need to shutdown this server I send a special arg say -close and this sends a signal to the running server (how do i get the PID now?) which terminates itself.
Is there a cleaner way to do this?
And yeah the main thing. How is this done in JAVA?
For e.g. a Web server it just keeps waiting for clients in a infinite loop. So how is it supposed to actually exit itself.
One way I can think of is by using a signal handler. I mean when the server is started initially it "takes over" a certain port after this if we try to start the same server again we will be unable to do so as the port will be occupied. This lets us know that our(?) server is already running.
Now if I need to shutdown this server I send a special arg say -close and this sends a signal to the running server (how do i get the PID now?) which terminates itself.
Is there a cleaner way to do this?
And yeah the main thing. How is this done in JAVA?