How to monitor network usage of processes on Linux
In computers, access to the Internet is absolutely essential. However, you might be interested in knowing which Linux processes on your computer are using the connections most frequently. Fortunately, monitoring processes using bandwidth is very easy with the help of some common Linux tools. The following is an introduction to several tools:
-
nethogs
nethogs is a program similar to htop or top that provides CPU and memory usage in terms of internet connections. It provides a quick view of which processes are using a network connection.
Similar to top, htop, or atop, nethogs is a full-screen program that updates every few seconds to show the network connections established by the current process.
You can easily install nethogs through your package manager.
For example, on Debian and Ubuntu:
linuxmi@linuxmi ~/www.linuxmi.com % sudo apt install nethogs

On Arch Linux:
sudo pacman -S nethogs
On the Red Hat series:
sudo dnf install nethogs
To run nethogs you need to run as root:
linuxmi@linuxmi ~/www.linuxmi.com % sudo nethogs

You can set it to run nethogs as a normal user with the following command:
sudo setcap "cap_net_admin,cap_net_raw+pe" /path/to/nethogs
You should replace "/path/to/nethogs" with the absolute pathname of nethogs. You can find it using which command:
which nethogs
Related:
- How to use htop to monitor Linux system processes https://www.linuxmi.com/htop.html
- The most important Linux commands no one teaches you https://www.linuxmi.com/linux-commands-important.html
2、lsof

Although lsof is a utility for listing open files, it can also list open network connections. The -i option lists Internet connections attached to processes running on the system. After all, in Linux, everything is a file.
To view the current internet connection, use the following command:
linuxmi@linuxmi ~/www.linuxmi.com % lsof -i
lsof displays the name, PID, file descriptor, internet connection type, size, protocol, and the connection's official file name for any command that has an open Internet connection.
Using the -i4 and -i6 options, you can view connections using IPv4 or IPv6.
Most likely you already have lsof installed. If you don't have it installed, it's easy to install on major Linux distributions.
On Debian and Ubuntu, enter:
sudo apt install lsof
And on Arch:
sudo pacman -S lsof
On Red Hat series distributions:
sudo dnf install lsof
3、netstat
netstat is a powerful program that allows you to view network connections on your system. But it doesn't show which processes the network connection is attached to. Like lsof, you can use command line options to view this information.
netstat is part of the net-tools package. You can install it on most Linux distributions using the default package manager.
For example, on Debian or Ubuntu:
sudo apt install net-tools
On Arch Linux:
sudo pacman -S net-tools
To install netstat on Fedora, CentOS and RHEL, run:
sudo dnf install net-tools
You can run netstat on the command line. By default, it displays the connection's protocol, address, and status, but the -p option adds a column showing the process ID and command name.
linuxmi@linuxmi ~/www.linuxmi.com % netstat -p

When you run netstat, it will just list all network connections and then exit. Using the -c option you can see a continuously updated list of connections:
linuxmi@linuxmi ~/www.linuxmi.com % netstat -pc

这与使用像 nethogs 这样的面向屏幕的程序类似,但以这种方式进行的优点是您可以将输出管道传输到另一个程序,如 grep 或分页程序,以便检查它:
linuxmi@linuxmi ~/www.linuxmi.com % netstat -p | grep 'systemd'

要查看系统上具有网络连接的所有进程,您可能需要以 root 身份运行 netstat:
linuxmi@linuxmi ~/www.linuxmi.com % sudo netstat

相关:Linux 下 12 个监视网络连接的 ss 命令示例 https://www.linuxmi.com/linux-ss-command.html
现在您可以看到哪些 Linux 应用程序在占用您的带宽
与许多现代操作系统一样,Linux 与互联网紧密连接。有时候很难追踪哪些进程在使用您的带宽。通过使用 nethogs、lsof 和 netstat 等工具,您可以找到具有打开连接的进程。
有时进程会失控,即使有连接。在 Linux 上,您可以轻松终止任何恶意进程。
The above is the detailed content of How to monitor network usage of processes on Linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.
