简单的bat处理,把指定端口集合杀死相应的进程,就是杀死对应的pid @echo off & setlocal EnableDelayedExpansion ]= ]= ]= ]= ]= for /f "usebackq delims== tokens=1-2" %%a in (`set obj`) do ( set port=%%b for /f "tokens=5" %%m in ('netstat -aon ^| findstr ":%%b&
private void t_btn_kill_Click(object sender, EventArgs e) { int port; bool b = int.TryParse(t_txt_guardport.Text, out port); if (!b) { MessageBox.Show("请输入正确的监听端口"); return; } Process p = new Process(); p.StartInfo.FileName = "cmd.exe"
使用这个命令:netstat -nap [root@Jaosn sphinx]# netstat -nap Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name 杀死进程 使用kill命令结束进程:kill XXX 常用:kill