阿里云服务器是一款功能强大的云计算产品,常常被用来部署各种应用程序。在使用阿里云服务器时,我们经常需要查看和管理正在运行的进程。本文将介绍如何在阿里云服务器中查看进程。
一、进程的概念
计算机上的进程是指正在运行的程序实例。在 Linux 操作系统中,每个运行的程序都是一个进程。进程可以占用 CPU 和内存等系统资源,通过查看进程,我们可以了解到服务器中正在运行的程序、运行状态以及资源占用情况。
二、使用 top 命令查看进程
在 Linux 系统中,可以使用 top 命令查看系统中正在运行的进程。top 命令会实时显示系统中进程的运行情况,包括 CPU 占用情况、内存占用情况、进程 ID 等信息。
在终端输入以下命令即可使用 top 命令查看进程:
“`
top
“`
执行该命令后,终端将显示类似下面的内容:
“`
top – 11:08:55 up 2 days, 3:06, 2 users, load average: 0.05, 0.02, 0.00
Tasks: 179 total, 1 running, 177 sleeping, 1 stopped, 0 zombie
%Cpu(s): 1.2 us, 0.8 sy, 0.0 ni, 98.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 2048176 total, 392668 free, 1252044 used, 401464 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 579512 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME COMMAND
1362 root 20 0 266668 26716 19896 S 8.9 1.3 29:47.20 jupyterhub-single
30330 root 20 0 72936 4444 3472 R 0.7 0.2 0:00.03 top
1 root 20 0 164672 4688 3016 S 0.0 0.2 1:44.29 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.03 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.04 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:
7 root 20 0 0 0 0 S 0.0 0.0 2:23.07 rcu_sched
8 root 20 0 0 0 0 S 0.0 0.0 0:26.09 rcu_bh
9 root rt 0 0 0 0 S 0.0 0.0 0:00.01 migration/0
10 root rt 0 0 0 0 S 0.0 0.0 0:00.04 watchdog/0
11 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 khelper
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 netns
13 root 20 0 0 0 0 S 0.0 0.0 0:00.04 kauditd
14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khungtaskd
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 oom_reaper
16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback
17 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kcompactd0
18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 crypto
19 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
20 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kblockd
21 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 md
22 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 edac-poller
23 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 watchdogd
24 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/u17:0
26 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khvcd
27 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kintegrityd
28 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
29 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
30 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khvcd
31 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 xfsalloc
32 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 xfs_mru_cache
33 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/u17:1
34 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0
35 root 20 0 0 0 0 S 0.0 0.0 0:00.00 jbd2/xvdb1-8
36 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:1
37 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 ext4-rsv-conver
38 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/u18:1
49 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 ipv6_addrconf
170 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:2
“`
在 top 命令的输出中,第一行是系统的运行时间、用户数、平均负载等信息,第二行是正在运行的任务数,其中 running 表示正在运行的任务数,sleeping 表示正在等待 CPU 的任务数,stopped 表示已经停止的任务数,zombie 表示僵尸进程的数量。
第三行是 CPU 的使用情况,包括用户空间、内核空间、空闲时间等的 CPU 时间百分比。用户空间指的是应用程序占用的 CPU 时间,内核空间指的是内核代码和驱动程序占用的 CPU 时间。
第四行是内存使用情况,包括系统总内存、空闲内存和已用内存等信息。
接下来的输出是各个进程的详细信息,包括 PID、USER、CPU 占用率、内存占用率、进程运行时间和命令名称等。
通过 top 命令可以实时监控系统中的进程,可以查看进程的运行状态、CPU 和内存占用情况,十分方便。
三、使用 ps 命令查看进程
除了使用 top 命令,我们还可以使用 ps 命令查看进程信息。ps 命令是一个非常强大的命令,可以显示当前进程的详细信息。
通过以下命令可以使用 ps 命令查看进程信息:
“`
ps aux | less
“`
使用该命令后,终端将显示当前系统中运行的所有进程和它们的详细信息,包括 PID、USER、CPU 占用率、内存占用率、进程运行时间和命令名称等。
ps 命令也可以根据关键字过滤出我们需要的进程。例如,我们要查看所有名字中包含 nginx 的进程,可以执行如下命令:
“`
ps aux | grep nginx
“`
该命令会将所有包含 nginx 的进程显示出来。
四、使用 htop 命令查看进程
htop 命令是一个交互式的进程监视器,可以实时显示系统中进程的状态和占用资源情况。与 top 命令相比,htop 命令的界面更加友好,可以让用户更加方便地查看和管理进程。
在阿里云服务器中,可以通过 yum 命令安装 htop 命令:
“`
sudo yum install htop
“`
安装完成后,可以通过以下命令启动 htop 命令:
“`
htop
“`
执行该命令后,终端将显示类似下面的内容:
“`
│ UID │ PID │ PPID │ C │ STIME │ TTY │ TIME │ CMD │
│ 0│ 1│ 0│ 0.0 │1月16 │? │ 00:01:44│ /usr/lib/systemd/systemd –switched- │
│ 0│ 2│ 0│ 0.0 │1月16 │? │ 00:00:04│ [kthreadd] │
│ 0│ 3│ 2│ 0.0 │1月16 │? │ 00:00:05│ [ksoftirqd/0] │
│ 0│ 5│ 2│ 0.0 │1月16 │? │ 00:00:00│ [kworker/0:0H] │
│ 0│ 7│ 2│ 0.0 │1月16 │? │ 00:02:23│ [rcu_sched] │
│ 0│ 8│ 2│ 0.0 │1月16 │? │ 00:00:26│ [rcu_bh] │
│ 0│ 9│ 2│ 0.0 │1月16 │? │ 00:00:01│ [migration/0] │
│ 0│ 10│ 2│ 0.0 │1月16 │? │ 00:00:04│ [watchdog/0] │
│ 0│ 11│ 2│ 0.0 │1月16 │? │ 00:00:00│ [khelper] │
│ 0│ 12│ 2│ 0.0 │1月16 │? │ 00:00:00│ [netns] │
│ 0│ 13│ 2│ 0.0 │1月16 │? │ 00:00:04│ [kauditd] │
│ 0│ 14│ 2│ 0.0 │1月16 │? │ 00:00:00│ [khungtaskd] │
│ 0│ 15│ 2│ 0.0 │1月16 │? │ 00:00:00│ [oom_reaper] │
│ 0│ 16│ 2│ 0.0 │1月16 │? │ 00:00:00│ [writeback] │
│ 0│ 17│ 2│ 0.0 │1月16 │? │ 00:00:00│ [kcompactd0] │
│ 0│ 18│ 2│ 0.0 │1月16 │? │ 00:00:00│ [crypto] │
│ 0│ 19│ 2│ 0.0 │1月16 │? │ 00:00:00│ [bioset] │
│ 0│ 20│ 2│ 0.0 │1月16 │? │ 00:00:00│ [kblockd] │
│ 0│ 21│ 2│ 0.0 │1月16 │? │ 00:00:00│ [md] │
│ 0│ 22│ 2│ 0.0 │1月16 │? │ 00:00:00│ [edac-poller] │
│ 0│ 23│ 2│ 0.0 │1月16 │? │ 00:00:00│ [watchdogd] │
│ 0│ 24│ 2│ 0.0 │1月16 │? │ 00:00:00│ [kworker/u17:0] │
│ 0│ 26│ 2│ 0.0 │1月16 │? │ 00:00:00│ [khvcd] │
│ 0│ 27│ 2│ 0.0 │1月16 │? │ 00:00:00│ [kintegrityd] │
│ 0│ 28│ 2│ 0.0 │1月16 │? │ 00:00:00│ [kdevtmpfs] │
│ 0│ 29│ 2│ 0.0 │1月16 │? │ 00:00:00│ [netns
转转请注明出处:https://www.yunxiaoer.com/93477.html