当前位置:网站首页>【Shell】查找进程的pid并根据pid获取该进程所占用的端口号以及该进程在系统中所下达的指令名称
【Shell】查找进程的pid并根据pid获取该进程所占用的端口号以及该进程在系统中所下达的指令名称
2022-08-09 06:46:00 【L-DiCaprio】
查找进程的pid并根据pid获取该进程所占用的端口号以及该进程在系统中所下达的指令名称–Linux shell脚本
#!/bin/bash
pwd_path=`pwd`
pid=$1_pid.txt
port=$1_port.txt
#把输入进程的pid存储到pid.txt文件里面
ps -ef | grep $1 | awk '{print $2}' > $pwd_path/$pid
#读取进程id并获取端口号存储到port.txt文件里面
for i in $(cat $pwd_path/$pid)
do
echo -e "\e[101m$i号PID对应的文件\e[0m">>$pwd_path/$port
ps -ef | awk -v var=$i '$2 == var {print $0}' | awk '{for(j=8;j<=NF;j++) {printf $j} print "\n"}' >> $pwd_path/$port
echo -e "\e[101m$i号PID对应的端口\e[0m">>$pwd_path/$port
netstat -nltp | grep $i | awk '{print $4}' | awk -F: '{print $NF}' >> $pwd_path/$port
done
边栏推荐
- AD的library中 库文件后缀有.intlib .schlib .pcblib 的区别
- Variable used in lambda expression should be final or effectively final报错解决方案
- 电学知识的疑问
- 中英文说明书丨CalBioreagents 山羊抗人白蛋白,IgG组分
- Mysql实操
- io.lettuce.core。RedisCommandTimeoutException命令超时
- Error: flask: TypeError: 'function' object is not iterable
- P7 Alibaba Interview Questions 2020.07 Sliding Window Algorithm (Alibaba Cloud Interview)
- 工控设备的系统如何进行加固
- C语言的内置宏(定义日志宏)
猜你喜欢
随机推荐
P7阿里面试题2020.07 之滑动窗算法(阿里云面试)
Transaction concluded
代码目录结构
字节跳动面试题之镜像二叉树2020
The working principle of the transformer (illustration, schematic explanation, understand at a glance)
C语言实现顺序栈和链队列
codeforces Valera and Elections (这思维题是做不明白了)
install flask
网络学习总结
图论,二叉树,dfs,bfs,dp,最短路专题
MongDb query method
shardingsphere data sharding configuration item description and example
C language implements sequential stack and chain queue
jdepend
Altium designer软件常用最全封装库,包含原理图库、PCB库和3D模型库
安装flask
缓存技术使用
AD picture PCB tutorial 20 minutes clear label shop operation process, copper network
如何 认识与学习BASH
Output method of list string print(*a) print(““.join(str(c) for c in a) )