Interview: if the program crashes, what are the possible causes?

Source: Internet
Author: 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
Cocould be causing this crash? How wocould you test each one?

You get the source code of an application. Every time the application is started, the program crashes. After debugging 10 times, you find that the program never crashes under the same conditions.

This program is a single thread and the library function used is the standard library of C. So what is the cause of the program crash? How do you detect it?

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
Particle time. This also has des heap overflow or upload uption of data on the stack.
It is also possible that the program depends on another application/external module that
Cocould 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 shocould 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

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

Answer: The question depends largely on the diagnosis of the application. However, we can summarize some common causes of random crashes:

1. uncertain variables: The program uses random numbers or variable components and is not well defined during program execution. For example, user input, random number, or time.

2. Memory leakage: memory overflow during each execution of the program. The culprit of each program crash is random because it depends on the number of processes running at a specific time.

This includes heap overflow or stack exceptions.

Programs that depend on other external applications may also crash. If our applications depend on some system attributes of one system and are modified by another program, this interference may cause system crash. Programs that interact with hardware are more prone to these errors. For example, a Web server is more prone to memory leaks, while programs close to system-level running are more prone to crash due to system dependencies.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.