top, ps 查看程序运行状态

文章目录

  • top :采集所有程序,按cpu/mem使用率排序
  • ps 命令
    • aux 参数组合
    • -ef 参数组合
    • -o: 自定义参数组合

top :采集所有程序,按cpu/mem使用率排序

若要查看程序运行的详细参数,需要输出重定向到文件,然后cat 该文件

#按内存使用率排序
#a: allocated memory
#c: Command line/Program name toggle
#b: Batch mode
#n: Number of iteration


#################################### 默认按%CPU排序
[yskj@eadage ~]$ top -bn 1 -c |head
top - 18:41:05 up 123 days,  6:27, 13 users,  load average: 1.62, 1.92, 2.29
Tasks: 665 total,   1 running, 664 sleeping,   0 stopped,   0 zombie
Cpu(s):  9.0%us,  2.3%sy,  0.0%ni, 88.5%id,  0.2%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  65658612k total, 56761348k used,  8897264k free,    69696k buffers
Swap: 32931836k total,   175980k used, 32755856k free,  6704824k cached

   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                        
123689 root      20   0 1348m 156m  15m S 70.0  0.2  10720:22 /usr/lib/vmware/bin/vmware                                                                                     
 12338 root      20   0 2992m 1.8g 1.8g S 18.9  2.9   4234:29 /usr/lib/vmware/bin/vmware-vmx -s vmx.stdio.keep=TRUE -# product=1;name=VMware Workstation;version=15.5.0;build
 73139 root      20   0 18.5g 1.9g  17m S 15.1  3.0 250:17.08 /usr/java/jdk1.8.0_211-amd64/bin/java -cp .:lib/*:/usr/share/java/mysql-connector-java.jar:/usr/share/java/orac


####################################  使用%MEM排序
[yskj@eadage ~]$ top -ac -bn 1 |head
top - 17:40:18 up 123 days,  5:26, 13 users,  load average: 3.26, 2.43, 2.33
Tasks: 661 total,   2 running, 659 sleeping,   0 stopped,   0 zombie
Cpu(s):  9.0%us,  2.3%sy,  0.0%ni, 88.5%id,  0.2%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  65658612k total, 54997260k used, 10661352k free,    54992k buffers
Swap: 32931836k total,   175980k used, 32755856k free,  5237208k cached

   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                        
100444 test      20   0 33.8g 5.1g  12m S  0.0  8.1  18:28.64 /usr/java/default/bin/java -Djava.util.logging.config.file=/opt/apache-tomcat-8.5.38-clini/conf/logging.propert
140283 root      20   0 6553m 4.9g 4.8g S  3.8  7.8 642:37.74 /usr/lib/virtualbox/VBoxHeadless --comment docker3_default_1583830509213_2312 --startvm f09ff652-9b75-4bcf-ab7b
 34426 test      20   0 22.9g 4.4g  12m S  0.0  7.1  23:25.62 /usr/java/default/bin/java -Djava.util.logging.config.file=/home/data/apache-tomcat-8.5.33/conf/logging.propert

ps 命令

aux 参数组合

[root@eadage ~]# ps aux |head  #按内存降序排:sort -5k -nr
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.0  19520   768 ?        Ss   Aug19   0:09 /sbin/init
root          2  0.0  0.0      0     0 ?        S    Aug19   0:00 [kthreadd]
root          3  0.0  0.0      0     0 ?        S    Aug19   3:42 [ksoftirqd/0]
root          5  0.0  0.0      0     0 ?        S<   Aug19   0:00 [kworker/0:0H]
root          8  0.1  0.0      0     0 ?        S    Aug19  86:27 [rcu_sched]
root          9  0.0  0.0      0     0 ?        S    Aug19   0:00 [rcu_bh]
root         10  0.0  0.0      0     0 ?        S    Aug19   0:23 [migration/0]
root         11  0.0  0.0      0     0 ?        S    Aug19   0:07 [watchdog/0]
root         12  0.0  0.0      0     0 ?        S    Aug19   0:07 [watchdog/1]

-ef 参数组合

[root@eadage test]# ps -ef |head -2
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0  2019 ?        00:00:35 /sbin/init
hdfs     103815   5684  1 Mar12 ?        01:29:50 /usr/java/jdk1.8.0_211-amd64/bin/java -Dproc_namenode -Xmx1000m -Dhdfs.audit.logger=INFO,RFAAUDIT -Dsecurity.audit.logger=INFO,RFAS -Djava.net.preferIPv4Stack=true -Dhadoop.log.dir=/home/cdh/var/log/hadoop-hdfs -Dhadoop.log.file=hadoop-cmf-hdfs-NAMENODE-eadage.log.out -Dhadoop.home.dir=/opt/cloudera/parcels/CDH-5.12.0-1.cdh5.12.0.p0.29/lib/hadoop -Dhadoop.id.str=hdfs -Dhadoop.root.logger=INFO,RFA -Djava.library.path=/opt/cloudera/parcels/CDH-5.12.0-1.cdh5.12.0.p0.29/lib/hadoop/lib/native -Dhadoop.policy.file=hadoop-policy.xml -Djava.net.preferIPv4Stack=true -Xms4294967296 -Xmx4294967296 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/cdh/tmp/hdfs_hdfs-NAMENODE-144a0ada48aafa3485e33bb69df57f5c_pid103815.hprof -XX:OnOutOfMemoryError=/opt/cm-5.12.2/lib64/cmf/service/common/killparent.sh -Dhadoop.security.logger=INFO,RFAS org.apache.hadoop.hdfs.server.namenode.NameNode
hdfs     103967   5684  0 Mar12 ?        01:09:54 /usr/java/jdk1.8.0_211-amd64/bin/java -Dproc_datanode -Xmx1000m -Dhdfs.audit.logger=INFO,RFAAUDIT -Dsecurity.audit.logger=INFO,RFAS -Djava.net.preferIPv4Stack=true -Dhadoop.log.dir=/home/cdh/var/log/hadoop-hdfs -Dhadoop.log.file=hadoop-cmf-hdfs-DATANODE-eadage.log.out -Dhadoop.home.dir=/opt/cloudera/parcels/CDH-5.12.0-1.cdh5.12.0.p0.29/lib/hadoop -Dhadoop.id.str=hdfs -Dhadoop.root.logger=INFO,RFA -Djava.library.path=/opt/cloudera/parcels/CDH-5.12.0-1.cdh5.12.0.p0.29/lib/hadoop/lib/native -Dhadoop.policy.file=hadoop-policy.xml -Djava.net.preferIPv4Stack=true -server -Xms1073741824 -Xmx1073741824 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/cdh/tmp/hdfs_hdfs-DATANODE-144a0ada48aafa3485e33bb69df57f5c_pid103967.hprof -XX:OnOutOfMemoryError=/opt/cm-5.12.2/lib64/cmf/service/common/killparent.sh -Dhadoop.security.logger=INFO,RFAS org.apache.hadoop.hdfs.server.datanode.DataNode

-o: 自定义参数组合

-o : output ( rsz: 物理内存使用量, vsz: 虚拟内存使用量)

[root@test ~]#  ps -e -o 'rsz,vsz,pid,comm,args,pcpu,stime,user,uid'     #|sort -n
577040 3117584 48739 firefox        /usr/lib64/firefox/firefox   1.9 Aug19 root         0
578172 840552 20920 Xvnc            /usr/bin/Xvnc :30 -desktop   1.9 Aug19 root         0
584300 3010360 101145 java          /usr/java/jdk1.8.0_211-amd6  0.3 Sep09 mapred     486
1089476 3537168 100948 java         /usr/java/jdk1.8.0_211-amd6  0.8 Sep09 yarn       484
1204928 5256788 131968 java         /usr/java/jdk1.8.0_211-amd6  0.3 Sep09 hbase      479
1407124 6674148 16325 java          /usr/java/default/bin/java   0.8 Sep18 root         0
1485764 4390836 32987 VirtualBoxVM  /usr/lib/virtualbox/Virtual 11.0 15:34 root         0

你可能感兴趣的:(linux系统)