DEV Community

Masayoshi Mizutani
Masayoshi Mizutani

Posted on

5 2

How to get core file of segmentation fault process in Docker

Configure to get core file

Run following commands in a start up script of docker container.

echo '/tmp/core.%h.%e.%t' > /proc/sys/kernel/core_pattern
ulimit -c unlimited
Enter fullscreen mode Exit fullscreen mode
  • In some case, default value of /proc/sys/kernel/core_pattern is pipe. Then, it should be configured explicitly
  • Configure size of core file by ulimit command

Setting for the program

  • Enable debug option if the program is compiled by yourself. Install debug symbol if it's from package manager.
  • Do not delete source code in docker image.

Run container

  • Use --privileged option when docker run to allow write permission for /proc/sys/kernel/core_pattern

After segmentation fault

  • Check your container ID by docker ps -a command
  • Create docker image from the container by docker commit
    • example) docker commit -m "coredump" 92b8935a7cd7 (92b8935a7cd7 is container ID)
  • docker run -it <created image ID> sh and boot a container in a state immediately after segmentation falut

After boot a container

  • Install gdb if it hasn't been installed
  • Run gdb /path/to/binary /path/to/corefile
  • Enjoy debugging

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (1)

Collapse
 
jmeridth profile image
Jason Meridth • Edited

Awesome article. Only tip, is if you're using docker-compose you can use privileged: true from docs in your docker-compose.yml file.

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay