做开发的同学经常会碰到一个恼人的问题,那就是启动服务器时会抛出一个XXXX端口被占用的异常(⊙o⊙)…,究竟这个端口被哪个家伙给使用了呢?下面我们花两步来找出来,并kill掉它。
假设一下,异常报出 1371端口被占用了。
在windows 环境下面,从开始->运行,输入cmd,进入dos界面,然后输入如下命令并运行。 view plaincopy to clipboardprint?
C:\Documents and Settings\qingxu>netstat -aon|findstr "1371"
TCP 10.5.35.151:1371 203.208.37.104:80 CLOSE_WAIT 2160
C:\Documents and Settings\qingxu>netstat -aon|findstr "1371"
TCP 10.5.35.151:1371 203.208.37.104:80 CLOSE_WAIT 2160 可以看到,运行命令后出现了一行记录,我们关注的是最后一个字段,对,就是2160,它表示占用这个端口的进程号。
有了进程号之后,继续输入如下命令并运行 view plaincopy to clipboardprint?
C:\Documents and Settings\qingxu>tasklist|findstr "2160"
Fiddler.exe 2160 Console 0 150,648 K
C:\Documents and Settings\qingxu>tasklist|findstr "2160"
Fiddler.exe 2160 Console 0 150,648 K
可以看到,是fiddler.exe这个程序在运行。之后你就可以关闭掉这个程序即解决问题,当然你也可以换端口号。
在linux下键入命令并运行 view plaincopy to clipboardprint?
-bash-2.05b$ sudo netstat -anp|grep '1371'
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 52 218.104.81.152:1371 211.100.39.250:29488 ESTABLISHED 6111/1
-bash-2.05b$ sudo netstat -anp|grep '1371'Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 52 218.104.81.152:1371 211.100.39.250:29488 ESTABLISHED 6111/1 最后一个字段即是进程号和应用程序名称,找到并关闭之。 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lovingprince/archive/2009/10/09/4646945.aspx
假设一下,异常报出 1371端口被占用了。
在windows 环境下面,从开始->运行,输入cmd,进入dos界面,然后输入如下命令并运行。 view plaincopy to clipboardprint?
C:\Documents and Settings\qingxu>netstat -aon|findstr "1371"
TCP 10.5.35.151:1371 203.208.37.104:80 CLOSE_WAIT 2160
C:\Documents and Settings\qingxu>netstat -aon|findstr "1371"
TCP 10.5.35.151:1371 203.208.37.104:80 CLOSE_WAIT 2160 可以看到,运行命令后出现了一行记录,我们关注的是最后一个字段,对,就是2160,它表示占用这个端口的进程号。
有了进程号之后,继续输入如下命令并运行 view plaincopy to clipboardprint?
C:\Documents and Settings\qingxu>tasklist|findstr "2160"
Fiddler.exe 2160 Console 0 150,648 K
C:\Documents and Settings\qingxu>tasklist|findstr "2160"
Fiddler.exe 2160 Console 0 150,648 K
可以看到,是fiddler.exe这个程序在运行。之后你就可以关闭掉这个程序即解决问题,当然你也可以换端口号。
在linux下键入命令并运行 view plaincopy to clipboardprint?
-bash-2.05b$ sudo netstat -anp|grep '1371'
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 52 218.104.81.152:1371 211.100.39.250:29488 ESTABLISHED 6111/1
-bash-2.05b$ sudo netstat -anp|grep '1371'Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 52 218.104.81.152:1371 211.100.39.250:29488 ESTABLISHED 6111/1 最后一个字段即是进程号和应用程序名称,找到并关闭之。 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lovingprince/archive/2009/10/09/4646945.aspx
[code=BatchFile]@echo off
if "%1" == "" goto all
netstat -ano | find ":%1">nul && (
echo 协议 本地地址 外部地址 状态 PID
netstat -ano | find ":%1"
) || echo 没有找到端口号为 %1 的进程
goto end
:all
netstat -ano
:end
echo on[/code]杀死指定进程号的进程(kill.bat)
[code=BatchFile]@echo off
if "%1" == "" goto info
setlocal enabledelayedexpansion
tasklist /fi "pid eq %1" | find "%1" > nul && (
tasklist /fi "pid eq %1"
echo.
set /p str="是否要结束 PID 为 %1 的进程(Y/N)? "
if /I "!str!" == "Y" taskkill /f /pid %1
) || echo 没有找到 PID 为 %1 的进程
goto end
:info
echo 使用方法:kill ^<需要结束的进程号(PID)^>
:end
echo on[/code]