WCHAN(等待通道)到底是什么意思?它的值是什么?这些值代表什么?我试图找到它们,但一无所获。
答案1
从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.
可以看出,它们是进程当前正在使用的内核函数。进一步:
-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
您可以/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
答案2
请注意,这个答案基本上已经过时了:你永远不需要名称列表或任何内容System.map
。直接ps
读取,而不是读取第 30 个字段(wchan)并根据符号映射文件对其进行解码。procps-ng
/proc/${pid}/wchan
/proc/${pid}/stat
事实上,一些内核可能会将 wchan 字段设置为/proc/${pid}/stat
1 而不是真实值,以隐藏内核地址空间布局随机化的细节。
(不过我在 Fedora 32 上使用 wchan 时遇到了一些奇怪的问题,请参阅Fedora 错误 1879450)。