这是一个创建于 4558 天前的主题,其中的信息可能已经有所发展或是发生改变。
linux环境下,运行一个python web app(flask,监听9009端口),用户从页面点击某个按钮后后台执行脚本启动某个java程序(subprocess.Popen('sh ' + os.path.join(self.path, 'startup.sh'), cwd=self.path, stdout=subprocess.PIPE, shell=True)),对应的脚本内容如下:
#!/bin/bash
nohup java -jar -Xmn128m -Xms512m -Xmx4096m xxGame.jar > /home/SG_DEVELOP/xxGame/app.out 2>&1 &
java程序完全启动后,查看9009端口占用情况结果如下:
user@sgse02 goss]$ netstat -lpn | grep 9009
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:9009 0.0.0.0:* LISTEN 13798/python
结束python web app程序进程后再启动,结果报端口已被占用,查看9009端口占用情况结果如下:
[user@sgse02 goss]$ netstat -lpn | grep 9009
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:9009 0.0.0.0:* LISTEN 13824/java
占用该端口的即之前启动的java程序:
[user@sgse02 goss]$ ps aux | grep 13824
user 13824 37.9 1.8 4625484 308980 pts/0 Sl 14:04 1:12 java -jar -Xmn128m -Xms512m -Xmx4096m xxGame.jar
user 13982 0.0 0.0 61148 748 pts/9 S+ 14:08 0:00 grep 13824
---------------------------------------
各位v2ex有谁遇到过类似情况么?
1 条回复 • 2017-04-24 23:48:15 +08:00
|
|
1
zyuyou 2017-04-24 23:48:15 +08:00 1
Popen 添加 close_fds=True
|