I've started a SimpleHTTPServer via the command python -m SimpleHTTPServer 9001
.
I'd like to stop it without having to force quit Terminal. What's the keystrokes required to stop it?
I've started a SimpleHTTPServer via the command python -m SimpleHTTPServer 9001
.
I'd like to stop it without having to force quit Terminal. What's the keystrokes required to stop it?
CTRL + C is usually the right way to kill the process and leave your terminal open.
Use CTRL+C.
This is a filler text because answer must be 30 characters.
Agree with Ctrl-C answer. Note that pressing Ctrl-C sends 'interrupt' signal (signal number 2).
Alternatively you can use TERM signal to terminate your server process.
You can send 'INT' or 'TERM' signal to request termination. Typically all good programs honor int and term signal and do cleanup.
To terminate a process properly, run
kill -2 <pid>
kill -15 <pid>
or
kill -INT <pid>
kill -TERM <pid>
There is a difference in SIGINT and SIGTERM. From this quora article,
SIGINT is the interrupt signal. The terminal sends it to the foreground process when the user presses ctrl-c. The default behavior is to terminate the process, but it can be caught or ignored. The intention is to provide a mechanism for an orderly, graceful shutdown.
SIGTERM is the termination signal. The default behavior is to terminate the process, but it also can be caught or ignored. The intention is to kill the process, gracefully or not, but to first allow it a chance to cleanup.
So use the right signal depending on your needs.