/proc/sysrq-trigger

Linux中可以通过给/proc/sysrq-trigger文件中写不同的字符来触发不同动作,比如说系统重启,构造crashdump等。

详细信息如下所示:

// 详细信息可以参考内核源码中文档:/Documentation/admin-guide/sysrq.rst
=========== ===================================================================
Command     Function
=========== ===================================================================
``b``       Will immediately reboot the system without syncing or unmounting
            your disks.
            将立即重启系统而不同步或卸载你的磁盘。

``c``       Will perform a system crash by a NULL pointer dereference.
            A crashdump will be taken if configured.
            如果系统配置好kdump,将制造系统crash并进行故障转储

``d``       Shows all locks that are held.
			显示系统中所有被持有锁的情况

``e``       Send a SIGTERM to all processes, except for init.
			向除 init 之外的所有进程发送 SIGTERM(优雅退出)

``f``       Will call the oom killer to kill a memory hog process, but do not
            panic if nothing can be killed.
            将调用 oom killer 来杀死内存占用进程
            
``g``       Used by kgdb (kernel debugger)
			由 kgdb(内核调试器)使用

``h``       Will display help (actually any other key than those listed
            here will display help. but ``h`` is easy to remember :-)
            显示所有支持的信号

``i``       Send a SIGKILL to all processes, except for init.
			向除 init 之外的所有进程发送 SIGKILL(强制退出)

``j``       Forcibly "Just thaw it" - filesystems frozen by the FIFREEZE ioctl.
			强制“解冻它”——FIFREEZE ioctl 冻结的文件系统

``k``       Secure Access Key (SAK) Kills all programs on the current virtual
            console. NOTE: See important comments below in SAK section.

``l``       Shows a stack backtrace for all active CPUs.
			显示所有活动 CPU 的堆栈回溯

``m``       Will dump current memory info to your console.
			会将当前内存信息转储到控制台

``n``       Used to make RT tasks nice-able

``o``       Will shut your system off (if configured and supported).
			将关闭系统(如果配置和支持)

``p``       Will dump the current registers and flags to your console.
			会将当前寄存器和标志转储到控制台

``q``       Will dump per CPU lists of all armed hrtimers (but NOT regular
            timer_list timers) and detailed information about all
            clockevent devices.
            将转储所有的hrtimers定时器(非常规的timer_list计时器)的每个 CPU 列表以及有关所有clockevent 设备的详细信息

``r``       Turns off keyboard raw mode and sets it to XLATE.

``s``       Will attempt to sync all mounted filesystems.
			将尝试同步所有已安装的文件系统

``t``       Will dump a list of current tasks and their information to your
            console.
            会将当前任务及其信息的列表转储到控制台

``u``       Will attempt to remount all mounted filesystems read-only.
			将尝试以只读方式重新挂载所有已安装的文件系统

``v``       Forcefully restores framebuffer console
``v``       Causes ETM buffer dump [ARM-specific]

``w``       Dumps tasks that are in uninterruptable (blocked) state.

``x``       Used by xmon interface on ppc/powerpc platforms.
            Show global PMU Registers on sparc64.
            Dump all TLB entries on MIPS.

``y``       Show global CPU Registers [SPARC-64 specific]

``z``       Dump the ftrace buffer
			转储 ftrace 缓冲区

``0``-``9`` Sets the console log level, controlling which kernel messages
            will be printed to your console. (``0``, for example would make
            it so that only emergency messages like PANICs or OOPSes would
            make it to your console.)
            设置控制台日志级别,控制哪些内核消息将打印到您的控制台。动态调整内核调试信息的打印等级。
=========== ===================================================================

除重启、关机、panic之外的所有调试信息可以通过dmesg信息查看,所有命令均需要在root权限下执行,以打印内核内存信息为例。

$ sudo echo m > /proc/sysrq-trigger
$ sudo dmesg
[180925.410625] sysrq: Show Memory
[180925.410635] Mem-Info:
[180925.410638] active_anon:64926 inactive_anon:627749 isolated_anon:0
                 active_file:236914 inactive_file:97644 isolated_file:0
                 unevictable:293560 dirty:408 writeback:0
                 slab_reclaimable:29004 slab_unreclaimable:30334
                 mapped:241633 shmem:614940 pagetables:9353 bounce:0
                 kernel_misc_reclaimable:0
                 free:540657 free_pcp:14250 free_cma:0
[180925.410645] Node 0 active_anon:259704kB inactive_anon:2510996kB active_file:947656kB inactive_file:390576kB unevictable:1174240kB isolated(anon):0kB isolated(file):0kB mapped:966532kB dirty:1632kB writeback:0kB shmem:2459760kB shmem_thp: 0kB shmem_pmdmapped: 0kB anon_thp: 0kB writeback_tmp:0kB kernel_stack:12176kB pagetables:37412kB all_unreclaimable? no
[180925.410653] Node 0 DMA free:14336kB min:132kB low:164kB high:196kB reserved_highatomic:0KB active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB writepending:0kB present:15896kB managed:15360kB mlocked:0kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB
[180925.410661] lowmem_reserve[]: 0 2163 7598 7598 7598
[180925.410669] Node 0 DMA32 free:1718312kB min:21252kB low:26052kB high:30852kB reserved_highatomic:0KB active_anon:62604kB inactive_anon:319324kB active_file:37004kB inactive_file:42488kB unevictable:46620kB writepending:128kB present:2537216kB managed:2274448kB mlocked:0kB bounce:0kB free_pcp:12968kB local_pcp:2860kB free_cma:0kB
[180925.410677] lowmem_reserve[]: 0 0 5435 5435 5435
[180925.410684] Node 0 Normal free:429980kB min:54388kB low:66448kB high:78508kB reserved_highatomic:0KB active_anon:197100kB inactive_anon:2191672kB active_file:910652kB inactive_file:348088kB unevictable:1127620kB writepending:1504kB present:5756928kB managed:5574372kB mlocked:64kB bounce:0kB free_pcp:44032kB local_pcp:8096kB free_cma:0kB
[180925.410693] lowmem_reserve[]: 0 0 0 0 0
[180925.410700] Node 0 DMA: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 1*2048kB (M) 3*4096kB (M) = 14336kB
[180925.410720] Node 0 DMA32: 21094*4kB (UME) 11864*8kB (UME) 6489*16kB (UME) 3860*32kB (UME) 2207*64kB (UME) 1336*128kB (UME) 704*256kB (ME) 426*512kB (ME) 251*1024kB (ME) 118*2048kB (E) 25*4096kB (UME) = 1718312kB
[180925.410744] Node 0 Normal: 1009*4kB (UME) 2321*8kB (UME) 1271*16kB (UME) 517*32kB (UME) 285*64kB (UME) 234*128kB (UME) 357*256kB (UME) 99*512kB (UME) 110*1024kB (UME) 27*2048kB (E) 3*4096kB (E) = 429980kB
[180925.410768] Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=1048576kB
[180925.410771] Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=2048kB
[180925.410773] 955438 total pagecache pages
[180925.410774] 6543 pages in swap cache
[180925.410776] Swap cache stats: add 1103399, delete 1096809, find 392708/470480
[180925.410778] Free swap  = 1464692kB
[180925.410779] Total swap = 2097148kB
[180925.410780] 2077510 pages RAM
[180925.410781] 0 pages HighMem/MovableOnly
[180925.410783] 111465 pages reserved
[180925.410784] 0 pages hwpoisoned
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值