如何删除已分配给端口的当前进程/应用程序?
例如:localhost:8080
如何删除已分配给端口的当前进程/应用程序?
例如:localhost:8080
当前回答
我们可以通过简单地重新启动IIS来避免这种情况,使用下面的命令:
IISRESET
其他回答
我在Windows上运行zookeeper,无法使用zookeeper-stop.sh停止在2181端口运行的zookeeper,所以尝试了这个双斜线“//”方法来kill任务。它工作
1. netstat -ano | findstr :2181
TCP 0.0.0.0:2181 0.0.0.0:0 LISTENING 8876
TCP [::]:2181 [::]:0 LISTENING 8876
2.taskkill //PID 8876 //F
SUCCESS: The process with PID 8876 has been terminated.
对于Windows用户,您可以使用CurrPorts工具轻松地杀死正在使用的端口:
打开命令提示符并发出下面的命令
netstat -ano|findstr "PID :8888"
输出将显示占用端口的进程id
发出下面的命令杀死PID
taskkill /pid 8912 /f
您将收到如下输出
SUCCESS: The process with PID 8860 has been terminated.
我为此写了一个很小的node js脚本。就像这样运行它: node killPort.js 8080或任何你需要杀死的端口。保存如下文件到killPort.js文件中:
const { exec } = require('child_process');
const fs = require(`fs`);
const port = process.argv.length > 2 ? process.argv[2] : ``;
if (!port || isNaN(port)) console.log(`port is required as an argument and has to be a number`);
else {
exec(`netstat -ano | findstr :${port}`, (err, stdout, stderr) => {
if (!stdout) console.log(`nobody listens on port ${port}`);
else {
const res = stdout.split(`\n`).map(s => s.trim());
const pid = res.map(s => s.split(` `).pop()).filter(s => s).pop();
console.log(`Listener of ${port} is found, its pid is ${pid}, killing it...`);
exec(`taskkill /PID ${pid} /F`, (err, stdout, stderr) => {
if (!stdout) console.log(`we tried to kill it, but not sure about the result, please run me again`);
else console.log(stdout);
})
}
});
}
netstat -ano | findstr :PORT
kill PI