windows/linux杀进程

windows

手动录入端口

新建一个bat文件,内容如下:

@ECHO OFF
set /p portid=Enter the Port to be killed: 
echo %portid%                                                                              
FOR /F "tokens=5" %%T IN ('netstat -a -n -o ^| findstr %portid% ') DO (
SET /A ProcessId=%%T) &GOTO SkipLine                                                   
:SkipLine                                                                              
echo ProcessId to kill = %ProcessId%
taskkill /f /pid %ProcessId%
PAUSE

双击运行后,输入端口号即可杀掉对应的进程。

固定端口

set portid=12306
echo %portid%                                                                              
FOR /F "tokens=5" %%T IN ('netstat -a -n -o ^| findstr %portid% ') DO (
SET /A ProcessId=%%T) &GOTO SkipLine                                                   
:SkipLine                                                                              
echo ProcessId to kill = %ProcessId%
taskkill /f /pid %ProcessId%

根据标题结束进程

并行启动多个进程:

start "<window title>" <command will be executed>

例子:

start "service1" mvn clean spring-boot:run
start "service2" mvn clean spring-boot:run

获取进程的PID(可选):

tasklist /V /FI "WindowTitle eq service1*"
tasklist /V /FI "WindowTitle eq service2*"

杀死进程:

taskkill /FI "WindowTitle eq service1*" /T /F
taskkill /FI "WindowTitle eq service2*" /T /F

linux

linux查端口进程占用情况。这里以端口为8086为例。

lsof -i:8086

直接杀掉进程

kill $(lsof -t -i:8086)

参考

https://stackoverflow.com/questions/6204003/kill-a-process-by-looking-up-the-port-being-used-by-it-from-a-bat

https://stackoverflow.com/questions/11583562/how-to-kill-a-process-running-on-particular-port-in-linux/32592965#32592965

https://stackoverflow.com/questions/9486960/how-to-get-pid-of-process-just-started-from-within-a-batch-file

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Linux死应用进程,可以使用以下命令: 1. 使用`pidof`命令来获取应用程序的进程ID(PID)。例如,如果应用程序的名称是`softwareName`,则可以运行以下命令来获取其PID:`pidof softwareName`。 2. 将获取到的PID传递给`kill`命令以杀死进程。可以使用以下命令来杀死进程:`kill -9 <PID>`。将`<PID>`替换为你在第一步中获取到的进程ID。 举例来说,你可以运行以下命令来死名为`softwareName`的应用程序进程: ``` pidof softwareName | xargs kill -9 ``` 这将使用`pidof`命令获取进程ID,并将其传递给`kill`命令来杀死进程。 请注意,使用`kill -9`命令会强制终止进程,因此请谨慎使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Linux中有效地管理进程的8个命令](https://download.csdn.net/download/weixin_38696582/14890471)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [纯代码方式死指定进程名的进程Linux&Windows)](https://blog.csdn.net/youzai2017/article/details/128116873)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值