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!

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

The core of the Linux operating system is its command line interface, which can perform various operations through the command line. 1. File and directory operations use ls, cd, mkdir, rm and other commands to manage files and directories. 2. User and permission management ensures system security and resource allocation through useradd, passwd, chmod and other commands. 3. Process management uses ps, kill and other commands to monitor and control system processes. 4. Network operations include ping, ifconfig, ssh and other commands to configure and manage network connections. 5. System monitoring and maintenance use commands such as top, df, du to understand the system's operating status and resource usage.

Introduction Linux is a powerful operating system favored by developers, system administrators, and power users due to its flexibility and efficiency. However, frequently using long and complex commands can be tedious and er

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.

Introduction: Securing the Digital Frontier with Linux-Based Ethical Hacking In our increasingly interconnected world, cybersecurity is paramount. Ethical hacking and penetration testing are vital for proactively identifying and mitigating vulnerabi

The methods for basic Linux learning from scratch include: 1. Understand the file system and command line interface, 2. Master basic commands such as ls, cd, mkdir, 3. Learn file operations, such as creating and editing files, 4. Explore advanced usage such as pipelines and grep commands, 5. Master debugging skills and performance optimization, 6. Continuously improve skills through practice and exploration.

Linux is widely used in servers, embedded systems and desktop environments. 1) In the server field, Linux has become an ideal choice for hosting websites, databases and applications due to its stability and security. 2) In embedded systems, Linux is popular for its high customization and efficiency. 3) In the desktop environment, Linux provides a variety of desktop environments to meet the needs of different users.

The disadvantages of Linux include user experience, software compatibility, hardware support, and learning curve. 1. The user experience is not as friendly as Windows or macOS, and it relies on the command line interface. 2. The software compatibility is not as good as other systems and lacks native versions of many commercial software. 3. Hardware support is not as comprehensive as Windows, and drivers may be compiled manually. 4. The learning curve is steep, and mastering command line operations requires time and patience.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.