Linux 进程号 端口号 互找

1、查看系统运行的java项目,并查看进程号。

 ps -ef|grep java

或者

jps

2、lsof命令:根据进程pid查端口。

如果提示无此命令,可以使用yum安装下:

yum -y install lsof
lsof -i | grep 17120

  

3、根据端口port查进程

lsof  -i:port

  

4、根据用户查看进程和端口号

lsof -i|grep root

  

5、 netstat命令根据端口查进程

netstat -anlp | grep 80

  

6、netstat根据进程查端口

jps

netstat -anpl | grep 17120

  

7、查询进程的启动程序路径

假设要查询的进程的PID为17120

cd /proc/17120
ls -anl

 显示:

total 0
dr-xr-xr-x  2 root root 0 Sep 16 16:12 attr
-rw-r--r--  1 root root 0 Sep 16 16:19 autogroup
-r--------  1 root root 0 Sep 16 16:19 auxv
-r--r--r--  1 root root 0 Sep 16 16:19 cgroup
--w-------  1 root root 0 Sep 16 16:19 clear_refs
-r--r--r--  1 root root 0 Sep  4 10:27 cmdline
-rw-r--r--  1 root root 0 Sep 16 16:19 comm
-rw-r--r--  1 root root 0 Sep 16 16:19 coredump_filter
-r--r--r--  1 root root 0 Sep 16 16:19 cpuset
lrwxrwxrwx  1 root root 0 Sep  4 10:27 cwd -> /
-r--------  1 root root 0 Sep 11 14:49 environ
lrwxrwxrwx  1 root root 0 Sep  4 10:27 exe -> /usr/lib/jvm/jdk1.8.0_131/bin/java
dr-x------  2 root root 0 Aug 27 19:32 fd
dr-x------  2 root root 0 Sep 16 16:05 fdinfo
-rw-r--r--  1 root root 0 Sep 16 16:19 gid_map
-r--------  1 root root 0 Sep 16 16:19 io
-r--r--r--  1 root root 0 Sep 16 16:19 limits
-rw-r--r--  1 root root 0 Sep 16 16:19 loginuid
dr-x------  2 root root 0 Sep 16 16:19 map_files
-r--r--r--  1 root root 0 Sep  4 10:27 maps
-rw-------  1 root root 0 Sep 16 16:19 mem
-r--r--r--  1 root root 0 Sep 16 16:19 mountinfo
-r--r--r--  1 root root 0 Sep 11 14:49 mounts
-r--------  1 root root 0 Sep 16 16:19 mountstats
dr-xr-xr-x  5 root root 0 Sep 11 14:49 net
dr-x--x--x  2 root root 0 Sep 16 16:19 ns
-r--r--r--  1 root root 0 Sep 16 16:19 numa_maps
-rw-r--r--  1 root root 0 Sep 16 16:19 oom_adj
-r--r--r--  1 root root 0 Sep 16 16:19 oom_score
-rw-r--r--  1 root root 0 Sep 16 16:19 oom_score_adj
-r--r--r--  1 root root 0 Sep 16 16:19 pagemap
-r--r--r--  1 root root 0 Sep 16 16:19 personality
-rw-r--r--  1 root root 0 Sep 16 16:19 projid_map
lrwxrwxrwx  1 root root 0 Sep  4 10:27 root -> /
-rw-r--r--  1 root root 0 Sep 16 16:19 sched
-r--r--r--  1 root root 0 Sep 16 16:19 schedstat
-r--r--r--  1 root root 0 Sep 16 16:19 sessionid
-rw-r--r--  1 root root 0 Sep 16 16:19 setgroups
-r--r--r--  1 root root 0 Sep 16 16:19 smaps
-r--r--r--  1 root root 0 Sep 16 16:19 stack
-r--r--r--  1 root root 0 Sep 16 15:58 stat
-r--r--r--  1 root root 0 Sep 16 16:19 statm
-r--r--r--  1 root root 0 Sep 11 14:49 status
-r--r--r--  1 root root 0 Sep 16 16:19 syscall
dr-xr-xr-x 89 root root 0 Sep 16 16:19 task
-r--r--r--  1 root root 0 Sep 16 16:19 timers
-rw-r--r--  1 root root 0 Sep 16 16:19 uid_map
-r--r--r--  1 root root 0 Sep 16 16:19 wchan

解析

  • cwd符号链接的是进程运行目录
  • exe符号连接就是执行程序的绝对路径
  • cmdline就是程序运行时输入的命令行命令
  • environ记录了进程运行时的环境变量
  • fd目录下是进程打开或使用的文件的符号连接

查看运行是命令:

cat cmdline
/usr/lib/jvm/jdk1.8.0_131/bin/java-Dcom.sun.akuma.Daemon=daemonized-Djava.awt.headless=true-DJENKINS_HOME=/var/lib/jenkins-jar/usr/lib/jenkins/jenkins.war--logfile=/var/log/jenkins/jenkins.log--webroot=/var/cache/jenkins/war--daemon--httpPort=8080--debug=5--handlerCount
Max=100--handlerCountMaxIdle=20
发布了144 篇原创文章 · 获赞 53 · 访问量 26万+

猜你喜欢

转载自blog.csdn.net/yanxilou/article/details/100891051