How to generate a core dump in Linux on a segmentation fault?

前端 未结 12 1227
余生分开走
余生分开走 2020-11-22 17:06

I have a process in Linux that\'s getting a segmentation fault. How can I tell it to generate a core dump when it fails?

12条回答
  •  醉梦人生
    2020-11-22 17:41

    In order to activate the core dump do the following:

    1. In /etc/profile comment the line:

      # ulimit -S -c 0 > /dev/null 2>&1
      
    2. In /etc/security/limits.conf comment out the line:

      *               soft    core            0
      
    3. execute the cmd limit coredumpsize unlimited and check it with cmd limit:

      # limit coredumpsize unlimited
      # limit
      cputime      unlimited
      filesize     unlimited
      datasize     unlimited
      stacksize    10240 kbytes
      coredumpsize unlimited
      memoryuse    unlimited
      vmemoryuse   unlimited
      descriptors  1024
      memorylocked 32 kbytes
      maxproc      528383
      #
      
    4. to check if the corefile gets written you can kill the relating process with cmd kill -s SEGV (should not be needed, just in case no core file gets written this can be used as a check):

      # kill -s SEGV 
      

    Once the corefile has been written make sure to deactivate the coredump settings again in the relating files (1./2./3.) !

提交回复
热议问题