进程管理

一、进程知识

  •   IO
  •   CPU
  •   内存
  •   网络

二、查看工具

2.1 ps 

2.1.1 ps 命令介绍

  一般都是使用  ps aux

  ps-aux 是不同于 ps aux的

  report a snapshot of the current processes. 报告当前进程的快照信息。 

[lh@hui36 ~]$ ps aux | less
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

USER    用户

PID      进程编号

%CPU      cpu占用率

%MEM     内存占用率

VSZ       占用虚拟内存,程序会调用一些公共的资源库,这是大家公有的,在这里算的时候,包含在内。

      完全驻留在内存的话需要占用多少内存空间

RSS    占用实际内存,驻留内存

TTY     进程运行的终端

STAT     进程状态,是由两部分组成,

          第一部分:第一字符 表示当前的状态,

          第二部分:第一个字符后面的段:表示 优先级,多线程,领导者等。

    第一部分

      D   uninterruptible sleep (usually IO)

      R   running or runnable (on run queue)
      S   interruptible sleep (waiting for an event to complete)
      T   stopped by job control signal
      t    stopped by debugger during the tracing
      W   paging (not valid since the 2.6.xx kernel)
      X    dead (should never be seen)
      Z    defunct ("zombie") process, terminated but not reaped by its parent

    第二部分:

      <   high-priority (not nice to other users)

      N    low-priority (nice to other users)
      L  has pages locked into memory (for real-time and  custom IO)
      s   is a session leader
      l   is multi-threaded (using CLONE_THREAD, like NPTLpthreads do)
      +   is in the foreground process group

      

START    启动时间

TIME       从启动到现在,占用cpu运行的时间。

COMMAND  启动的命令。

 2.2.2按次序排列

 ps aux  --sort=-pid,+%cpu

   ps aux  --sort=-%mem

通过sort来排序,通过加减号来指定排序的次序。  后面的字段,就是 ps aux的表头的小写字段。

2.2.3 自定义字段查看

ps axo user,pid,%cpu,&mem,command     //只显示这些

ps axo user,pid,%cpu,&mem,command --sort=%cpu    //只显示这些 并按照指定排序

2.2.4 查看指定进程

ps aux | grep sshd   #一般就用这个

cat /run/sshd.pid 

pgrep sshd

pidof sshd

原文地址:https://www.cnblogs.com/louhui/p/8729322.html