当前位置: 首页 > 科技观察

如何在Linux中找到CPU占用率高的进程

时间:2023-03-19 00:22:13 科技观察

在上一篇文章中我们讨论了如何在Linux中找到最耗内存的进程。在Linux系统中你也可能会遇到发现CPU使用率高的进程的情况。如果是这样,那么您需要列出系统上的高CPU密集型进程以确保确定。我认为只有两种方法可以做到:使用top命令和ps命令。出于某些原因,我更喜欢使用top命令而不是ps命令。但是这两种工具都可以实现你想要的,所以你可以根据自己的需要来决定使用哪一种。这两种工具都被Linux系统管理员广泛使用。1)如何使用top命令找出Linux中CPU占用率高的进程在众多的Linux系统性能监控工具中,Linux的top命令是一款非常优秀且广为人知的工具。top命令提供了Linux系统运行进程的动态实时视图。它显示系统概览信息和当前由Linux内核管理的进程列表。它显示了很多系统信息,如CPU使用率、内存使用率、交换内存、正在运行的进程数、当前系统正常运行时间、系统负载、缓冲区大小、缓存大小、进程PID等等。默认情况下,top命令的输出按CPU使用率排序,结果每5秒更新一次。如果您想要更清晰的视图以深入了解结果,以批处理模式运行top命令是一个不错的方法。同时需要理解top命令输出的含义,从而解决系统的性能问题。#top-b|head-50top-00:19:17up14:23,1user,loadaverage:2.46,2.18,1.97Tasks:306total,1running,305sleeping,0stopped,0zombie%Cpu0:10.4us,3.0sy,0.0ni,83.9id,0.0wa,1.3hi,1.3si,0.0st%Cpu1:17.0us,3.0sy,0.0ni,78.7id,0.0wa,0.3hi,1.0si,0.0st%Cpu2:13.0us,4.0sy,0.0ni,81.3id,0.0wa,0.3hi,1.3si,0.0st%Cpu3:12.3us,3.3sy,0.0ni,82.5id,0.3wa,0.7hi,1.0si,0.0st%Cpu4:12.2us,3.0sy,0.0ni,82.8id,0.7wa,0.3hi,1.0si,0.0st%Cpu5:6.4us,2.7sy,0.0ni,89.2id,0.0wa,0.7hi,1.0si,0.0st%Cpu6:26.7us,3.4sy,0.0ni,68.6id,0.0wa,0.7hi,0.7si,0.0st%Cpu7:15.6us,4.0sy,0.0ni,78.8id,0.0wa,0.7hi,1.0si,0.0stKiBMem:16248556total,1448920free,8571484used,6228152buff/cacheKiBSwap:17873388total,17873388free,0used.4596044availMemPIDUSERPRNIVIRTRESSHRS%CPU%MEMTIME+COMMAND2179daygeek203106324613584327564S79.53.814:19.76WebContent1714daygeek204603372974600403504S20.26.065:18.91firefox1227daygeek204192012376332180348S13.92.320:43.26gnome-shell18324daygeek203296192766040127948S6.34.79:18.12WebContent1170daygeek201008264572036546180S6.03.518:07.85Xorg4684daygeek2033637081.1g1.0gS3.67.213:49.92VirtualBoxVM4607daygeek2045910401.7g1.6gS3.011.014:09.65VirtualBoxVM1211daygeek9-1128652682103216588S2.00.110:46.37pulseaudio4562daygeek2010968882881221044S1.70.24:42.93VBoxSVC1783daygeek203123888376896134788S1.32.339:32.56WebContent3286daygeek203089736404088184968S1.02.541:57.44WebContent上面的命令的各部分解释:top:command-b:批处理文件方式head-50:显示输出结果的前50个PID:进程IDUSER:进程所有者PR:进程级别NI:the进程的NICE值VIRT:进程使用的虚拟内存RES:进程使用的物理内存SHR:进程使用的共享内存S:这个值表示进程的状态:S=sleeping,R=running,Z=Zombieprocess%CPU:进程占用CPU的百分比%MEM:进程使用RAM的比例TIME+:进程运行了多长时间COMMAND:进程名如果想看命令的完整路径而不是命令名称,按以下格式运行top命令:#top-c-b|head-50top-00:28:49up14:33,1user,loadaverage:2.43,2.49,2.23Tasks:305total,1running,304sleeping,0stopped,0zombie%Cpu0:11.7us,3.7sy,0.0ni,82.3id,0.0wa,1.0hi,1.3si,0.0st%Cpu1:13.6us,3.3sy,0.0ni,81.1id,0.7wa,0.3hi,1.0si,0.0st%Cpu2:10.9us,2.6sy,0.0ni,85.1id,0.0wa,0.3hi,1.0si,0.0st%Cpu3:16.0us,2.6sy,0.0ni,80.1id,0.0wa,0.3hi,1.0si,0.0st%Cpu4:9.2us,3.6sy,0.0ni,85.9id,0.0wa,0.3hi,1.0si,0.0st%Cpu5:15.6us,2.9sy,0.0ni,80.5id,0.0wa,0.3hi,0.7si,0.0st%Cpu6:11.6us,4.3sy,0.0ni,82.7id,0.0wa,0.3hi,1.0si,0.0st%Cpu7:8.0us,3.0sy,0.0ni,87.3id,0.0wa,0.7hi,1.0si,0.0stKiBMem:16248556total,1022456free,8778508used,6447592buff/cacheKiBSwap:17873388total,17873388free,0used.4201560availMemPIDUSERPRNIVIRTRESSHRS%CPU%MEMTIME+COMMAND18527daygeek203151820624808325748S52.83.859:26.72/usr/lib/firefox/firefox-contentproc-childID18-isForBrowser-prefsLen10002-prefMapSize213431-parentBuildID20191031132559-greomni/+1714daygeek204764668910940443228S21.55.668:59.33/usr/lib/firefox/firefox--new-window1227daygeek204193108377344181404S11.62.321:47.36/usr/bin/gnome-shell1170daygeek201008820572700546844S5.63.519:05.10/usr/lib/Xorgvt2-displayfd3-auth/run/user/1000/gdm/Xauthority-nolistentcp-backgroundnone-noreset-keeptty-verbose318324daygeek203300288789344127948S5.04.99:46.89/usr/lib/firefox/firefox-contentproc-childID16-isForBrowser-prefsLen10002-prefMapSize213431-parentBuildID20191031132559-greomni/+4684daygeek2033637081.1g1.0gS3.67.214:10.18/usr/lib/virtualbox/VirtualBoxVM--commentCentOS7--startvm002f47b8-2af2-48f5-be1d-67b67e03514c--no-startvm-errormsgbox4607daygeek2045910401.7g1.6gS3.011.014:28.86/usr/lib/virtualbox/VirtualBoxVM--commentUbuntu-18.04--startvme8c32dbb-8b01-41b0-977a-bf28b9db1117--no-startvm-errormsgbox1783daygeek203132640451924132168S2.62.839:49.66/usr/lib/firefox/firefox-contentproc-childID1-isForBrowser-prefsLen1-prefMapSize213431-parentBuildID20191031132559-greomni/usr/l+1211daygeek9-1128652682127216828S2.00.111:01.29/usr/bin/pulseaudio--daemonize=no4562daygeek2010968882881221044S1.70.24:49.33/usr/lib/virtualbox/VBoxSVC--auto-shutdown16865daygeek203073364430596124652S1.32.78:04.02/usr/lib/firefox/firefox-contentproc-childID15-isForBrowser-prefsLen10002-prefMapSize213431-parentBuildID20191031132559-greomni/+2179daygeek202945348429644172940S1.02.615:20.90/usr/lib/firefox/firefox-contentproc-childID6-isForBrowser-prefsLen7821-prefMapSize213431-parentBuildID20191031132559-greomni/us+2)怎样使用ps命令找出Linux中CPU占用高进程ps是进程状态processstatus的缩写,可以显示系统中活跃/运行进程的信息。它提供当前进程及其详细信息,例如用户名、用户ID、CPU使用率、内存使用率、启动日期时间的进程快照、命令名称等。#ps-eopid,ppid,%mem,%cpu,cmd--sort=-%cpu|headPIDPPID%MEM%CPUCMD1852717144.240.3/usr/lib/firefox/firefox-contentproc-childID18-isForBrowser-prefsLen10002-prefMapSize213431-parentBuildID20191031132559-greomni/usr/lib/firefox/omni.ja-appomni/usr/lib/firefox/browser/omni.ja-appdir/usr/lib/firefox/browser1714truetab171411525.68.0/usr/lib/firefox/firefox--new-window1832417144.96.3/usr/lib/firefox/firefox-contentproc-childID16-isForBrowser-prefsLen10002-prefMapSize213431-parentBuildID20191031132559-greomni/usr/lib/firefox/omni.ja-appomni/usr/lib/firefox/browser/omni.ja-appdir/usr/lib/firefox/browser1714truetab328617142.05.1/usr/lib/firefox/firefox-contentproc-childID14-isForBrowser-prefsLen8078-prefMapSize213431-parentBuildID20191031132559-greomni/usr/lib/firefox/omni.ja-lib/firefoxni/us/browser/omni.ja-appdir/usr/lib/firefox/browser1714truetab178317143.04.5/usr/lib/firefox/firefox-contentproc-childID1-isForBrowser-prefsLen1-prefMapSize213431-parentBuildID20191031132559-greomni/usr/lib/firefox/omni.ja-appomni/usr/lib/firefox/browser/omni.ja-appdir/usr/lib/firefox/browser1714truetab122711522.32.5/usr/bin/gnome-shell117011683.52.2/usr/lib/Xorgvt2-displayfd3-auth/run/user/1000/gdm/Xauthority-nolistentcp-backgroundnone-noreset-keeptty-verbose31686517142.52.1/usr/lib/firefox/firefox-contentproc-childID15-isForBrowser-prefsLen10002-prefMap31Size191250310-greomni/usr/lib/firefox/omni.ja-appomni/usr/lib/firefox/browser/omni.ja-appdir/usr/lib/firefox/browser1714truetab217917142.71.8/usr/lib/firefox/firefox-contentproc-childID6-isForBrowser-prefsLen7821-prefMapSize213431-parentBuildID20191031132559-greomni/usr/lib/firefox/omni.ja-appomni/usr/lib/firefox/browser/omni.ja-appdir/usr/lib/firefox/browser1714truetab部分解释:ps:命令name-e:选择所有进程-o:自定义输出格式–sort=-%cpu:根据CPU使用率对输出结果进行排序head:显示结果的前10行PID:进程IDPPID:父进程的ID%MEM:进程%CPU使用的RAM百分比:进程占用的CPU百分比Command:进程名如果只想查看命令名而不是命令的绝对路径,按如下格式运行ps命令:#ps-eopid,ppid,%mem,%cpu,comm--sort=-%cpu|headPIDPPID%MEM%CPUCOMMAND1852717144.140.4WebContent171411525.78.0firefox1832417144.96.3WebContent328617142.05.1WebContent178317143.04.5WebContent122711522.32.5gnome-shell117011683.52.2Xorg1686517142.42.1WebContent217917142.71.8WebContent

最新推荐
猜你喜欢