IBM/AIX 下找到占用指定端口的进程并杀死它
零、Windows下的方法 > netstat -ano | find "1521" TCP 0.0.0.0:1521 0.0.0.0:0 LISTENING 2024 > taskkill /pid 2024
一、相关方法的参考资料(转载) 1:首先根据端口号 # netstat -A | grep 1099 返回 f1000089c27a2358 tcp4 0 0 *.389 *.* LISTEN 2:移除sock # rmsock f100089c27a2358 tcpcb The socket 0x702f6800 is being held by proccess 4986 (java). 3:杀死进程 # kill 4986
二、功能脚本(原创) ##功能:找到端口所在进程的pid并选择是否杀死此进程 ##参数$1 = 端口
- !/bin/ksh
- function kpd
- {
- ### 扫描端口所在pcb
- netstat -A | grep $1| head -n 1 ;
- pcb=$(netstat -A | grep $1| head -n 1 | awk 'BEGIN{FS=" "}{print $1}');
- ### 扫描pcb所在进程id
- rmsock "$pcb" tcpcb;
- pid=$(rmsock "$pcb" tcpcb | awk 'BEGIN{FS=" "}{print $9}');
- ### 是否杀死进程?
- echo "杀死占用端口:"$1" 的进程:"$pid"?(y/n)";
- read choose;
- if [ "$choose" == "y" ];then
- kill -9 "$pid";
- echo "已杀死进程:"$pid" .";
- fi
- }
### 示例:杀死占用1099端口的进程 # kpd 1099 f1000e00111533b0 tcp 0 0 *.1099 *.* LISTEN The socket 0x11153008 is being held by proccess 12189714 (java). 杀死占用端口:1099 的进程:12189714?(y/n)