首页 > 系统相关 >Linux基础 - 进程管理 ps

Linux基础 - 进程管理 ps

时间:2023-02-19 13:57:24浏览次数:32  
标签:bin ps 00 -- usr Linux 进程 root

 

ps aux | sort -k4,4nr | head -n 10  # 查看内存占用前10名的程序

ps -e / ps -ef / ps -eF / ps -ely   # To see every process on the system using standard syntax

ps ax / ps axu                      # To see every process on the system using BSD syntax

ps -ejH / ps axjf                   # To print a process tree

ps -eLf / ps axms                   # To get info about threads

 

查看当前用户的活跃进程

[root@cl-server ~]# ps
   PID TTY          TIME CMD
  1656 pts/0    00:00:00 httpd
  1855 pts/0    00:00:00 bash
  2901 pts/0    00:00:23 java
  3034 pts/0    00:00:00 ps

  

UID:    程序被该 UID 所拥有
PID:    程序的ID 
PPID:   上级父程序的ID
C:      CPU使用的资源百分比, CPU用于计算执行优先级的因子
STIME:  程序启动时间
TTY:    进程所属的终端控制台, 问号表示这些进程不属于任何TTY, 它们是由系统启动的。
TIME:   程序使用的CPU时间
CMD:    程序的指令
[root@server ~]# ps -ef | grep salt UID PID PPID C STIME TTY TIME CMD root 2899 1 0 2021 ? 00:09:14 /usr/bin/python /usr/bin/salt-master root 3050 2899 0 2021 ? 00:00:00 /usr/bin/python /usr/bin/salt-master root 3272 2899 0 2021 ? 00:00:00 /usr/bin/python /usr/bin/salt-master root 3275 2899 0 2021 ? 00:00:03 /usr/bin/python /usr/bin/salt-master root 3276 2899 0 2021 ? 13:13:45 /usr/bin/python /usr/bin/salt-master root 3277 2899 0 2021 ? 00:09:08 /usr/bin/python /usr/bin/salt-master root 3278 3277 0 2021 ? 00:00:04 /usr/bin/python /usr/bin/salt-master root 3288 3277 0 2021 ? 00:02:35 /usr/bin/python /usr/bin/salt-master root 3289 3277 0 2021 ? 00:02:47 /usr/bin/python /usr/bin/salt-master root 3290 3277 0 2021 ? 00:02:40 /usr/bin/python /usr/bin/salt-master root 3292 2899 0 2021 ? 1-13:21:45 /usr/bin/python /usr/bin/salt-master root 3293 3277 0 2021 ? 00:02:33 /usr/bin/python /usr/bin/salt-master root 3295 3277 0 2021 ? 00:02:13 /usr/bin/python /usr/bin/salt-master root 3182 6423 0 09:59 pts/1 00:00:00 grep --color=auto salt

  

-a: 显示所有用户的进程    -l: long format,展示更多信息

VSZ: 进程的虚拟内存    RSS: 常驻内存的大小

STAT状态值:  S-睡眠,s-表示该进程是会话的先导进程,N-表示进程拥有比普通优先级更低的优先级,R-正在运行,D-短期等待,Z-僵死进程, T-被跟踪或者被停止等等

[soupman@myos ~]$ ps -lax 
F   UID     PID    PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0       1       0  20   0 179336  7924 -      Ss   ?         12:48 /usr/lib/systemd/systemd --switched-root --system --deseri
1     0       2       0  20   0      0     0 -      S    ?          0:00 [kthreadd]

 

[root@cl-server ~]#  ps axu
USER        PID %CPU %MEM    VSZ     RSS TTY   STAT START   TIME COMMAND
root          1  0.0  0.2 125464    3916   ?   Ss   14:28   0:02 /usr/lib/systemd/systemd --switched-root --system --deserializ
root          2  0.0  0.0      0       0   ?   S    14:28   0:00 [kthreadd]
root        692  0.0  0.0 110204     856 tty1  Ss+  14:28   0:00 /sbin/agetty --noclear tty1 linux
mysql       957  0.1 10.4 1183028 195308   ?   Ssl  14:28   0:07 /application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
root       2901  1.6 20.2 3658356 377928   ?   Sl   15:37   0:25 /usr/local/jdk1.8.0_281/bin/java -Xms64M -Xmx1G -Djava.util.lo

 

[root@cl-server ~]# ps -ef f
UID         PID   PPID  C STIME TTY      STAT   TIME CMD
root          2      0  0 14:28 ?        S      0:00 [kthreadd]
root          4      2  0 14:28 ?        S<     0:00  \_ [kworker/0:0H]
root       1082      1  0 14:28 ?        Ssl    0:02 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root       1557   1082  0 14:28 ?        Sl     0:00  \_ /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8899 -cont
root       1572   1082  0 14:28 ?        Sl     0:00  \_ /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8899 -container

  

TTY 展示探究

说明:当前cl-server服务器,通过VMware Workstation 界面启动,通过xshell工具开启两个会话。
启动终端: tty1, 会话终端: pts/0, pts/1。 在pts/0上启动 activemq 服务。
[root@cl-server ~]# ps ax
  PID TTY      STAT   TIME COMMAND
     1 ?        Ss     0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
     2 ?        S      0:00 [kthreadd]
     4 ?        S<     0:00 [kworker/0:0H]
   692 tty1     Ss+    0:00 /sbin/agetty --noclear tty1 linux
  1656 pts/0    Ss+    0:00 /bin/httpd -f -h /data/html
  1689 ?        Ss     0:00 /bin/httpd -f -h /data/html
  1853 ?        Ss     0:00 sshd: root@pts/0
  1855 pts/0    Ss     0:00 -bash
  1951 ?        R      0:00 [kworker/1:1]
  2472 ?        Ss     0:00 sshd: root@pts/1
  2474 pts/1    Ss+    0:00 -bash
  2901 pts/0    Sl     0:24 /usr/local/jdk1.8.0_281/bin/java -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -
  3102 pts/0    R+     0:00 ps ax

关闭会话pts/0, TTY变成?
[root@cl-server ~]# ps ax
   PID TTY      STAT   TIME COMMAND
  1656 ?        Ss+    0:00 /bin/httpd -f -h /data/html
  1689 ?        Ss     0:00 /bin/httpd -f -h /data/html
  2901 ?        Sl     0:25 /usr/local/jdk1.8.0_281/bin/java -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -
  3156 pts/1    R+     0:00 ps ax

 

       To get security info:
          ps -eo euser,ruser,suser,fuser,f,comm,label
          ps axZ
          ps -eM

       To see every process running as root (real & effective ID) in user format:
          ps -U root -u root u

       To see every process with a user-defined format:
          ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
          ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
          ps -Ao pid,tt,user,fname,tmout,f,wchan

       Print only the process IDs of syslogd:
          ps -C syslogd -o pid=

       Print only the name of PID 42:
          ps -q 42 -o comm=

  

[root@cl-server ~]# ps --help

Usage:
 ps [options]

 Try 'ps --help <simple|list|output|threads|misc|all>'
  or 'ps --help <s|l|o|t|m|a>'
 for additional help text.

For more details see ps(1).
[root@cl-server ~]# ps --help all

Usage:
 ps [options]

Basic options:
 -A, -e               all processes
 -a                   all with tty, except session leaders
  a                   all with tty, including other users
 -d                   all except session leaders
 -N, --deselect       negate selection
  r                   only running processes
  T                   all processes on this terminal
  x                   processes without controlling ttys

Selection by list:
 -C <command>         command name
 -G, --Group <GID>    real group id or name
 -g, --group <group>  session or effective group name
 -p, p, --pid <PID>   process id
        --ppid <PID>  parent process id
 -q, q, --quick-pid <PID>
                      process id (quick mode)
 -s, --sid <session>  session id
 -t, t, --tty <tty>   terminal
 -u, U, --user <UID>  effective user id or name
 -U, --User <UID>     real user id or name

  The selection options take as their argument either:
    a comma-separated list e.g. '-u root,nobody' or
    a blank-separated list e.g. '-p 123 4567'

Output formats:
 -F                   extra full
 -f                   full-format, including command lines
  f, --forest         ascii art process tree
 -H                   show process hierarchy
 -j                   jobs format
  j                   BSD job control format
 -l                   long format
  l                   BSD long format
 -M, Z                add security data (for SELinux)
 -O <format>          preloaded with default columns
  O <format>          as -O, with BSD personality
 -o, o, --format <format>
                      user-defined format
  s                   signal format
  u                   user-oriented format
  v                   virtual memory format
  X                   register format
 -y                   do not show flags, show rss vs. addr (used with -l)
     --context        display security context (for SELinux)
     --headers        repeat header lines, one per page
     --no-headers     do not print header at all
     --cols, --columns, --width <num>
                      set screen width
     --rows, --lines <num>
                      set screen height

Show threads:
  H                   as if they were processes
 -L                   possibly with LWP and NLWP columns
 -m, m                after processes
 -T                   possibly with SPID column

Miscellaneous options:
 -c                   show scheduling class with -l option
  c                   show true command name
  e                   show the environment after command
  k,    --sort        specify sort order as: [+|-]key[,[+|-]key[,...]]
  L                   show format specifiers
  n                   display numeric uid and wchan
  S,    --cumulative  include some dead child process data
 -y                   do not show flags, show rss (only with -l)
 -V, V, --version     display version information and exit
 -w, w                unlimited output width

        --help <simple|list|output|threads|misc|all>
                      display help and exit

For more details see ps(1).

  

标签:bin,ps,00,--,usr,Linux,进程,root
From: https://www.cnblogs.com/kingdomer/p/15670631.html

相关文章

  • Kepserver获取MX OPC SERVER的数据
    1,新建通道;    2,新建通道(直接点下一步),但是建好通道后,需要先启动一下QiuckClient,然后才能选择ImportItems ......
  • https的工作流程详解
    在了解https之前,我们先看下http的协议有哪些不足,加密、证书,签名这些概念,以便于我们更全面的掌握https的原理以及工作流程。   HTTP协议的不足 不验证身份,导致身份......
  • Linux系统的日志管理
    (Linux系统的日志管理)一、systemd-journald服务1.systemd-journald介绍#系统时间日志的核心服务#收集包括来自内核,早期引导阶段啊,进程启动,运行时的标准输出和错误输......
  • Linux系列教程(十四)——Linux用户和用户组管理之相关配置文件
    前面我们介绍了软件包管理。首先介绍了rpm包的相关命令,但是我们发现直接安装rpm包会被其依赖性折磨的不行,然后解决办法是yum在线管理,通过yum命令安装rpm包能自动帮助我......
  • 【自用】Linux常用命令
    目录grepgrepLinux搜索指定目录中所有文件的内容grep-rn'要搜索的关键词'*-r递归查找-n显示行号-R查找所有文件包含子目录-i忽略大小写-l只列出匹配的文件......
  • Linux基础 - 文件系统 /proc
      一、/proc文件系统1.1/proc:一个虚拟文件系统/proc文件系统是一种内核和内核模块用来向进程(process)发送信息的机制(所以叫做/proc)。最初的设计目的是允许......
  • 5.windows安装linux系统
    本章意图将windows系统安装为Linux系统 1.安装的准备:U盘(不小于20G)windows电脑安装软件连接链接:https://pan.baidu.com/s/1QHYv3tif2cX3V6dDQ9nV4w提取码:o1......
  • myEclipse 8.5 安装 svn 插件
    转的,我也是这么用的fatjar插件一般用不到。。。1、MyEclipse8.5默认安装的。首先从http://sourceforge.net/下载插件;2、新建文件myplugin,解压......
  • 用myeclipse的Hibernate 反向引擎 生成 数据库的 entity
    把Myeclipse转到DBBrowser 新建一个DatabaseConnectiondriver 然后找到要反向工程的表 右键->HibernateReverseEngineering然后,选好entity缩放的目录对CreatePO......
  • github 私有仓库linux下免输入账号密码 ||php shell_exec webhook自动化部署||如何使w
    github私有仓库linux下免输入账号密码cd~/touch.git-credentialsvim.git-credentials内容为:https://{username}:{password}@github.com比如https://account:password......