linux下根據埠號查詢對應程式
linux下根據埠號查詢對應程式
我們經常使用netstat -lnp可以查詢對應埠跟程式,但是有些埠是在netstat -lnp裡卻沒顯示對應的程式pid,如果我們使用某個埠已經被佔用,需要找到對應占用埠的進
程關閉之類的,此時可以透過lsof來查詢對應埠的對應程式pid號,
[wei@vm-cbu-qa-168-13 web-deploy]$ netstat -lnp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:7008 0.0.0.0:* LISTEN 27709/java
tcp 0 0 0.0.0.0:6208 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:800 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:7009 0.0.0.0:* LISTEN 27709/java
tcp 0 0 127.0.0.1:15777 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:15778 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:35559 0.0.0.0:* LISTEN 27709/java
tcp 0 0 0.0.0.0:55336 0.0.0.0:* LISTEN 27709/java
tcp 0 0 0.0.0.0:4200 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:58666 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:845 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:4110 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:4207 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:20880 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:4208 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:18000 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:18001 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:18002 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:42483 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:48116 0.0.0.0:* LISTEN -
tcp 0 0 10.20.168.13:8022 0.0.0.0:* LISTEN -
例:
[root@dg ~]# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 2572/hpiod
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1973/portmap
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2607/sshd
tcp 0 0 0.0.0.0:918 0.0.0.0:* LISTEN 2008/rpc.statd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2618/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2654/sendmail: acce
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 2592/python
udp 0 0 0.0.0.0:912 0.0.0.0:* 2008/rpc.statd
udp 0 0 0.0.0.0:915 0.0.0.0:* 2008/rpc.statd
udp 0 0 0.0.0.0:5353 0.0.0.0:* 2780/avahi-daemon:
udp 0 0 0.0.0.0:111 0.0.0.0:* 1973/portmap
udp 0 0 0.0.0.0:18677 0.0.0.0:* 2780/avahi-daemon:
udp 0 0 0.0.0.0:631 0.0.0.0:* 2618/cupsd
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] STREAM LISTENING 4739 1696/iscsid @ISCSIADM_ABSTRACT_NAMESPACE
unix 2 [ ACC ] STREAM LISTENING 8427 3290/gam_server @/tmp/fam-root-
unix 2 [ ACC ] STREAM LISTENING 5997 2369/hald @/var/run/hald/dbus-jSEoLN4lOK
unix 2 [ ACC ] STREAM LISTENING 5996 2369/hald @/var/run/hald/dbus-QcBRXONucw
unix 2 [ ACC ] STREAM LISTENING 10641 5824/dbus-daemon @/tmp/dbus-WEnczw6uAf
unix 2 [ ACC ] STREAM LISTENING 4724 1690/brcm_iscsiuio @ISCSID_UIP_ABSTRACT_NAMESPACE
unix 2 [ ACC ] STREAM LISTENING 5029 1874/audispd /var/run/audispd_events
unix 2 [ ACC ] STREAM LISTENING 5767 2262/dbus-daemon /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 5850 2283/sdpd /var/run/sdp
unix 2 [ ACC ] STREAM LISTENING 5933 2346/pcscd /var/run/pcscd.comm
unix 2 [ ACC ] STREAM LISTENING 7319 2674/gpm /dev/gpmctl
unix 2 [ ACC ] STREAM LISTENING 5961 2356/acpid /var/run/acpid.socket
unix 2 [ ACC ] STREAM LISTENING 11542 5975/mapping-daemon /tmp/mapping-root
unix 2 [ ACC ] STREAM LISTENING 11713 6023/scim-launcher /tmp/scim-socket-frontend-root
unix 2 [ ACC ] STREAM LISTENING 11839 6061/scim-helper-ma /tmp/scim-helper-manager-socket-root
unix 2 [ ACC ] STREAM LISTENING 11844 6062/scim-panel-gtk /tmp/scim-panel-socket:0-root
unix 2 [ ACC ] STREAM LISTENING 7364 2716/xfs /tmp/.font-unix/fs7100
unix 2 [ ACC ] STREAM LISTENING 8108 2869/gdm-binary /tmp/.gdm_socket
unix 2 [ ACC ] STREAM LISTENING 7112 2618/cupsd /var/run/cups/cups.sock
unix 2 [ ACC ] STREAM LISTENING 8135 2981/Xorg /tmp/.X11-unix/X0
unix 2 [ ACC ] STREAM LISTENING 10605 5794/ssh-agent /tmp/ssh-KbTTXd5744/agent.5744
unix 2 [ ACC ] STREAM LISTENING 10669 5830/gconfd-2 /tmp/orbit-root/linc-16c6-0-7197d24b7486b
unix 2 [ ACC ] STREAM LISTENING 10675 5744/gnome-session /tmp/orbit-root/linc-1670-0-1c1b8f9dd3274
unix 2 [ ACC ] STREAM LISTENING 10871 5744/gnome-session /tmp/.ICE-unix/5744
unix 2 [ ACC ] STREAM LISTENING 10880 5837/gnome-keyring- /tmp/keyring-COB2Wt/socket
unix 2 [ ACC ] STREAM LISTENING 10899 5839/gnome-settings /tmp/orbit-root/linc-16cf-0-15341a783b63b
unix 2 [ ACC ] STREAM LISTENING 10970 5862/metacity /tmp/orbit-root/linc-16e6-0-1163a33175713
unix 2 [ ACC ] STREAM LISTENING 11150 5885/gnome-screensa /tmp/orbit-root/linc-16f2-0-2ae9cbf7bdc22
unix 2 [ ACC ] STREAM LISTENING 11183 5871/gnome-panel /tmp/orbit-root/linc-16ef-0-6ba7b04fa1155
unix 2 [ ACC ] STREAM LISTENING 11213 5876/nautilus /tmp/orbit-root/linc-16f4-0-39885352afc4a
unix 2 [ ACC ] STREAM LISTENING 11232 5906/gnome-volume-m /tmp/orbit-root/linc-1707-0-398853534f0c7
unix 2 [ ACC ] STREAM LISTENING 11255 5898/bonobo-activat /tmp/orbit-root/linc-170a-0-39620e3ad7ddf
unix 2 [ ACC ] STREAM LISTENING 11488 5913/gnome-vfs-daem /tmp/orbit-root/linc-1719-0-22a0db48be9ea
unix 2 [ ACC ] STREAM LISTENING 11573 5973/trashapplet /tmp/orbit-root/linc-1755-0-59001db0cc2f3
unix 2 [ ACC ] STREAM LISTENING 11613 5943/bt-applet /tmp/orbit-root/linc-1737-0-3fad53dd6778d
unix 2 [ ACC ] STREAM LISTENING 11632 5965/wnck-applet /tmp/orbit-root/linc-174d-0-430d492289231
unix 2 [ ACC ] STREAM LISTENING 7527 2780/avahi-daemon: /var/run/avahi-daemon/socket
unix 2 [ ACC ] STREAM LISTENING 11754 5903/eggcups /tmp/orbit-root/linc-170f-0-63ab91caa95f9
unix 2 [ ACC ] STREAM LISTENING 11697 5998/nm-applet /tmp/orbit-root/linc-176e-0-7e890c7827874
unix 2 [ ACC ] STREAM LISTENING 11784 6045/gnome-power-ma /tmp/orbit-root/linc-1726-0-67e5013bc3eed
unix 2 [ ACC ] STREAM LISTENING 11937 5950/python /tmp/orbit-root/linc-173e-0-5b203778a163a
unix 2 [ ACC ] STREAM LISTENING 11988 6129/clock-applet /tmp/orbit-root/linc-17f1-0-505981cf8942a
unix 2 [ ACC ] STREAM LISTENING 12007 6136/mixer_applet2 /tmp/orbit-root/linc-17f8-0-505981ce444d
unix 2 [ ACC ] STREAM LISTENING 12043 6133/notification-a /tmp/orbit-root/linc-17f5-0-3e596de875f9f
unix 2 [ ACC ] STREAM LISTENING 24926 20881/1 /tmp/ssh-MHUjd20881/agent.20881
[root@rac1 ~]# netstat -lnp |grep 1521
tcp 0 0 10.11.82.161:1521 0.0.0.0:* LISTEN 4480/tnslsnr
tcp 0 0 10.11.82.151:1521 0.0.0.0:* LISTEN 4480/tnslsnr
tcp 0 0 10.11.82.201:1521 0.0.0.0:* LISTEN 4469/tnslsnr
[root@rac1 ~]# ps -ef |grep LISTEN
oracle 4469 1 0 May29 ? 00:00:08 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER_SCAN1 -inherit
oracle 4480 1 0 May29 ? 00:00:08 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER -inherit
root 7223 24292 0 14:26 pts/1 00:00:00 grep LISTEN
[root@rac1 ~]# netstat -anp |grep 1521
tcp 0 0 10.11.82.161:1521 0.0.0.0:* LISTEN 4480/tnslsnr
tcp 0 0 10.11.82.151:1521 0.0.0.0:* LISTEN 4480/tnslsnr
tcp 0 0 10.11.82.201:1521 0.0.0.0:* LISTEN 4469/tnslsnr
tcp 0 0 10.11.82.201:1521 10.11.82.201:19497 ESTABLISHED 4469/tnslsnr
tcp 0 0 10.11.82.161:47524 10.11.82.161:1521 ESTABLISHED 4008/asm_pmon_+ASM1
tcp 0 0 10.11.82.161:47537 10.11.82.161:1521 ESTABLISHED 4733/ora_pmon_orcl1
tcp 0 0 10.11.82.161:1521 10.11.82.161:47524 ESTABLISHED 4480/tnslsnr
tcp 0 0 10.11.82.161:1521 10.11.82.161:47537 ESTABLISHED 4480/tnslsnr
tcp 0 0 10.11.82.201:19497 10.11.82.201:1521 ESTABLISHED 4733/ora_pmon_orcl1
比如我們要查詢20880埠被那個程式佔用,netstat查詢不出來
[wei@vm-cbu-qa-168-13 web-deploy]$ netstat -lnp | grep 20880 (Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:20880 0.0.0.0:* LISTEN -
我們用lsof來查詢下
[html]
[wei@vm-cbu-qa-168-13 web-deploy]$ lsof -Pnl +M -i4 | grep 20880
java 15239 710 260u IPv4 87019792 TCP 10.20.168.13:35822->10.20.172.31:20880 (ESTABLISHED)
java 15239 710 285u IPv4 87038933 TCP 10.20.168.13:43058->10.20.172.93:20880 (ESTABLISHED)
java 25755 712 544u IPv4 87265535 TCP *:20880 (LISTEN)
java 25755 712 562u IPv4 87265755 TCP 10.20.168.13:40151->10.20.168.16:20880 (ESTABLISHED)
java 25755 712 563u IPv4 87265695 TCP 10.20.168.13:59947->10.20.151.21:20880 (ESTABLISHED)
java 25755 712 564u IPv4 87265696 TCP 10.20.168.13:47042->10.20.142.80:20880 (ESTABLISHED)
java 25755 712 565u IPv4 87265703 TCP 10.20.168.13:40939->10.20.141.52:20880 (ESTABLISHED)
java 25755 712 570u IPv4 87265751 TCP 10.20.168.13:43361->10.20.141.141:20880 (ESTABLISHED)
java 25755 712 571u IPv4 87265753 TCP 10.20.168.13:40960->10.20.143.111:20880 (ESTABLISHED)
java 25755 712 572u IPv4 87265752 TCP 10.20.168.13:45368->10.20.141.63:20880 (ESTABLISHED)
java 25755 712 573u IPv4 87265754 TCP 10.20.168.13:34315->10.20.168.17:20880 (ESTABLISHED)
java 27709 713 339u IPv4 87271862 TCP 10.20.168.13:50212->10.20.172.11:20880 (ESTABLISHED)
java 27709 713 341u IPv4 87271859 TCP 10.20.168.13:41128->10.20.172.88:20880 (ESTABLISHED)
java 27709 713 347u IPv4 87271865 TCP 10.20.168.13:46782->10.20.172.1:20880 (ESTABLISHED)
可以看到監聽20880埠的是程式pid是25755,user是 712
i4是查詢ipv4埠
[html]
[wei@vm-cbu-qa-168-13 web-deploy]$ lsof -Pnl +M -i4
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
portmap 1616 32 3u IPv4 3488 UDP *:111[portmapper]
portmap 1616 32 4u IPv4 3489 TCP *:111[portmapper] (LISTEN)
DragoonAg 4153 0 6u IPv4 28872832 TCP 10.20.168.13:54978->10.20.149.114:13888 (ESTABLISHED)
DragoonAg 4153 0 8u IPv4 28872826 TCP 127.0.0.1:15777 (LISTEN)
DragoonAg 4153 0 10u IPv4 28872828 TCP 127.0.0.1:15778 (LISTEN)
DragoonAg 4153 0 12u IPv4 28872836 UDP 10.20.168.13:13777->10.20.149.114:60569
DragoonAg 4153 0 13u IPv4 86898035 TCP 10.20.168.13:38027->10.20.159.108:15888 (ESTABLISHED)
DragoonAg 4153 0 15u IPv4 86648332 TCP 127.0.0.1:15777->127.0.0.1:41653 (ESTABLISHED)
python 10488 0 4u IPv4 292127 TCP 10.20.168.13:8022 (LISTEN)
java 15239 710 5u IPv4 86647757 TCP *:4208 (LISTEN)
java 15239 710 15u IPv4 86647829 TCP *:35485 (LISTEN)
java 15239 710 18u IPv4 86647831 TCP *:4207 (LISTEN)
java 15239 710 20u IPv4 86647833 TCP *:42483 (LISTEN)
java 15239 710 22u IPv4 87286934 TCP 10.20.168.13:44190->110.75.194.17:80 (CLOSE_WAIT)
java 15239 710 246u IPv4 86648330 TCP 127.0.0.1:41653->127.0.0.1:15777 (ESTABLISHED)
java 15239 710 253u IPv4 86648976 TCP *:4110 (LISTEN)
java 15239 710 255u IPv4 87010313 TCP 10.20.168.13:4110->10.20.172.31:38036
檢視資料庫的1521埠
[root@rac1 ~]# lsof -Pnl +M -i4 | grep 1521
oracle 4008 1100 28u IPv4 14719 TCP 10.11.82.161:47524->10.11.82.161:1521 (ESTABLISHED)
tnslsnr 4469 1100 14u IPv4 14019 TCP 10.11.82.201:1521 (LISTEN)
tnslsnr 4469 1100 15u IPv4 15625 TCP 10.11.82.201:1521->10.11.82.201:19497 (ESTABLISHED)
tnslsnr 4480 1100 14u IPv4 14070 TCP 10.11.82.151:1521 (LISTEN)
tnslsnr 4480 1100 15u IPv4 14071 TCP 10.11.82.161:1521 (LISTEN)
tnslsnr 4480 1100 16u IPv4 14721 TCP 10.11.82.161:1521->10.11.82.161:47524 (ESTABLISHED)
tnslsnr 4480 1100 18u IPv4 17546 TCP 10.11.82.161:1521->10.11.82.161:47537 (ESTABLISHED)
oracle 4733 1100 27u IPv4 15624 TCP 10.11.82.201:19497->10.11.82.201:1521 (ESTABLISHED)
oracle 4733 1100 31u IPv4 17545 TCP 10.11.82.161:47537->10.11.82.161:1521 (ESTABLISHED)
[wei@vm-cbu-qa-168-13 web-deploy]$ lsof -Pnl +M -i6
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
cfservd 5513 0 4u IPv6 17813 TCP *:5308 (LISTEN)
java 13334 0 64u IPv6 85851503 TCP 10.20.168.13:46591->10.20.145.12:57126 (ESTABLISHED)
java 13334 0 65u IPv6 86276005 TCP 10.20.168.13:34506->10.20.172.85:80 (CLOSE_WAIT)
java 13334 0 66u IPv6 86313523 TCP 10.20.168.13:36320->10.20.172.85:80 (CLOSE_WAIT)
java 13334 0 67u IPv6 86382763 TCP 10.20.168.13:52680->10.20.172.85:80 (CLOSE_WAIT)
java 13334 0 71u IPv6 85851508 TCP *:58126 (LISTEN)
lsof命令引數解釋
1) -P :這個選項約束著網路檔案的埠號到埠名稱的轉換。約束轉換可以使lsof執行得更快一些。在埠名稱的查詢不能奏效時,這是很有用的。
2) -n : 這個選項約束著網路檔案的埠號到主機名稱的轉換。約束轉換可以使lsof的執行更快一些。在主機名稱的查詢不能奏效時,它非常有用。
3) -l :這個選項約束著使用者ID號到登入名的轉換。在登入名的查詢不正確或很慢時,這個選項就很有用。
4) +M :此選項支援本地TCP和UDP埠對映程式的註冊報告。
5) -i4 :僅列示IPv4協議下的埠。
6) -i6 : 僅列示IPv6協議下的埠。
http://guoruisheng-163-com.iteye.com/blog/546166
http:///os/201209/153029.html
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/14710393/viewspace-762922/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- linux 下根據埠kill 程式Linux
- windows根據程式號查詢程式目錄Windows
- Linux 怎麼根據程式號,找對應的程式Linux
- 微博根據手機號查詢
- Linux 下查詢埠號由哪個程式執行Linux
- 根據作業系統程式號,查詢sql語句作業系統SQL
- linux根據字尾查詢文字Linux
- IIS7根據PID查詢對應的站點
- 「SAP技術」SAP WM 如何根據TR號碼查詢TO號碼?
- 根據rowid查詢資料檔案號,資料塊號
- 根據檔案查殺linux程式Linux
- 根據表查詢索引資訊索引
- 根據父表查詢子表
- 根據PID查詢 sqlSQL
- Linux根據程式號,檢視相關資訊Linux
- Windows 根據埠號,找出檔案安裝位置Windows
- 查詢埠號佔用
- mac查詢埠對應的PIDMac
- Laravel ORM 中,根據關聯查詢的欄位值,對主查詢排名LaravelORM
- 根據欄位名查詢所有表
- pid,sid相互查詢,根據PID查詢sqlSQL
- 如何在 Linux 中查詢服務的埠號Linux
- netstat -ano 埠對應的程式號
- 根據關鍵字查詢車輛資訊
- Oracle根據主鍵查詢外來鍵Oracle
- 根據TCode查詢User Exit and BADI
- vue+element-ui根據時間查詢VueUI
- mysql like查詢 - 根據多個條件的模糊匹配查詢MySql
- EBS(ERP)根據請求號(request ID)查詢正在執行的sqlSQL
- 根據作業系統程式號檢視oracle對應的SQL語句內容作業系統OracleSQL
- 根據查詢條件批量修改表資料
- MyBatis-maven-User例子-根據id查詢UserMyBatisMaven
- mysql根據節點查詢所有葉節點MySql
- SQL server根據表名查詢表主鍵SQLServer
- 根據Tcode查詢Menu Path的Tcode
- linux 中根據檔案的大小進行檔案的查詢Linux
- 在AIX系統根據oracle程式pid查詢sql語句AIOracleSQL
- 更改JBOSS的預設埠號和預設根應用程式