一、dmesg是做什么的?
用来显示开机信息, kernel会将开机信息存储在ring buffer中。开机时来不及查看信息,可利用dmesg来查看。开机信息亦保存在/var/log/dmesg。我觉得和windows的事件记录差不多:
image.png
二、dmesg能做什么?
按理说涉及到一些硬件、驱动、应用程序的安装都会在/var/log/dmesg记录日志.如果出现问题毫无头绪的时候或许它会带给你一些思路。
但是对于一名程序员来说,如果突然遇到进程被杀死,而且又没有记录日志的情况该怎么解决了?dmesg是一个比较好的方案。例子:
[root@10 ~]# dmesg|grep -i kill
[7037720.970942] java invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0
[7037720.970977] [<ffffffff81117311>] oom_kill_process+0x241/0x390
[7037720.970979] [<ffffffff81116dad>] ? oom_unkillable_task+0xcd/0x120
[7037721.035435] Out of memory: Kill process 1702 (mysqld) score 654 or sacrifice child
[7037721.035485] Killed process 1702 (mysqld) total-vm:26986284kB, anon-rss:21371076kB, file-rss:0kB
[13068470.038057] cftlogagent invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0
[13068470.038093] [<ffffffff81117311>] oom_kill_process+0x241/0x390
[13068470.038095] [<ffffffff81116dad>] ? oom_unkillable_task+0xcd/0x120
[13068470.088787] Out of memory: Kill process 3395 (mysqld) score 760 or sacrifice child
[13068470.088877] Killed process 3395 (mysqld) total-vm:29259688kB, anon-rss:23601276kB, file-rss:0kB
[16675520.838442] sendfile invoked oom-killer: gfp_mask=0x200da, order=0, oom_score_adj=0
[16675520.838472] [<ffffffff81117311>] oom_kill_process+0x241/0x390
[16675520.838474] [<ffffffff81116dad>] ? oom_unkillable_task+0xcd/0x120
[16675520.896256] Out of memory: Kill process 1918 (mysqld) score 722 or sacrifice child
[16675520.896336] Killed process 1918 (mysqld) total-vm:27805180kB, anon-rss:22767460kB, file-rss:0kB
[17428521.411478] java invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0
[17428521.411523] [<ffffffff81117311>] oom_kill_process+0x241/0x390
[17428521.411526] [<ffffffff81116dad>] ? oom_unkillable_task+0xcd/0x120
[17428521.464182] Out of memory: Kill process 20757 (mysqld) score 656 or sacrifice child
[17428521.464267] Killed process 20757 (mysqld) total-vm:26523640kB, anon-rss:21080056kB, file-rss:0kB
[root@10 ~]#
发现系统自动kill掉了一些mysqld进程。那为什么系统会自动杀死进程呢?应该是出于保护作用,将某些内存占用非常多的进程杀死,从而保护进程不会因为内存耗尽而宕机。
网友评论