Linux Kernel Debugging Methods

The CONFIG_MAGIC_SYSRQ option should be enabled in the kernel configuration options, so that after the system starts, the /proc/sysrq-trigger node will be generated for debugging.

Second, you can set kernel.sysrq=1 in /etc/sysctl.conf to enable the sysq function by default. You can also dynamically enable the sysrq function by writing to the /proc/sys/kernel/sysrq node. Writing different values ​​enables different functions:

0 - disable sysrq completely

1 - enable all functions of sysrq

2 - enable control of console   logging level

4 - enable control of keyboard (SAK,   unraw)

8 - enable debugging dumps of   processes etc.

16 - enable sync command

32 - enable remount read-only

64 - enable signalling of processes   (term, kill, oom-kill)

128- allow reboot/poweroff

256- allow nicing of all RT tasks

【Instructions for use】

#echo m > /proc/sysrq-trigger export memory allocation information

#echo t > /proc/sysrq-trigger Export current task status information

#echo p > /proc/sysrq-trigger Export current CPU register and flag information

#echo c > /proc/sysrq-trigger generates a null pointer panic event, which artificially causes the system to crash

#echo s > /proc/sysrq-trigger syncs all mounted filesystems instantly

#echo u > /proc/sysrq-trigger instantly remounts all filesystems as read-only

#echo w > /proc/sysrq-trigger Dump tasks in uninterruptable blocking state

Easily kill linux, introduce the powerful functions of /proc/sysrq-trigger  

Reboot the computer now echo "b" > /proc/sysrq-trigger

Shut down the computer immediately echo "o" > /proc/sysrq-trigger

Export memory allocation information echo "m" > proc/sysrq-trigger (can be viewed with /var/log/message) Outputs memory statistics to the console

Export current CPU register information and flag bit information echo "p" > proc/sysrq-trigger (outputs all flags and registers to the console)

Export thread status information echo "t" > proc/sysrq-trigger (outputs a list of processes to the console)

故意让系统崩溃            echo "c"  > proc/sysrq-trigger         (crashes the system without first unmounting file systems or syncing disks attached to the system)

Remount all filesystems immediately echo "s" > proc/sysrq-trigger (attempts to sync disks attached to the system)

Immediately remount all file systems as read-only echo "u" > proc/sysrq-trigger (attempts to unmount and remount all file systems as read-only)

In addition, there are two functions similar to force logout

e ---- kills all processes except init using SIGTERM

i ---- kills all processes except init using SIGKILL

 

When a sysrq command is triggered, the kernel will print information to the kernel's ring buffer and output to the system console. This information is also typically output to /var/log/messages via syslog.
Occasionally, the system may have become unresponsive and syslogd may not be able to log this information. In this case, it is recommended that you set up a serial terminal to collect this information.
What types of sysrq events can be fired?
After the sysrq feature is turned on, several sysrq events can be fired. Different kernel versions may be slightly different. But some are shared:
* m - export information about memory allocation ,
* t - export thread state information,
* p - export the current CPU register information and flag bit information,
* c - intentionally crash the system (useful when using netdump or diskdump),
*s - syncs all mounted filesystems on the fly,
* u - instantly remounts all filesystems as read-only,
*b - reboot the system on the fly,
* o - Instant shutdown (if the machine is set up and supports this feature).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324981350&siteId=291194637