Jul 21, 2015

f Comment

[SOLVED] I cannot kill Nginx with Unix kill command. How do I kill it without rebooting?

Amazon Let's say you are trying to kill Nginx by running the "kill" Unix command like the following.
$ ps aux|grep nginx
www-data  1408  0.0  1.1 104168  5588 ?        Sl   10:08   0:01 nginx: worker process
ubuntu    3490  0.0  0.1  11996   932 pts/0    S+   10:45   0:00 grep --color=auto nginx
$ sudo kill -9 1048
$ ps aux|grep nginx
www-data  1408  0.0  1.1 104168  5588 ?        Sl   10:08   0:01 nginx: worker process
ubuntu    3539  0.0  0.1  11996   936 pts/0    S+   10:49   0:00 grep --color=auto nginx
But for some reason, the Nginx worker process just won't let you kill it. How do you kill this immortal Nginx worker process? Some people suggest rebooting your Unix machine, but it may be a hassle for you. Read on to see how to kill the Nginx worker process without restarting Unix.

I am running Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-43-generic x86_64).


Cause

One possible cause is that you've killed Nginx master process first, which leaves your Nginx worker process unmanaged and orphaned.

Solution

In short, you can't. Just kidding. Here's how you kill the zombie Nginx worker process. First note from the above command trace that the process ID of Nginx worker process is 1408. Then locate your Nginx's PID file by looking in the nginx init.d Ubuntu script. In my case, the script is at /etc/init.d/nginx, and Nginx PID file is at /run/nginx.pid.

Let's change the process ID in Nginx's PID file to 1408 as follows.
$ cat /run/nginx.pid
1403
$ sudo vi /run/nginx.pid
$ cat /run/nginx.pid
1408
Let's stop Nginx and start it again as follows.
$ sudo service nginx stop
* Stopping Nginx Server...
$ ps aux|grep nginx
root      3542  0.0  0.4  67296  2128 pts/2    S+   10:49   0:00 sudo vi /etc/init.d/nginx
root      3543  1.4  1.1  50356  5692 pts/2    S+   10:49   0:00 vi /etc/init.d/nginx
ubuntu    3579  0.0  0.1  11996   932 pts/0    S+   10:49   0:00 grep --color=auto nginx
$ sudo service nginx start
* Starting Nginx Server...                                       [ OK ]
$ ps aux|grep nginx
root      3542  0.0  0.4  67296  2128 pts/2    S+   10:49   0:00 sudo vi /etc/init.d/nginx
root      3543  0.1  1.1  50356  5692 pts/2    S+   10:49   0:00 vi /etc/init.d/nginx
root      3603  0.0  0.3  95172  1892 ?        Ss   10:49   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www-data  3605  0.0  1.1 104484  5844 ?        Sl   10:49   0:00 nginx: worker process
www-data  3606  0.0  0.9 103792  4812 ?        Sl   10:49   0:00 nginx: worker process
www-data  3607  0.0  0.9 103792  4808 ?        Sl   10:49   0:00 nginx: worker process
www-data  3608  0.0  0.9 103792  4808 ?        Sl   10:49   0:00 nginx: worker process
ubuntu    3627  0.0  0.1  11996   936 pts/0    S+   10:51   0:00 grep --color=auto nginx
Congratulations. You have killed the seemingly immortal Nginx worker process. Cheers!

Questions? Let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael