- netstat – a command-line tool that displays network connections, routing tables, and a number of network interface statistics.
- fuser – a command line tool to identify processes using files or sockets.
- lsof – a command line tool to list open files under Linux / UNIX to report a list of all open files and the processes that opened them.
- /proc/$pid/ file system – Under Linux /proc includes a directory for each running process (including kernel processes) at /proc/PID, containing information about that process, notably including the processes name that opened port.
example
查询rails端口占用进程:
例如:lsof -i:3000
杀掉进程:
$ kill -9 2212
其中-9 制定了传递给进程的信号是9,即强制、尽快终止进程。
2212则是上面查到的PID。
kill、killall
这两个命令是用来向进程发送信号的。kill 命令需要进程号作为参数,而 killall 需要进程名称。
另外,还可以在这两个命令后附加要发送信号序号作为参数。默认情况下,它们都向相关进程发送信号 15 (TERM)。例如,如果您想要终止 PID 为 785 的进程,请输入以下命令:
$ kill 785
$ kill -19 785
假设您知道想要终止的进程的命令名称。您可以通过该名称来终止它,而不用再使用 ps 找出该进程的进程号:
$ killall -9 mozilla