进程管理的bash命令——更多bash命令(一)

本文介绍了Bash中的进程管理命令,包括使用`ps`查看进程,`top`实时监测进程以及`kill`系列命令结束进程。详细讲解了各命令的参数和用法,如`ps`的-e、-a、-L选项,`top`的系统资源显示,以及`kill`的信号传递。
摘要由CSDN通过智能技术生成

一、管理进程

1、ps命令
  • 下面是man手册中的描述,注意:三种风格的参数可以混合使用,但是最好每个参数都用空格隔开,避免不必要的冲突。例如,我可以使用 ps -e l --forest来显示所有进程参数,使用UNIX风格的-e,使用BSD风格的l,以及GNU风格的–forest。
PS(1)                                                                                        User Commands                                                                                       
NAME
       ps - report a snapshot of the current processes.
SYNOPSIS
       ps [options]

DESCRIPTION
       ps displays information about a selection of the active processes.  If you want a repetitive update of the selection and the displayed information, use top(1) instead.

       This version of ps accepts several kinds of options:

       1   UNIX options, which may be grouped and must be preceded by a dash.
       2   BSD options, which may be grouped and must not be used with a dash.
       3   GNU long options, which are preceded by two dashes.

       Options of different types may be freely mixed, but conflicts can appear.  There are some synonymous options, which are functionally identical, due to the many standards and ps
       implementations that this ps is compatible with.
  • ps的常用命令参数举例

    • -e 显示所有进程
    • -a 显示除控制进程和无终端进程外的所有进程
    • -L 显示进程中的线程
    • -l 显示UNIX风格的长列表(CMD显示命令缩写)
    • l 显示BSD风格的长列表(内容更全,command显示程序实际路径,bash貌似不是)
    • -U userlist 或 -g grplist 或 -p pidlist 显示对应列表中的进程
    • –forest 会通过折线图的形式展示进程的层级关系
    • –info 显示调试信息
    • –sort order 按指定的order输出进程信息。
  • BSD风格长列表中

    • F 内核分配给进程的系统标记
    • TTY 进程启动时的终端设备
    • TIME 运行进程需要的累计CPU时间
    • STAT 代表当前进程状态的双字状态码
      • 第一个参数O代表正在运行;S代表休眠;R代表可运行,正在等待;Z代表僵化
      • 第二个参数:< 该进程运行在高优先级上; N 低优先级上;L该进程有页面锁定在内存中;s控制进程;l段线程的;+运行在前台。
      • VSZ 进程在内存中的大小,以KB为单位
      • RSS 进程在未换出时占有的物理内存
      • WCHAN 进程休眠的内核函数地址。
    • 下面是使用 ps l --forest展示的内容列表:
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
0  1000  2941  2933  20   0  19320  4960 do_wai Ss   pts/0      0:00 bash
4  1000  3500  2941  20   0  20120  3176 -      R+   pts/0      0:00  \_ ps l --forest
4  1000  1249  1214  20   0 173872  6040 poll_s Ssl+ tty2       0:00 /usr/lib/gdm3/gdm-x-session --run-script env GNOME_SHELL_SESSION_MODE=ubuntu /usr/bin/gnome-session --session
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值