最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]如何杀掉在后台运行的uwsgi的进程

Linux crifan 11567浏览 0评论

折腾:

[记录]尝试去在CentOS中折腾uwsgi

期间,之前运行uwsgi,没有加上 &,所以可以直接control+C去终止运行。

后来通过:

uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processes 4 –threads 2 –stats 127.0.0.1:9191 &

去让uwsgi在后台运行。

现在怀疑端口占用,想要去杀掉uwsgi:

自己通过

ps aux

然后看到有关uwsgi的进程id,然后去干掉:

kill 18049

或者:

kill 18049 18352 18353 18354 18355

都还是会重启:

..brutally killing workers…                                                                                                          
(SIPEvents)  SIPEvents worker 1 buried after 1 seconds
worker 2 buried after 1 seconds
worker 3 buried after 1 seconds
worker 4 buried after 1 seconds
binary reloading uWSGI…
chdir() to /usr/share/nginx/html/uwsgi
closing all non-uwsgi socket fds > 2 (max_fd = 65535)…
found fd 3 mapped to socket 0 (127.0.0.1:8080)
running /usr/local/bin/uwsgi
*** Starting uWSGI 2.0.13.1 (64bit) on [Thu Aug 18 15:11:42 2016] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-17) on 17 August 2016 17:19:10
os: Linux-3.10.101-1.el6.elrepo.x86_64 #1 SMP Wed Mar 16 20:55:27 EDT 2016
nodename: AY140128113754462e2eZ
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /usr/share/nginx/html/uwsgi
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use –uid/–gid/–chroot options
*** WARNING: you are running uWSGI as root !!! (use the –uid flag) *** 
your processes number limit is 31452
your memory page size is 4096 bytes
detected max file descriptor number: 65535
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with –thunder-lock)
uwsgi socket 0 inherited INET address 127.0.0.1:8080 fd 3
Python version: 2.7.12 (default, Aug 15 2016, 11:09:04)  [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
Python main interpreter initialized at 0x11ffae0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 415360 bytes (405 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint=”) ready in 0 seconds on interpreter 0x11ffae0 pid: 18049 (default app)
*** uWSGI is running in multiple interpreter mode ***
gracefully (RE)spawned uWSGI master process (pid: 18049)
spawned uWSGI worker 1 (pid: 18368, cores: 2)
spawned uWSGI worker 2 (pid: 18369, cores: 2)
spawned uWSGI worker 3 (pid: 18370, cores: 2)
spawned uWSGI worker 4 (pid: 18371, cores: 2)
*** Stats server enabled on 127.0.0.1:9191 fd: 15 ***

how kill uwsgi

python – How to kill all instance of uwsgi – Stack Overflow

how to kill uWSGI process – Stack Overflow

how to kill uWSGI process – Stack Overflow

(SIPEvents)  SIPEvents pidof uwsgi
18371 18370 18369 18368 18049

->

所以之前的:

kill `pidof uwsgi`

和我自己写的效果一样

-》还是导致重启。

(SIPEvents)  SIPEvents ps ax | grep uwsgi
18049 pts/0    SN     0:00 /usr/local/bin/uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processes 4 –threads 2 –stats 127.0.0.1:9191
18499 pts/0    SNl    0:00 /usr/local/bin/uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processes 4 –threads 2 –stats 127.0.0.1:9191
18500 pts/0    SNl    0:00 /usr/local/bin/uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processes 4 –threads 2 –stats 127.0.0.1:9191
18501 pts/0    SNl    0:00 /usr/local/bin/uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processes 4 –threads 2 –stats 127.0.0.1:9191
18502 pts/0    SNl    0:00 /usr/local/bin/uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processes 4 –threads 2 –stats 127.0.0.1:9191
18522 pts/0    S+     0:00 grep –color=auto –exclude-dir=.bzr –exclude-dir=CVS –exclude-dir=.git –exclude-dir=.hg –exclude-dir=.svn uwsgi

Things to know (best practices and “issues”) READ IT !!! — uWSGI 2.0 documentation

(SIPEvents)  SIPEvents killall -s INT /usr/local/bin/uwsgi
SIGINT/SIGQUIT received…killing workers…
(SIPEvents)  SIPEvents worker 1 buried after 1 seconds
worker 2 buried after 1 seconds
worker 3 buried after 1 seconds
worker 4 buried after 1 seconds
goodbye to uWSGI.
[1]  + 18049 done       uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processes 4  2
(SIPEvents)  SIPEvents ps ax | grep uwsgi                 
18556 pts/0    S+     0:00 grep –color=auto –exclude-dir=.bzr –exclude-dir=CVS –exclude-dir=.git –exclude-dir=.hg –exclude-dir=.svn uwsgi

[总结]

如果运行uwsgi,带了pid的,则可以通过pid去停止uwsgi。

但是此处是没有pid,而默认直接kill则会导致uwsgi重启,没有被杀掉。

然后才知道,kill会发送SIGTERM,只会导致重启,而不是结束掉。

需要发送SIGINT或SIGQUIT,对应着是INT才可以,最终用:

killall -s INT /usr/local/bin/uwsgi

即可干掉uwsgi。

其中此处的uwsgi是对应的路径

可以通过:

ps ax | grep uwsgi

输出的结果中,看到对应的uwsgi的路径。

转载请注明:在路上 » [已解决]如何杀掉在后台运行的uwsgi的进程

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.202 seconds, using 22.18MB memory