面試:如果程式崩潰,可能的原因是什嗎?

來源:互聯網
上載者:User

You are given the source to an application which crashes when it is run. After running
it ten times in a debugger, you find it never crashes in the same place. The application
is single threaded, and uses only the C standard library. What programming errors
could be causing this crash? How would you test each one?

大意:你得到一個應用的源碼,該應用每次啟動都會出現程式崩潰。再你調試了10次後發現,在一個相同的條件下,該程式從不崩潰。

該程式是單線程,並且使用的庫函數是c的標準庫。那麼,該程式崩潰的原因是什嗎?你怎樣檢測它呢?

The question largely depends on the type of application being diagnosed. However, we can

give some general causes of random crashes.
1. Random variable: The application uses some random number or variable component
   which may not be fixed for every execution of the program. Examples include: user
  input, a random number generated by the program, or the time of day.
2. Memory Leak: The program may have run out of memory. Other culprits are totally
   random for each run since it depends on the number of processes running at that
  particular time. This also includes heap overflow or corruption of data on the stack.
It is also possible that the program depends on another application / external module that
could lead to the crash. If our application, for example, depends on some system attributes
and they are modified by another program, then this interference may lead to a crash. Pro-
grams which interact with hardware are more prone to these errors.
In an interview, we should ask about which kind of application is being run. This information
may give you some idea about the kind of error the interviewer is looking for. For example,
a web server is more prone to memory leakage, whereas a program that runs close to the

system level is more prone to crashes due to system dependencies.

答案:該問題很大程度上取決於對該應用的診斷。但我們可以總結一下一些隨機常見的崩潰原因:

1. 不確定的變數:程式使用了隨機的數字或變數組件,在程式執行時沒有被很好的確定範圍。如:使用者輸入,隨機數,或時間。

2.記憶體流失:程式每次執行時都記憶體溢出。每次運行程式崩潰的罪魁禍首是隨機的,因為它依賴於在特定時間啟動並執行進程數。

包括堆溢出或者是棧異常。

程式依賴於其它外部應用也可能導致崩潰。如果我們的應用依賴於一個系統某些系統屬性,他們被另一個程式修改,那麼這個幹擾可能會導致系統崩潰。與硬體互動的程式更容易出現這些錯誤。例如,一個Web伺服器是更容易出現記憶體流失,而接近系統級啟動並執行程式更容易崩潰,由於系統的依賴。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.