我在mac上,做:

rails server

我得到:

2010-12-17 12:35:15] INFO  WEBrick 1.3.1
[2010-12-17 12:35:15] INFO  ruby 1.8.7 (2010-08-16) [i686-darwin10.4.0]
[2010-12-17 12:35:15] WARN  TCPServer Error: Address already in use - bind(2)
Exiting

我知道我可以在一个新的端口上启动一个进程,但是我想终止这个进程。


当前回答

类型:

man lsof

然后寻找-w -n和-i

-i:网络东西 -n:加快速度 -w:切换警告

手册页上有更多的细节

其他回答

您需要使用tcp端口3000获取程序的进程id。获取进程id

lsof -i tcp:3000 -t

然后使用进程id,使用ubuntu kill命令简单地杀死进程。

kill -9 pid

或者只是运行下面提到的组合命令。它将首先获取pid,然后终止该进程。

kill -9 $(lsof -i tcp:3000 -t)

Kill -9 $(lsof -i tcp:3000 -t)

使用此命令可以关闭服务器:

ps aux|grep rails 

这是一个在windows中杀死进程的WSL脚本

PIDS=$(/mnt/c/windows/system32/cmd.exe /c netstat -ano | /mnt/c/windows/system32/cmd.exe /c findstr :$1 | awk '{print $5}')
for pid in $PIDS
do
    /mnt/c/windows/system32/cmd.exe /c wmic process where "processid=$pid" delete
done

例子

myscriptname 8080

假设你想要杀死端口3000上的任何东西(这是webrick通常使用的),在你的终端中输入这个来找出进程的PID:

$ lsof -wni tcp:3000

然后,使用PID列中的数字杀死进程:

$ kill -9 PID