ruby TCPServer 错误:地址已被使用 - bind(2)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10261477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 05:03:23  来源:igfitidea点击:

TCPServer Error: Address already in use - bind(2)

rubyjekyll

提问by Omnipresent

Jekyll was working fine for me few weeks back but now all of a sudden it gives me the following error:

几周前 Jekyll 对我来说工作正常,但现在突然间它给了我以下错误:

TCPServer Error: Address already in use - bind(2)
INFO  WEBrick::HTTPServer#start: pid=7300 port=4000

 % lsof -i :4000
 <fetches nothing>

Even though nothing is running on the port. Below are the details:

即使端口上没有运行任何东西。以下是详细信息:

 % jekyll --version
Jekyll 0.11.2
 % where jekyll
/home/bhaarat/.rvm/gems/ruby-1.9.2-p290/bin/jekyll
/usr/bin/jekyll
 % ruby --version
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
 % rvm --version
rvm 1.10.0 

Here is the output

这是输出

 % jekyll --server
Configuration from /home/bhaarat/blog/omnipresent.github.com/_config.yml
Auto-regenerating enabled: /home/bhaarat/blog/omnipresent.github.com -> /home/bhaarat/blog/omnipresent.github.com/_site
[2012-04-21 13:46:40] regeneration: 38 files changed
[2012-04-21 13:46:40] INFO  WEBrick 1.3.1
[2012-04-21 13:46:40] INFO  ruby 1.9.2 (2011-07-09) [i686-linux]
[2012-04-21 13:46:40] WARN  TCPServer Error: Address already in use - bind(2)
[2012-04-21 13:46:40] INFO  WEBrick::HTTPServer#start: pid=7382 port=4000

I know the address isn't in use and jekyll is probably breaking for some other reason but throwing that error. What are my options? I've tried re-installing as well.

我知道该地址未在使用中,并且 jekyll 可能由于其他原因而中断,但抛出了该错误。我有哪些选择?我也试过重新安装。

回答by Naoise Golden

Type this in your terminal to find out the PID of the process that's using the 3000 port:

在终端中输入以下内容以找出使用 3000 端口的进程的 PID:

$ lsof -wni tcp:3000

Then, use the number in the PID column to kill the process:

然后,使用 PID 列中的数字来终止进程:

$ kill -9 PID

回答by Fonzie

I was not qualified to post comment. So I added a new answer.

我没有资格发表评论。所以我添加了一个新的答案。

I encountered this problem on Mac OS X 10.10.3. And I had never installed/used Jekyll before. I was not able to start jekyll server with its default port number 4000. The reason was that the port was the same as what NoMachine used. With

我在 Mac OS X 10.10.3 上遇到了这个问题。而且我之前从未安装/使用过 Jekyll。我无法使用默认端口号 4000 启动 jekyll 服务器。原因是该端口与 NoMachine 使用的端口相同。和

$ sudo lsof -wni tcp:4000

Note: Running this command without sudowill have no output.

注意:sudo在没有的情况下运行此命令将没有输出。

I saw this output:

我看到了这个输出:

COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
nxd     449   nx    3u  IPv4 0x8d22************      0t0  TCP *:terabase (LISTEN)
nxd     449   nx    4u  IPv6 0x8d22************      0t0  TCP *:terabase (LISTEN)

The port 4000 was occupied by nxd, which was the process started by NoMachine. And

4000端口被 占用nxd,是NoMachine启动的进程。和

$ sudo kill -9 449

would not work, because NoMachine's nxd process would keep restarting, with a new PID.

不会工作,因为 NoMachine 的 nxd 进程会不断重新启动,并使用新的 PID。

Therefore, I had to either:

因此,我不得不:

  • Changed my jekyll server port in the site _config.ymlto another spared one. I appended the line below to _config.ymland it worked.

    port: 3000 # change server port to 3000

  • 将站点中的 jekyll 服务器端口更改_config.yml为另一个备用端口。我将下面的行附加到_config.yml它的工作。

    port: 3000 # change server port to 3000

or

或者

  • Changed NoMachine's default nxd port, or Uninstall NoMachine
  • 更改了 NoMachine 的默认 nxd 端口,或卸载 NoMachine

回答by kevin

Ctrl-Zdoesn't terminate a program, but rather suspends it and sends it to the background. You can resume the program with the "fg" command. To actually terminate it, use Ctrl-C.

Ctrl-Z不会终止程序,而是挂起它并将其发送到后台。您可以使用“fg”命令恢复程序。要实际终止它,请使用Ctrl-C.

The actual error message seems to be bogus and can be ignored. I am getting the same error message "address in use" but jekyll works fine anyway at the expected port.

实际的错误消息似乎是假的,可以忽略。我收到相同的错误消息“正在使用的地址”,但无论如何 jekyll 在预期的端口上都可以正常工作。

回答by wfwei

I have met this problem recently.

我最近遇到了这个问题。

I tried out all the method mentioned above, and even restarted my computer, but still couldn't solve it!!! Then I removed the jekyll and installed a new version, it just worked.

上面的方法我都试过了,甚至重启了电脑,还是解决不了!!!然后我删除了 jekyll 并安装了一个新版本,它正常工作。

gem uninstall jekyll & gem install jekyll(maybe you need super user priviledge).

gem uninstall jekyll & gem install jekyll(也许您需要超级用户权限)。

If you really get annoyed with similar bugs, this sb method is worth a try...

如果你真的对类似的 bug 感到恼火,这个 sb 方法值得一试......

回答by Manoj Datt

First you need to find PID of the process that's using the 3000 port:

首先,您需要找到使用 3000 端口的进程的 PID:

 $ps -ef

Output Like this:

输出像这样:

1003      4953  2614  0 08:51 pts/0    00:00:00 -bash
1003      5634     1  0 08:56 pts/0    00:00:00 spring server | moviestore | started 2 hours ago                                           
1003      5637  5634  0 08:56 ?        00:00:01 spring app    | moviestore | started 2 hours ago | development mode                                                              
1003      6078  4953  0 09:03 pts/0    00:00:03 puma 3.6.0 (tcp://localhost:3000) [moviestore]              
1003      6117  2614  0 09:03 pts/1    00:00:00 -bash
root      6520     2  0 09:57 ?        00:00:00 [kworker/u8:2]
root      6936  1225  0 11:09 ?        00:00:00 [lightdm] <defunct>
1003      7084     1  0 11:09 ?        00:00:00 /usr/bin/python /usr/share/apport/apport-gtk
1003      7475     1  0 11:10 ?        00:00:00 /usr/bin/python /usr/share/apport/apport-gtk
root      8739  1225  1 11:29 tty8     00:00:11 /usr/bin/X :1 -auth /var/run/lightdm/root/:1 -nolisten tcp vt8 -novtswitch
root      8853  1225  0 11:29 ?        00:00:00 lightdm --session-child 13 22
1002      8943     1  0 11:30 ?        00:00:00 /usr/bin/gnome-keyring-daemon --daemonize --login
1002      8954  8853  0 11:30 ?        00:00:00 gnome-session --session=ubuntu
1002      8992  8954  0 11:30 ?        00:00:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session gnome-session --session=ubuntu
1002      8995     1  0 11:30 ?        00:00:00 /usr/bin/dbus-launch --exit-with-session gnome-session --session=ubuntu
1002      8996     1  0 11:30 ?        00:00:00 //bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
1002      9007  8954  0 11:30 ?        00:00:00 /usr/lib/gnome-settings-daemon/gnome-settings-daemon
1002      9015     1  0 11:30 ?        00:00:00 /usr/lib/gvfs/gvfsd
1002      9018  8954  1 11:30 ?        00:00:07 compiz
1002      9021     1  0 11:30 ?        00:00:00 /usr/lib/x86_64-linux-gnu/gconf/gconfd-2
1002      9028  8954  0 11:30 ?        00:00:00 /usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1
1002      9029  8954  0 11:30 ?        00:00:01 nautilus -n
1002      9030  8954  0 11:30 ?        00:00:00 /usr/lib/gnome-settings-daemon/gnome-fallback-mount-helper
1002      9031  8954  0 11:30 ?        00:00:00 nm-applet
1002      9032  8954  0 11:30 ?        00:00:02 /opt/mTrac/mTrac
1002      9033  8954  0 11:30 ?        00:00:00 bluetooth-applet
1002      9045  9032  0 11:30 ?        00:00:00 /opt/mTrac/mTrac --type=zygote --no-sandbox
1002      9050     1  0 11:30 ?        00:00:00 /usr/lib/gvfs/gvfs-gdu-volume-monitor
1002      9054     1  0 11:30 ?        00:00:00 /usr/bin/pulseaudio --start --log-target=syslog
1002      9057     1  0 11:30 ?        00:00:00 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
1002      9062     1  0 11:30 ?        00:00:00 /usr/lib/gvfs/gvfs-afc-volume-monitor

here you can see :

在这里你可以看到:

1003      6078  4953  0 09:03 pts/0    00:00:03 puma 3.6.0 (tcp://localhost:3000) [moviestore]   

localhost:3000 have pid: 6078

本地主机:3000 有 pid: 6078

kill that process by

杀死该进程

$sudo kill 6078  

then run

然后运行

$rails s

回答by Avinash Kumar Singh

we can user fuser command

我们可以使用 fuser 命令

fuser -k 3000/tcp

fuser -k 3000/tcp

回答by harvey

Check that you don't have another terminal open where you are already running a server. If that is the case, do a CTRL-Cto shutdown the server, and that will free the port/address.

检查您没有打开另一个终端,您已经在运行服务器。如果是这种情况,请执行CTRL-C以关闭服务器,这将释放端口/地址。

回答by Arvind

work around

解决

in /_siterun: python -m SimpleHTTPServer 8080

/_site运行:python -m SimpleHTTPServer 8080