search
HomeSystem TutorialLINUXHow to monitor network usage of processes on Linux

How to monitor network usage of processes on Linux

Feb 05, 2024 pm 04:45 PM
linuxlinux tutoriallinux systemlinux commandshell scriptlinux toolsgood promiseGetting started with linuxlinux learning

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:

  1. 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
如何监控 Linux 上进程的网络使用情况

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
如何监控 Linux 上进程的网络使用情况

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

如何监控 Linux 上进程的网络使用情况

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
如何监控 Linux 上进程的网络使用情况

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
如何监控 Linux 上进程的网络使用情况

这与使用像 nethogs 这样的面向屏幕的程序类似,但以这种方式进行的优点是您可以将输出管道传输到另一个程序,如 grep 或分页程序,以便检查它:

linuxmi@linuxmi ~/www.linuxmi.com
 % netstat -p | grep 'systemd'
如何监控 Linux 上进程的网络使用情况

要查看系统上具有网络连接的所有进程,您可能需要以 root 身份运行 netstat:

linuxmi@linuxmi ~/www.linuxmi.com
 % sudo netstat
如何监控 Linux 上进程的网络使用情况

相关: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!

Statement
This article is reproduced at:良许Linux教程网. If there is any infringement, please contact admin@php.cn delete
Does the internet run on Linux?Does the internet run on Linux?Apr 14, 2025 am 12:03 AM

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.

What are Linux operations?What are Linux operations?Apr 13, 2025 am 12:20 AM

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.

Boost Productivity with Custom Command Shortcuts Using Linux AliasesBoost Productivity with Custom Command Shortcuts Using Linux AliasesApr 12, 2025 am 11:43 AM

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

What is Linux actually good for?What is Linux actually good for?Apr 12, 2025 am 12:20 AM

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.

Essential Tools and Frameworks for Mastering Ethical Hacking on LinuxEssential Tools and Frameworks for Mastering Ethical Hacking on LinuxApr 11, 2025 am 09:11 AM

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

How to learn Linux basics?How to learn Linux basics?Apr 10, 2025 am 09:32 AM

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.

What is the most use of Linux?What is the most use of Linux?Apr 09, 2025 am 12:02 AM

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.

What are the disadvantages of Linux?What are the disadvantages of Linux?Apr 08, 2025 am 12:01 AM

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.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

DVWA

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

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

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.