0

I am running OpenSUSE. I usually open the console with an interactive non-login shell bash, and frequently use tcsh after logon. I am writing some C code, compiling with gcc, and I'd like to have the core dump files created whenever an executable fails.

I know I can select manually the core dump size to be unlimited, but I don't want to type

limits coredumpsize unlimited

in tcsh or

ulimit -c unlimited

in the default shell bash every time I log on as my user.

Is there a way to set the core dump size automatically whenever I logon as user in bash and/or tcsh?

0

After a bit of research I may have solved the problem. Once I login to the UNIX machine, it redirects me to the home directory, according to the shell chosen, from the available ones on the system from the file \etc\passwd as follows:

alandella:x:1000:100:alandella:/home/alandella:/bin/bash

This explains the non-login interactive bash shell (konsole). The shell, let it be bash or tcsh runs, and the following files are read at login/logout:

~/.login  -> Executes cmds at login
~/.tcshrc ->               same as ~./bashrc in bash and ~./cshrc in csh
~/.logout ->               at logout

So, by adding the following lines to the ~/.tcshrc and ~/.bashrc files:

~/.bashrc -> ulimit -Sc X
~/.tcshrc -> limit coredumpsize X

where X is a value (kB) or unlimited, and it should do the trick.

Sometimes, it is told to also edit the ~/.profile file. I did not edit it, even if MY bash shell sources it at login. Why does it not make a difference? Because I always use a non-login shell, as I double-click konsole to open the terminal. The ~/.profile file is sourced at startup only in a login shell (usually sh, which I do not use). I have bash that looks at the following files in sequence:

.bash_profile -> .bash_login -> .profile

in MY case, the first two files do not exist, so bash sources .profile if I use a login shell.

NOTE. This operation must be done as root, and in order to make this trick work, the following conditions must/should be met:

  1. That the file /etc/security/limits.conf sets suitable hard/soft limits for the user and root. If a hard limit of the core dump size of 2000 kB is imposed, then when we modify ~/.bashrc with 3000 kB, the core dump size limit will continue to be 2000 kB. Lookup limits.conf.

  2. That the files under /etc/pam.d contain the session required pam_limits.so line, in order to allow the /etc/security/limits.conf settings to take place.

  3. That the file /etc/sysctl.conf contains kernel.core_pattern = core.%e.%p, this sets the format of the generated core files, where %e is the executable filename and %p is the pid.

  • Note: the ~/.bashrc, ~/.cshrc and ~/.tcshrc are initialisation scripts which are read at each shell or subshell. If for example you run a shell script which make a loop running another subshell 1000 times, this initialisation script will be read 1000 times. The ulimit or limit you need, has to be called only once and so has to be called within ~/.profile or ~/.login. – daniel Azuelos Mar 26 '18 at 11:06
  • @danielAzuelos I tried that, but whenever I delete the lines in ~/.bashrc or ~/.tcshrc and add the new limit setting in ~/.profile, the soft limit for the core sticks at 0 for some wizardry I cannot wrap my head around – alandella Mar 26 '18 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.