Issue
I wrote a bash script to start a Django development sever, however, I want to be able to quit the server while it's running with a bash script as well. I'm writing a web app for Koding.com that starts a Django process in an online terminal linked to the user's personal VM by running a bash script with a press of a button, and I want users to be able to end the process with a press of a button as well. I know that control C would end the process, but I haven't been able to find out how to do that in a bash script. How could I go about doing this? Thanks!
UPDATE: I ultimately combined my selected answer for this question and this answer from another question I asked (how to run unix commands in django shell) to solve my problem: https://stackoverflow.com/a/22777849/2181017
Solution
You can kill the process listening on 8000/TCP:
fuser -k 8000/tcp
The fuser
command shows which processes are using the named files, sockets, or filesystems and the -k
option kills them as well.
Wait, just to clarify, there's no way to temporarily exit that django shell thing so that I could run a unix command?
When you start the development server it will run in foreground, blocking the prompt. You can pause the task that is running in foreground by hitting CTRL+Z
, and then send the task to background running the bg
command (I assume you are running the bash shell or a lookalike). The jobs
command will list paused tasks or tasks running in background. You can bring a task to foreground using the fg
command.
Please refer to the bash man page (man bash
).
Answered By - Paulo Scardine Answer Checked By - Dawn Plyler (WPSolving Volunteer)