惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
Blog — PlanetScale
Blog — PlanetScale
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
D
DataBreaches.Net
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
F
Fortinet All Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
Recent Announcements
Recent Announcements
Jina AI
Jina AI
G
Google Developers Blog
腾讯CDC
博客园_首页
博客园 - 【当耐特】

WangDeer

非机动车交通规则测验 微软 50 周年壁纸是在 macOS上设计的? 「转」西二旗折叠:蜂巢经济学启示录 难得空明 Ubuntu Clean ApidocJs apigroup Support Chinese int(10)里面的10是什么意思? 5-3 会话 2021-03-25 「PHP架构师」面试准备 Laravel 上传 Docx 文件,表单验证不通过 4-4 发送信号 4-3 信号集 4-2 编写中断信号处理程序 2022-03-10 面试复盘 4-1 什么是中断信号(软中断) 3-6 SUID特权进程 3-5多进程编写 3-4进程调度 3-3进程exec 3-2进程退出和回收 3-1进程标识与fork 2-3解释器文件 2-2命令行参数与环境参数表 2-1程序与进程 1-1课程介绍 终极复盘 第八章 传承篇 第七章 自由篇 第六章 品牌篇 第五章 作品篇
3-7 进程查看
王二 · 2022-03-08 · via WangDeer

一个程序启动之后就是一个进程,进程的数据在内存中,包括正文段和数据段,内存中的一些数据也会写入到proc文件系统中。


$ ll /proc/
total 4
dr-xr-xr-x 447 root     root        0 Mar  8 06:31 ./
drwxr-xr-x   1 root     root     4096 Mar  1 07:45 ../
dr-xr-xr-x   9 root     root        0 Mar  8 11:43 1/
dr-xr-xr-x   9 root     root        0 Mar  8 11:47 12/
dr-xr-xr-x   9 root     root        0 Mar  8 11:47 21/
dr-xr-xr-x   9 root     root        0 Mar  8 11:47 22/
dr-xr-xr-x   9 root     root        0 Mar  8 11:47 23/
dr-xr-xr-x   9 root     root        0 Mar  8 11:47 24/
dr-xr-xr-x   9 root     root        0 Mar  8 11:47 3252/
dr-xr-xr-x   9 laradock laradock    0 Mar  8 11:47 499/
dr-xr-xr-x   9 root     root        0 Mar  8 11:47 983/

top

top - display Linux processes.

The top program provides a dynamic real-time view of a running system.

It can display system summary information as well as a list of processes or threads currently being managed by the Linuxkernel.

The types of system summary information shown and the types, order and size of information displayed for processes are all user configurable and that configuration can be made persistent across restarts.

The program provides a limited interactive interface for process manipulation as well as a much more extensive interface for personal configuration – encompassing every aspect of its operation.

And while top is referred to throughout thisdocument, you are free to name the program anything you wish.

That new name, possibly an alias, will then be reflected on top’s display and used when reading and writing a configuration file.

top - 23:28:59 up 13:13,  1 user,  load average: 0.30, 1.20, 1.61
任务: 386 total,   1 running, 385 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.8 us,  1.7 sy,  0.1 ni, 95.3 id,  0.0 wa,  0.0 hi,  0.2 si,  0.0 st
MiB Mem :   5855.6 total,    664.6 free,   3875.4 used,   1315.7 buff/cache
MiB Swap:    976.0 total,    364.7 free,    611.3 used.   1379.6 avail Mem 

进程号 USER      PR  NI    VIRT    RES    SHR    %CPU  %MEM     TIME+ COMMAND                                                                        
7305  wanger    20   0  4956504   454380 52432 S  4.6   7.6  28:24.62 gnome-shell

...

pstree 查看 Linux 进程间的关系,显示进程树。

pstree shows running processes as a tree.

The tree is rooted at either pid or init if pid is omitted.

If a user name is specified, all process trees rooted at processes owned by that user are shown.

pstree -ap

    ├─sshd,9408
    │   └─sshd,444836    
    │       └─bash,444875
    │           └─pstree,444893 -ap

ps

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 instead.


$ ps ejx
   PPID     PID    PGID     SID TTY        TPGID STAT   UID   TIME COMMAND
      0       1       1       1 pts/0          1 Ss+      0   0:00 /usr/bin/python3 -u /sbin/my_init PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/us
      1      12      12       1 pts/0          1 S        0   0:01 /usr/sbin/syslog-ng --pidfile /var/run/syslog-ng.pid -F --no-caps LC_ALL=en_US.UTF-
      1      21       1       1 pts/0          1 S+       0   0:00 /usr/bin/runsvdir -P /etc/service AST_VERSION=1.0.10 BLACKFIRE_CLIENT_ID="<client_i
     21      22      22      22 ?             -1 Ss       0   0:00 runsv cron AST_VERSION=1.0.10 BLACKFIRE_CLIENT_ID="<client_id>" BLACKFIRE_CLIENT_TO
     21      23      23      23 ?             -1 Ss       0   0:00 runsv sshd AST_VERSION=1.0.10 BLACKFIRE_CLIENT_ID="<client_id>" BLACKFIRE_CLIENT_TO
     22      24      22      22 ?             -1 S        0   0:00 /usr/sbin/cron -f NPM_FETCH_RETRY_MINTIMEOUT=10000 LANGUAGE=en_US.UTF-8 NPM_FETCH_R
      0     983     983     983 pts/1       3354 Ss       0   0:00 bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/larado
    983    3354    3354     983 pts/1       3354 R+       0   0:00 ps ejx LC_ALL=en_US.UTF-8 NVM_DIR=/home/laradock/.nvm LS_COLORS=no=00:fi=00:di=01;3

Linux 系统中一般会把进程/线程称为任务Task。 TTY 是一个物理终端|伪终端pts/0 ssh / telnet

proc文件系统

process information pseudo-filesystem.(进程信息伪文件系统)

The proc filesystem is a pseudo-filesystem which provides an interface to kernel data structures. It is commonly mounted at /proc.

Typically, it is mounted automatically by the system, but it can also be mounted manually using a command such as:

Most of the files in the proc filesystem are read-only, but some files are writable, allowing kernel variables to be changed.


/proc/983# ll
total 0
dr-xr-xr-x   9 root root 0 Mar  8 11:56 ./
dr-xr-xr-x 460 root root 0 Mar  8 06:31 ../
-r--r--r--   1 root root 0 Mar  8 11:56 arch_status
dr-xr-xr-x   2 root root 0 Mar  8 11:56 attr/
-rw-r--r--   1 root root 0 Mar  8 11:56 autogroup
-r--------   1 root root 0 Mar  8 11:56 auxv
-r--r--r--   1 root root 0 Mar  8 11:56 cgroup
--w-------   1 root root 0 Mar  8 11:56 clear_refs
-r--r--r--   1 root root 0 Mar  8 11:56 cmdline
-rw-r--r--   1 root root 0 Mar  8 11:56 comm
-rw-r--r--   1 root root 0 Mar  8 11:56 coredump_filter
-r--r--r--   1 root root 0 Mar  8 11:56 cpu_resctrl_groups
-r--r--r--   1 root root 0 Mar  8 11:56 cpuset
lrwxrwxrwx   1 root root 0 Mar  8 11:56 cwd -> /proc/983/
-r--------   1 root root 0 Mar  8 11:56 environ
lrwxrwxrwx   1 root root 0 Mar  8 11:56 exe -> /bin/bash*
dr-x------   2 root root 0 Mar  8 11:56 fd/
dr-x------   2 root root 0 Mar  8 11:56 fdinfo/
-rw-r--r--   1 root root 0 Mar  8 11:56 gid_map
-r--------   1 root root 0 Mar  8 11:56 io
-r--r--r--   1 root root 0 Mar  8 11:56 limits
-rw-r--r--   1 root root 0 Mar  8 11:56 loginuid
dr-x------   2 root root 0 Mar  8 11:56 map_files/
-r--r--r--   1 root root 0 Mar  8 11:56 maps
-rw-------   1 root root 0 Mar  8 11:56 mem
-r--r--r--   1 root root 0 Mar  8 11:56 mountinfo
-r--r--r--   1 root root 0 Mar  8 11:56 mounts
-r--------   1 root root 0 Mar  8 11:56 mountstats
dr-xr-xr-x  53 root root 0 Mar  8 11:56 net/
dr-x--x--x   2 root root 0 Mar  8 11:56 ns/
-r--r--r--   1 root root 0 Mar  8 11:56 numa_maps
-rw-r--r--   1 root root 0 Mar  8 11:56 oom_adj
-r--r--r--   1 root root 0 Mar  8 11:56 oom_score
-rw-r--r--   1 root root 0 Mar  8 11:56 oom_score_adj
-r--------   1 root root 0 Mar  8 11:56 pagemap
-r--------   1 root root 0 Mar  8 11:56 patch_state
-r--------   1 root root 0 Mar  8 11:56 personality
-rw-r--r--   1 root root 0 Mar  8 11:56 projid_map
lrwxrwxrwx   1 root root 0 Mar  8 11:56 root -> //
-rw-r--r--   1 root root 0 Mar  8 11:56 sched
-r--r--r--   1 root root 0 Mar  8 11:56 schedstat
-r--r--r--   1 root root 0 Mar  8 11:56 sessionid
-rw-r--r--   1 root root 0 Mar  8 11:56 setgroups
-r--r--r--   1 root root 0 Mar  8 11:56 smaps
-r--r--r--   1 root root 0 Mar  8 11:56 smaps_rollup
-r--------   1 root root 0 Mar  8 11:56 stack
-r--r--r--   1 root root 0 Mar  8 11:56 stat
-r--r--r--   1 root root 0 Mar  8 11:56 statm
-r--r--r--   1 root root 0 Mar  8 11:56 status
-r--------   1 root root 0 Mar  8 11:56 syscall
dr-xr-xr-x   3 root root 0 Mar  8 11:56 task/
-rw-r--r--   1 root root 0 Mar  8 11:56 timens_offsets
-r--r--r--   1 root root 0 Mar  8 11:56 timers
-rw-rw-rw-   1 root root 0 Mar  8 11:56 timerslack_ns
-rw-r--r--   1 root root 0 Mar  8 11:56 uid_map
-r--r--r--   1 root root 0 Mar  8 11:56 wchan