How do I shut down a python simpleHTTPserver?
You are simply sending signals to the processes. kill
is a command to send those signals.
The keyboard command Ctrl+C sends a SIGINT, kill -9
sends a SIGKILL, and kill -15
sends a SIGTERM.
What signal do you want to send to your server to end it?
if you have started the server with
python -m SimpleHTTPServer 8888
then you can press ctrl + c to down the server.
But if you have started the server with
python -m SimpleHTTPServer 8888 &
or
python -m SimpleHTTPServer 8888 & disown
you have to see the list first to kill the process,
run command
ps
or
ps aux | less
it will show you some running process like this ..
PID TTY TIME CMD7247 pts/3 00:00:00 python7360 pts/3 00:00:00 ps23606 pts/3 00:00:00 bash
you can get the PID from here. and kill that process by running this command..
kill -9 7247
here 7247 is the python id.
Also for some reason if the port still open you can shut down the port with this command
fuser -k 8888/tcp
here 8888 is the tcp port opened by python.
Hope its clear now.
MYPORT=8888; kill -9 `ps -ef |grep SimpleHTTPServer |grep $MYPORT |awk '{print $2}'`
That is it!
Explain command line :
ps -ef
: list all process.grep SimpleHTTPServer
: filter process which belong to "SimpleHTTPServer"grep $MYPORT
: filter again process belong to "SimpleHTTPServer" where port is MYPORT (.i.e: MYPORT=8888)awk '{print $2}'
: print second column of result which is the PID (Process ID)kill -9 <PID>
: Force Kill process with the appropriate PID.