---
title: "Linux服务器在kernel panic时自动重启"
author: "wangxc"
date: "2010-08-20T16:45:46Z"
tags: []
categories: ["非技术"]
slug: "linux-kernel-panic"
draft: false
lastmod: "2010-08-20T16:51:41Z"
id: 743424
url: "https://wangxc.iteye.com/blog/743424"
---

配置的方法很简单：

```java
sudo vi /etc/sysctl.conf
```


编辑sysct1.conf文件，在文件加入


```java
kernel.panic = 20
```


当系统遇到 kernel panic 20秒后自动重启。

linux在遇到kernel panic时，是怎么工作的，最权威的资料永远来自内核源代码：



```java

 ....  
   if (panic_timeout > 0) {  
                /*  
                 * Delay timeout seconds before rebooting the machine.
                 * We can't use the "normal" timers since we just panicked.
                 */ 
                printk(KERN_EMERG "Rebooting in %d seconds..", panic_timeout);  

                for (i = 0; i < panic_timeout*1000; ) {  
                        touch_nmi_watchdog();  
                       i += panic_blink(i); 
                        mdelay(1);  
                        i++;  
                }  

               /*  
                * This will not be a clean reboot, with everything 
                * shutting down.  But if there is a chance of                    
                * rebooting the system it will be rebooted. 
                */

              emergency_restart();  

        }  

......



```