美文网首页
ps:一个查看当前进程快照的命令

ps:一个查看当前进程快照的命令

作者: robot_test_boy | 来源:发表于2022-08-17 08:40 被阅读0次

ps更全面的介绍见官网。一个简单的常见命令,竟也这么复杂,要学的内容很多。用的时候查查字典。

几点感触:1) ps三种风格参数选项;2) note中ps的原理,数据从/proc中读取数据;3) note中僵尸进程;4) 根据需要不同场景下的ps命令。


ps - report a snapshot of the current  processes.

ps 仅仅显示查询当前活动进程的相关信息。如果要重复查询进程动态变化的相关信息,请使用TOP命令。

ps命令的3种参数选项:

1  UNIX options 可以分组,且参数选项前面必须要有一个破折号。

2  BSD options 可以分组,但参数选项前面不能有一个破折号。

3  GNU long options参数选项前面必须要有两个破折号。

注意:ps -aux和ps aux的区别。The POSIX and UNIX标准要求ps -aux通过-a参数来打印出所有进程信息和-x参数打印其用户叫x的进程的信息。假如x用户不存在,会打印警告信息。其旨在帮助转换旧脚本和习惯。它很脆弱,可能会发生变化,因此不应依赖它。

默认情况下,PS选择将相同有效用户ID(euid =EUID)作为当前用户并与调用者相关联的所有进程。PS展示了进程id(pid=PID),进程相关的终端(tname=TTY),累积起来的CPU占用时间(time=TIME),以及可执行文件名(ucmd=CMD)。默认情况下,PS输出不排序。

BSD风格的参数选项,默认情况下将增加字段显示:进程状态 (stat=STAT),显示命令参数(args=COMMAND)而不是可执行文件名。You can override this with the PS_FORMAT environment variable.

example

使用标准格式查看系统上的所有进程:ps -e、ps -ef、 ps -eF、 ps -ely

使用BSD格式查看系统上的每一个进程:ps ax、ps axu

打印进程树: ps -ejH、 ps axjf

打印线程相关信息: ps -eLf、ps axms

打印安全(用户相关)信息:ps -eo euser,ruser,suser,fuser,f,comm,label、 ps axZ、 ps -eM

打印以root用户运行的所有进程: ps -U root -u root u

打印用户自定义格式下的所有进程: 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

打印syslogd名字有关的进程PID:ps -C syslogd -o pid=, -C cmdlist

打印PID为42有关的进程名字: ps -q 42 -o comm=

note

This ps works by reading the virtual files in /proc. This ps does not need to be setuid  kmem or have any privileges to run.Do not give this ps any special permissions.

CPU usage is currently expressed as the  percentage of time spent running during  the entire lifetime of a process.  This is not  ideal, and it does not conform to the standards that ps otherwise conforms to.  CPU usage is unlikely to add up to exactly 100%.

The SIZE and RSS fields don't count some parts of a process including the page tables, kernel stack, struct thread_info, and struct task_struct.  This is usually at least 20 KiB of memory that is always resident.  SIZE is the virtual size of the process  (code+data+stack).

Processes marked <defunct> are dead processes (so-called "zombies") that remain  because their parent has not destroyed them properly.  These processes will be destroyed by init(8) if the parent process exits.

If the length of the username is greater  than the length of the display column, the  username will be truncated.  See the -o and  -O formatting options to customize length.

Commands options such as ps -aux are  not recommended as it is a confusion of  two different standards.  According to the  POSIX and UNIX standards, the above  command asks to display all processes  with a TTY (generally the commands users are running) plus all processes owned by  a user named x.  If that user doesn't exist,  then ps will assume you really meant ps aux.

相关文章

  • Linux命令 - ps

    ps命令能够给出当前系统中进程的快照, man ps 查看解析如下 report a snapshot of th...

  • linux常用命令

    1、查看当前目录:pwd 命令:pwd 查看当前目录路径 2、查看进程:ps -ef 命令:ps -ef 查...

  • ps命令使用总结

    ps命令 简介 ps命令是Process Status的缩写,ps命令显示的是当前系统中运行的进程的快照。如果想要...

  • 进程

    1.进程的命令 查看CPU:top查看所有的进程:ps -A查看当前的进程:ps关闭进程:kill -9 进程id...

  • 进程相关操作

    进程相关命令 ps – 报告当前进程快照 top – 显示任务 jobs – 列出活跃的任务 bg – 把一个任务...

  • 【蜗牛黑板报】爆好用的常见命令ps,vim

    ps查看进程命令: 1. ps -A ps命令是ProcessStatus的缩写。ps命令用来列出系统中当前运行的...

  • Linux 基本指令

    查看进程: 1、ps 命令用于查看当前正在运行的进程。grep 是搜索例如: ps -ef | grep java...

  • ubuntu查看及结束进程

    查看进程: 1、ps 命令用于查看当前正在运行的进程。 grep 是搜索 例如: ps -ef | grep ja...

  • linux命令ps aux|grep xxx详解

    ps命令 要对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程, 而ps命令(Proces...

  • day20-进程管理(1)

    1. 监控进程状态 1.1 使用ps命令查看当前的进程状态(静态) ps -aux为常用组合,用于查看进程的用户、...

网友评论

      本文标题:ps:一个查看当前进程快照的命令

      本文链接:https://www.haomeiwen.com/subject/ubrtbrtx.html