Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the path of, or disable python's core dump?

Tags:

python

linux

dump

I need to change the path of the python's core dump file, or completely disable it. I'm aware that it's possible to change the pattern and location of the core dumps in linux using:

/proc/sys/kernel/core_pattern 

But this is not a suitable solution on a shared server and/or on a grid engine.

So, how can I change the path of python's core dump, or how can I disable it's flush to the disk?

Is it possible to change that pattern to /dev/null only for my user?

like image 646
adrin Avatar asked Oct 31 '25 03:10

adrin


2 Answers

You can use shell command ulimit to control it:

ulimit -c 0  # Disable core file creation

Without the value, it will print current limit (the maximum size of core file will be created):

ulimit -c
like image 104
falsetru Avatar answered Nov 01 '25 18:11

falsetru


I think, this page gives you what you are looking for: http://sigquit.wordpress.com/2009/03/13/the-core-pattern/

Quoting from the page:

"...the kernel configuration includes a file named “core_pattern”:

/proc/sys/kernel/core_pattern

In my system, that file contains just this single word: core

As expected, this pattern shows how the core file will be generated. Two things can be understood from the previous line: The filename of the core dump file generated will be “core”; and second, the current directory will be used to store it (as the path specified is completely relative to the current directory).

Now, if we change the contents of that file… (as root, of course)

$> mkdir -p /tmp/cores
$> chmod a+rwx /tmp/cores
$> echo "/tmp/cores/core.%e.%p.%h.%t" > /proc/sys/kernel/core_pattern

You can use the following pattern elements in the core_pattern file:

%p: pid
%: '%' is dropped
%%: output one '%'
%u: uid
%g: gid
%s: signal number
%t: UNIX time of dump
%h: hostname
%e: executable filename
%: both are dropped

Further on, this part touches the specific need of handling things when working on a cluster of nodes:

Isn’t is great?! Imagine that you have a cluster of machines and you want to use a NFS directory to store all core files from all the nodes. You will be able to detect which node generated the core file (with the hostname), which program generated it (with the program name), and also when did it happen (with the unix time).

And configuring it for good,

The changes done before are only applicable until the next reboot. In order to make the change in all future reboots, you will need to add the following in “/etc/sysctl.conf“:

# Own core file pattern...
kernel.core_pattern=/tmp/cores/core.%e.%p.%h.%t

sysctl.conf is the file controlling every configuration under /proc/sys

like image 22
SPN Avatar answered Nov 01 '25 18:11

SPN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!