Ubuntu find source of process in top command năm 2024

Linux is an open-source and highly popular operating system, and it is the preferred option for deploying servers and applications on the Internet. It is very popular due to its command-line interface and built-in tools which help you to perform your tasks quickly and save a lot of time.

Sometimes your application or website is very slow or unresponsive due to high memory and CPU usage. In this case, you can use the ps and top command to identify which processes are eating all the resources on your system.

In this post, we will explain how to find top memory and CPU resource-consuming processes in Linux.

Use ps Command to Find Top Processes

ps is a Linux command-line utility with many options that helps you to display output in different formats.

To list all running processes in Linux, run the following command:

ps aux

This will show you an overview of all running processes:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.1 0.1 160716 9904 ? Ss 16:58 0:06 /sbin/init splash root 2 0.0 0.0 0 0 ? S 16:58 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_gp] root 4 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_par_gp] root 6 0.0 0.0 0 0 ? I< 16:58 0:00 [kworker/0:0H-kb] root 9 0.0 0.0 0 0 ? I< 16:58 0:00 [mm_percpu_wq] root 10 0.0 0.0 0 0 ? S 16:58 0:00 [ksoftirqd/0] root 11 0.1 0.0 0 0 ? I 16:58 0:05 [rcu_sched] root 12 0.0 0.0 0 0 ? S 16:58 0:00 [migration/0] You can use the ps command with –sort argument to sort the output by memory and CPU usage.

The syntax for using the sort argument is:

ps aux --sort

To find the top running processes by CPU usage, run the following command:

ps aux --sort -%cpu

Output:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND vyom 8115 7.8 3.0 25770108 233784 tty2 Sl+ 17:58 1:37 /opt/google/chrome/chrome --type=renderer --enable-crashpad --crashpad-handler-pid=2815 --enable-crash-reporter=373d0de2-e0c8-419c-b983-084c773fcd79, --display-capture-permissions-policy-allowed --change-stack-guard-on-fork=enable --lang=en-GB --num-raster-threads=1 --renderer-client-id=82 --launch-time-ticks=3564377766 --shared-files=v8_context_snapshot_data:100 --field-trial-handle=0,i,7343938639469663677,16234295293987540603,131072 --enable-features=PasswordImport vyom 8164 6.2 3.0 25705000 233456 tty2 Sl+ 17:58 1:16 /opt/google/chrome/chrome --type=renderer --enable-crashpad --crashpad-handler-pid=2815 --enable-crash-reporter=373d0de2-e0c8-419c-b983-084c773fcd79, --display-capture-permissions-policy-allowed --change-stack-guard-on-fork=enable --lang=en-GB --num-raster-threads=1 --renderer-client-id=85 --launch-time-ticks=3576904510 --shared-files=v8_context_snapshot_data:100 --field-trial-handle=0,i,7343938639469663677,16234295293987540603,131072 --enable-features=PasswordImport vyom 2806 4.4 4.5 17565904 343660 tty2 SLl+ 17:01 3:26 /opt/google/chrome/chrome --enable-crashpad vyom 2314 4.3 2.9 3472696 222248 tty2 Rl+ 17:00 3:22 /usr/bin/gnome-shell To find the top running processes by memory usage, run the following command:

ps aux --sort -%mem

Output:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND vyom 2806 4.4 4.5 17562832 343688 tty2 SLl+ 17:01 3:26 /opt/google/chrome/chrome --enable-crashpad vyom 8115 7.8 3.0 25770108 232204 tty2 Sl+ 17:58 1:38 /opt/google/chrome/chrome --type=renderer --enable-crashpad --crashpad-handler-pid=2815 --enable-crash-reporter=373d0de2-e0c8-419c-b983-084c773fcd79, --display-capture-permissions-policy-allowed --change-stack-guard-on-fork=enable --lang=en-GB --num-raster-threads=1 --renderer-client-id=82 --launch-time-ticks=3564377766 --shared-files=v8_context_snapshot_data:100 --field-trial-handle=0,i,7343938639469663677,16234295293987540603,131072 --enable-features=PasswordImport vyom 8164 6.1 3.0 25705000 230116 tty2 Sl+ 17:58 1:16 /opt/google/chrome/chrome --type=renderer --enable-crashpad --crashpad-handler-pid=2815 --enable-crash-reporter=373d0de2-e0c8-419c-b983-084c773fcd79, --display-capture-permissions-policy-allowed --change-stack-guard-on-fork=enable --lang=en-GB --num-raster-threads=1 --renderer-client-id=85 --launch-time-ticks=3576904510 --shared-files=v8_context_snapshot_data:100 --field-trial-handle=0,i,7343938639469663677,16234295293987540603,131072 --enable-features=PasswordImport If you want to show only the top 10 memory consuming processes, run the following command:

ps aux --sort -%mem | head -10

If you want to show only the command name instead of the full path of the command, run the following command:

ps -eo pid,ppid,cmd,comm,%mem,%cpu --sort=-%mem | head -10

Output:

PID PPID CMD COMMAND %MEM %CPU 2806 1 /opt/google/chrome/chrome - chrome 4.5 4.3 8164 2828 /opt/google/chrome/chrome - chrome 3.2 6.2 8115 2828 /opt/google/chrome/chrome - chrome 3.0 7.8 2314 2176 /usr/bin/gnome-shell gnome-shell 2.9 4.4 2996 2828 /opt/google/chrome/chrome - chrome 2.4 0.5 8074 2828 /opt/google/chrome/chrome - chrome 2.4 0.8 7520 2828 /opt/google/chrome/chrome - chrome 2.4 0.3 8175 2828 /opt/google/chrome/chrome - chrome 2.2 0.3 2858 2823 /opt/google/chrome/chrome - chrome 2.2 3.8

Also Read

How to Check Linux CPU Usage or Utilization

Use the top Command to Find Top Processes by Memory and CPU Usage

top is another built-in Linux command-line utility that can be used to show all running processes in Linux. You can use various options with the top command to filter the output based on your requirements.

You can use the top command with the -o flag to show the top memory consuming processes:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.1 0.1 160716 9904 ? Ss 16:58 0:06 /sbin/init splash root 2 0.0 0.0 0 0 ? S 16:58 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_gp] root 4 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_par_gp] root 6 0.0 0.0 0 0 ? I< 16:58 0:00 [kworker/0:0H-kb] root 9 0.0 0.0 0 0 ? I< 16:58 0:00 [mm_percpu_wq] root 10 0.0 0.0 0 0 ? S 16:58 0:00 [ksoftirqd/0] root 11 0.1 0.0 0 0 ? I 16:58 0:05 [rcu_sched] root 12 0.0 0.0 0 0 ? S 16:58 0:00 [migration/0] 0

Output:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.1 0.1 160716 9904 ? Ss 16:58 0:06 /sbin/init splash root 2 0.0 0.0 0 0 ? S 16:58 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_gp] root 4 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_par_gp] root 6 0.0 0.0 0 0 ? I< 16:58 0:00 [kworker/0:0H-kb] root 9 0.0 0.0 0 0 ? I< 16:58 0:00 [mm_percpu_wq] root 10 0.0 0.0 0 0 ? S 16:58 0:00 [ksoftirqd/0] root 11 0.1 0.0 0 0 ? I 16:58 0:05 [rcu_sched] root 12 0.0 0.0 0 0 ? S 16:58 0:00 [migration/0] 1

If you want to display only the top 10 memory consuming processes, run the following command:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.1 0.1 160716 9904 ? Ss 16:58 0:06 /sbin/init splash root 2 0.0 0.0 0 0 ? S 16:58 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_gp] root 4 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_par_gp] root 6 0.0 0.0 0 0 ? I< 16:58 0:00 [kworker/0:0H-kb] root 9 0.0 0.0 0 0 ? I< 16:58 0:00 [mm_percpu_wq] root 10 0.0 0.0 0 0 ? S 16:58 0:00 [ksoftirqd/0] root 11 0.1 0.0 0 0 ? I 16:58 0:05 [rcu_sched] root 12 0.0 0.0 0 0 ? S 16:58 0:00 [migration/0] 2

Output:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.1 0.1 160716 9904 ? Ss 16:58 0:06 /sbin/init splash root 2 0.0 0.0 0 0 ? S 16:58 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_gp] root 4 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_par_gp] root 6 0.0 0.0 0 0 ? I< 16:58 0:00 [kworker/0:0H-kb] root 9 0.0 0.0 0 0 ? I< 16:58 0:00 [mm_percpu_wq] root 10 0.0 0.0 0 0 ? S 16:58 0:00 [ksoftirqd/0] root 11 0.1 0.0 0 0 ? I 16:58 0:05 [rcu_sched] root 12 0.0 0.0 0 0 ? S 16:58 0:00 [migration/0] 3

If you want to display only the top 10 CPU-consuming processes, run the following command:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.1 0.1 160716 9904 ? Ss 16:58 0:06 /sbin/init splash root 2 0.0 0.0 0 0 ? S 16:58 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_gp] root 4 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_par_gp] root 6 0.0 0.0 0 0 ? I< 16:58 0:00 [kworker/0:0H-kb] root 9 0.0 0.0 0 0 ? I< 16:58 0:00 [mm_percpu_wq] root 10 0.0 0.0 0 0 ? S 16:58 0:00 [ksoftirqd/0] root 11 0.1 0.0 0 0 ? I 16:58 0:05 [rcu_sched] root 12 0.0 0.0 0 0 ? S 16:58 0:00 [migration/0] 4

Output:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.1 0.1 160716 9904 ? Ss 16:58 0:06 /sbin/init splash root 2 0.0 0.0 0 0 ? S 16:58 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_gp] root 4 0.0 0.0 0 0 ? I< 16:58 0:00 [rcu_par_gp] root 6 0.0 0.0 0 0 ? I< 16:58 0:00 [kworker/0:0H-kb] root 9 0.0 0.0 0 0 ? I< 16:58 0:00 [mm_percpu_wq] root 10 0.0 0.0 0 0 ? S 16:58 0:00 [ksoftirqd/0] root 11 0.1 0.0 0 0 ? I 16:58 0:05 [rcu_sched] root 12 0.0 0.0 0 0 ? S 16:58 0:00 [migration/0] 5

Also Read

How to Check Size of Files and Directory on Linux

Conclusion

In this post, we explained how to find top CPU and Memory consuming processes in Linux. You can use these commands to troubleshoot performance-related issues in Linux. Try it on VPS hosting from Atlantic.Net!

How do I find the source of a process in Ubuntu?

You can use the lsof command to find the files that are opened by the running process. This will help you the find the directory where the cache.sh file is located. Usage: lsof -p PID , where PID is the actual PID of the process. locate cache.sh will find the file.16 thg 10, 2018nullHow can I find the origin of a process and stop it permanently? - Ask ...askubuntu.com › questions › how-can-i-find-the-origin-of-a-process-and-st...null

How do I see the process path in top?

To view the entire file path of your processes, press “c” while top is running.nullHow to Use the top Command to Monitor System Processes and ...gridpane.com › how-to-use-the-top-command-to-monitor-system-processes...null

How to find process in top command?

top Command Syntax and Options. To run the top command, type top in the command line and press Enter. The command starts in interactive command mode, showing the active processes and other system information.nullHow to Use the top Command in Linux - phoenixNAPphoenixnap.com › top-command-in-linuxnull

How do I find the origin of a process in Linux?

Most reliable way is to look at the /proc dir for the process. Each process has a /proc// directory where it keeps information like: cwd link to the current working directory. fd a dir with links to the open files [file descriptors]nullLinux: How to know where a process was started and how it was started?serverfault.com › questions › linux-how-to-know-where-a-process-was-star...null

Chủ Đề