Linux の 4 つの小さなドラゴンのプロセス コマンド: ps、netstat、top、kill は、一度読むだけで十分です。

ps: プロセス情報の表示
netstat: ポート情報の表示
top: プロセス情報を動的に監視
kill: プロセスを強制終了

1. psコマンドの使用方法

psこのコマンドは、プロセス関連の情報を表示するために使用されます。このコマンドの一般的なアプリケーションでは、その後に e パラメーターと f パラメーターを指定して、システム内のすべてのプロセスを表示します。

[root@localhost /]# ps -ef
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 11:01 ?        00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 23
root          2      0  0 11:01 ?        00:00:00 [kthreadd]
root          3      2  0 11:01 ?        00:00:01 [ksoftirqd/0]
root          5      2  0 11:01 ?        00:00:00 [kworker/0:0H]
root          7      2  0 11:01 ?        00:00:00 [migration/0]
root          8      2  0 11:01 ?        00:00:00 [rcu_bh]
root          9      2  0 11:01 ?        00:00:00 [rcuob/0]
······

特定のプロセスを検索する機能は、次のようなコマンドとパイプを使用したコマンドを組み合わせることで実現できますpsgrep

[root@localhost /]# ps -ef | grep python
root        775      1  0 11:01 ?        00:00:00 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
root        804      1  0 11:01 ?        00:00:02 /usr/bin/python -Es /usr/sbin/tuned -l -P
root      10570   6979  0 19:52 pts/1    00:00:00 grep --color=auto python

このうち、root 10570 6979 0 19:52 pts/1 00:00:00 grep \--color=auto pythonこの行の情報はgrepコマンドそのものを表します。

2. netstatコマンドの使用

netstatこのコマンドはインストールされていません。yum を使用してインストールできます。コマンドは次のとおりです。

yum install \-y net-tools

netstatの一般的な使用法は次のとおりです。

[root@localhost /]# netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2470/master         
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN      6962/sshd: root@pts 
tcp        0      0 0.0.0.0:53646           0.0.0.0:*               LISTEN      1628/rpc.statd      
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1457/rpcbind        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1451/sshd        
······

ここには多くのプロセスおよびポート情報が表示されます。netstatまた、grep特定のポートのステータスを見つける機能を実現するには、コマンドと組み合わせて使用​​する必要があります。次のように:

[root@localhost /]# netstat -anp | grep 22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1451/sshd           
tcp        0     52 192.168.91.128:22       192.168.91.1:14888      ESTABLISHED 6962/sshd: root@pts 
tcp6       0      0 :::22                   :::*                    LISTEN      1451/sshd

3. topコマンドの使用方法

topこのコマンドの主な機能は、システム内で最も多くのリソースを消費するプロセス情報 (プロセス ID、メモリ使用量、CPU 使用量など) を動的に表示することです。これらの情報は基本的にコマンドと同じですが、唯一の違いは次のとおりですpstopこのコマンドはプロセス情報を動的に表示できます。

[root@localhost /]# top
top - 23:16:07 up 12:15,  2 users,  load average: 0.00, 0.01, 0.05
Tasks: 384 total,   2 running, 382 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   1870760 total,  1443836 used,   426924 free,      748 buffers
KiB Swap:  2097148 total,        0 used,  2097148 free.   922564 cached Mem

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                                                      
 12974 root      20   0       0      0      0 S  0.3  0.0   0:00.11 kworker/0:1                                                                                                  
     1 root      20   0   53696   7512   2512 S  0.0  0.4   0:02.33 systemd     

これは%Cpu(s): 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 stCPU 使用率を示します。

KiB Mem: 1870760 total, 1443836 used, 426924 free, 748 buffersメモリの使用量を示します。
以下は動的に変化するテーブルです。PIDその行はテーブルのヘッダーです。qこの監視モードを終了するには、 を押してください。

4. kill コマンドの使用

主な一般的な使用法は 2 つあります。

  • kill PIDPID プロセスを自動的に終了させるには、
  • kill \-9 PIDプロセスを強制的に終了します。

おすすめ

転載: blog.csdn.net/weixin_43025343/article/details/132385528