How will you debug an application that terminates with a non-zero exit code?
sobes.tech AI
Answer from AI
I will check the application and system logs for errors or exceptions that could have led to a crash. Using structured logging (JSON, key-value) makes analysis easier.
I will utilize tracing tools (for example, strace in Linux) to track system calls made by the application before the crash. This will help identify which resources or operations caused the problem.
If possible, I will run the application in a debugger (GDB, PDB, etc.) for step-by-step execution and to analyze the state of variables at the time of failure.
I will examine core dumps, if generated, using utilities like gdb to obtain stack traces and memory contents at the time of the crash.
I will check the environment in which the application was running: memory availability, disk space, network resources, configuration files, and environment variables.
I will compare the versions of all dependencies and libraries used by the application with the version on which the application runs stably.
I will try to reproduce the problem in a controlled testing environment, isolating potential external factors.
I will use monitoring metrics (CPU, memory, I/O) to identify peak loads or anomalies preceding the crash.
Example of using strace:
# Trace all system calls of a process with PID 12345
strace -p 12345
# Trace system calls for a command and record output to a file
strace -o syscalls.log ./my_app arg1 arg2
Example of analyzing a core dump with GDB:
# Run GDB with the executable and core dump
gdb ./my_app core.12345
# Inside GDB:
# Show stack trace
(gdb) bt
# Show local variable values
(gdb) info locals
# Show function argument values
(gdb) info args