I am developing some PHP scripts on a Namecheap shared server. I accidentally made a loop which seems to go on indefinitely (or for a very long time), so now I am trying to kill it using SSH.
I have viewed a list of running processes with top
, found the misbehaving PHP script, and tried to kill it with kill
. However, after I kill it with this command, when I try using the ps
, it is still running!
The result of the ps
:
PID TTY STAT TIME COMMAND
819520 ? S 0:00 /usr/bin/php /my/php/file.php
I have tried killing the process over and over, but it just won't die!
The SSH is limited, so I can't use commands like killall
. What do I do??!
Try running something like apachectl stop and then apachectl start to start it back up. This will kill your server for a period of time but it will also make sure that any processes stuck on that script will go away.
The best way is to close the terminal window as we cannot type anything while the server is running! Press the (X) button on the top right(on Windows/Linux)/Press the red color circle on the top left(on Mac OS) of the terminal window to stop the PHP server from running.
Depending on your setup this could be managed via fast-cgi or mod_php or even php-fpm. If you use mod_php , then there will be no "php processes" visible for ps . You can still see if your PHP engine is in use by using lsof : $ lsof -ln [...]
To kill the process you can do the following:
ps -ef
kill -9 <pid>
A nice reference: When should I use kill -9?
Just for fun, an example:
$ sleep 100 &
[1] 4156
$ ps -ef | grep slee[p]
me 4156 3501 0 10:34 pts/5 00:00:00 sleep 100
$ kill 4156
[1]+ Terminated sleep 100
$ ps -ef | grep slee[p]
$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With