WCHAN 以 ps 为单位的值

Chi*_*rya 10 kernel ps

WCHAN(等待通道)究竟是什么意思?它的价值是什么以及这些价值代表什么?我试图找到他们,但一无所获。

mur*_*uru 3

来自man ps, 部分Standard Format Specifiers:

nwchan     WCHAN     address of the kernel function where the process
                     is sleeping (use wchan if you want the kernel
                     function name).  Running tasks will display a
                     dash ('-') in this column.
wchan      WCHAN     name of the kernel function in which the process
                     is sleeping, a "-" if the process is running, or
                     a "*" if the process is multi-threaded and ps is
                     not displaying threads.
Run Code Online (Sandbox Code Playgroud)

可以看出,它们是进程当前正在使用的内核函数。更远:

-n namelist
      Set namelist file.  Identical to N.  The namelist file is needed
      for a proper WCHAN display, and must match the current Linux
      kernel exactly for correct output.  Without this option, the
      default search path for the namelist is:

              $PS_SYSMAP
              $PS_SYSTEM_MAP
              /proc/*/wchan
              /boot/System.map-$(uname -r)
              /boot/System.map
              /lib/modules/$(uname -r)/System.map
              /usr/src/linux/System.map
              /System.map
Run Code Online (Sandbox Code Playgroud)

您可以/boot/System.map-$(uname -r)在 Ubuntu 上检查函数列表:

$ sudo head /boot/System.map-$(uname -r)
0000000000000000 D __per_cpu_start
0000000000000000 D irq_stack_union
0000000000000000 A xen_irq_disable_direct_reloc
0000000000000000 A xen_save_fl_direct_reloc
00000000000001e0 A kexec_control_code_size
0000000000004000 d exception_stacks
0000000000009000 D gdt_page
000000000000a000 D espfix_waddr
000000000000a008 D espfix_stack
000000000000a020 D cpu_info
Run Code Online (Sandbox Code Playgroud)

  • @ChiragAcharya 正如我所说,阅读内核源代码。您可以访问 http://lxr.free-electrons.com/ 等网站来搜索函数。并将“-o wchan=WIDE-WCHAN-COLUMN”与“ps”一起使用,以便获得完整的函数名称。 (2认同)

Cra*_*ger 1

请注意,这个答案大部分已经过时:您永远不需要名单或System.map不再需要。psin直接procps-ng读取/proc/${pid}/wchan,而不是从/proc/${pid}/stat符号映射文件中读取第 30 个字段 (wchan) 并对其进行解码。

事实上,一些内核可能会将 wchan 字段设置/proc/${pid}/stat为 1 而不是实际值,以隐藏内核地址空间布局随机化的细节。

(不过,我在 Fedora 32 上使用 wchan 时遇到了一些奇怪的问题,请参阅fedora bug 1879450)。