通过端口号查找进程id

通过端口号查找进程id

我正在尝试(目前收效甚微)在我的 Fedora 24 服务器上设置 Dovecot 邮件服务器。我已经安装了 Dovecot 并设置了conf文件,一切都很好。但是当我跑步时:

systemctl restart dovecot

编辑conf文件后我收到这条消息

Job for dovecot.service failed because the control process exited with error code. See "systemctl status dovecot.service" and "journalctl -xe" for details

运行systemctl status dovecot.service给了我一个不同的错误

[root@fedora app]# systemctl status dovecot.service
● dovecot.service - Dovecot IMAP/POP3 email server
   Loaded: loaded (/usr/lib/systemd/system/dovecot.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2016-08-16 15:02:30 UTC; 37min ago
     Docs: man:dovecot(1)
           http://wiki2.dovecot.org/
  Process: 11293 ExecStart=/usr/sbin/dovecot (code=exited, status=89)
  Process: 11285 ExecStartPre=/usr/libexec/dovecot/prestartscript (code=exited, status=0/SUCCESS)

Aug 16 15:02:30 fedora dovecot[11293]: Error: service(imap-login): listen(*, 993) failed: Address already in use
Aug 16 15:02:30 fedora dovecot[11293]: master: Error: service(imap-login): listen(*, 993) failed: Address already in use
Aug 16 15:02:30 fedora dovecot[11293]: Error: service(imap-login): listen(::, 993) failed: Address already in use
Aug 16 15:02:30 fedora dovecot[11293]: master: Error: service(imap-login): listen(::, 993) failed: Address already in use
Aug 16 15:02:30 fedora dovecot[11293]: Fatal: Failed to start listeners
Aug 16 15:02:30 fedora dovecot[11293]: master: Fatal: Failed to start listeners
Aug 16 15:02:30 fedora systemd[1]: dovecot.service: Control process exited, code=exited status=89
Aug 16 15:02:30 fedora systemd[1]: Failed to start Dovecot IMAP/POP3 email server.
Aug 16 15:02:30 fedora systemd[1]: dovecot.service: Unit entered failed state.
Aug 16 15:02:30 fedora systemd[1]: dovecot.service: Failed with result 'exit-code'.

我尝试运行lsof -i | grep 993,但这不会产生任何进程。知道如何解决这个问题吗?

答案1

netstat当您尝试解决许多与网络相关的问题时,它是您的朋友。要找到侦听端口,我会使用netstat -tulpn | grep :<port number>

例如,要查找哪些 pid 正在端口 22 上侦听,我将运行:

netstat -tulpn | grep :22
tcp  0  0 0.0.0.0:22    0.0.0.0:*    LISTEN      3062/sshd

这告诉我 pid 3062 的 sshd 正在侦听端口 22。

答案2

ss您可能还喜欢使用比 grep 端口号更系统、更精确的解决方案。

# ss -t -l 'sport = 22'
State      Recv-Q Send-Q Local Address:Port                 Peer Address:Port
LISTEN     0      128        *:ssh                      *:*
LISTEN     0      128       :::ssh                     :::*

相关内容