top

主要用于查看 Linux系统中的所有进程
top整体示例图

top 详解 及 使用

上面的top
top图解上

top - 04:27:03 up 6 days, 23:25,             # top 系统运行时间
2 users,                                     # 用户个数
load average: 0.00, 0.00, 0.00               # 平均负载
Tasks: 258 total,   1 running, 257 sleeping,   0 stopped,   0 zombie    
# 任务:总共258个,1个正在运行,257个睡眠,0个已停止,0个僵尸进程

%Cpu(s):          0.0 us,              1.6 sy,      0.0 ni,     98.4 id,    0.0 wa,  0.0 hi,  0.0 si,  0.0 st
# CPU使用率:用户空间占用CPU百分比  内核空间占用CPU百分比  不知道     空闲CPU百分比  不知道了......

MiB Mem :  16008.3 total,    273.1 free,  10718.1 used,   5017.1 buff/cache
# 内存使用率: 总计                空闲          使用              缓存

MiB Swap:   4096.0 total,   4094.5 free,      1.5 used.   4953.2 avail Mem
# 交换内存使用率:  总计           空闲           使用             可用内存

下面的top
top图解下

  PID      USER        PR      NI             VIRT                                      RES   
进程ID   进程所属用户   优先级  nice值  进程使用的虚拟内存总量,单位kb  进程使用的、未被换出的物理内存大小,单位kb。

       SHR                                                S 
共享内存大小,单位kb                 进程状态  D:不可中断的睡眠状态  R:运行  S:睡眠  T:跟踪/停止  Z:僵尸进程

    %CPU           %MEM                TIME+                      COMMAND
CPU占用百分比   内存占用百分比   进程使用的CPU时间总计,单位1/100秒    命令名

top 常用的命令

输入 1 : 显示所有 CPU 统计信息
输入 k ,会提示输入进程ID,输入ID后,可杀死对应进程
top -Hp PID :显示当前进程所有的线程



taskset

主要用于查看 当前进程中的 所有线程

Show or change the CPU affinity of a process.

Options:
 -a, --all-tasks         operate on all the tasks (threads) for a given pid
 -p, --pid               operate on existing given pid
 -c, --cpu-list          display and specify cpus in list format
 -h, --help              display this help
 -V, --version           display version

The default behavior is to run a new command:
    taskset 03 sshd -b 1024
You can retrieve the mask of an existing task:    # 您可以检索现有任务的掩码:
    taskset -p 700
Or set it:                                        # 或者设置 (掩码)
    taskset -p 03 700
List format uses a comma-separated list instead of a mask:      # 
    taskset -pc 0,3,7-11 700
Ranges in list format can take a stride argument:
    e.g. 0-31:2 is equivalent to mask 0x55555555

taskset 的基本使用

1. 显示某个进程(线程)运行所在的核

taskset -cp PID

2. 设置某个进程(线程)运行的核

启动时设置 `taskset -c 0,10 ./bind_core`
运行中设置 `taskset -cp core PID`         # core 可以为单个,或 列表 ,或 逗号分割
内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/qz652219228/p/16712726.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!