Operating System - HP-UX
1748151 Members
3734 Online
108758 Solutions
New Discussion юеВ

how to avoid producing "core" or let the size of core be zero?

 
whuijun
Occasional Advisor

how to avoid producing "core" or let the size of core be zero?

sometimes,I found that my system produced a core file which size is very big and lead to the space of disk used up.also lost some production data.
so I want to know how to avoid this case on time?

thanks.
12 REPLIES 12
Zigor Buruaga
Esteemed Contributor

Re: how to avoid producing "core" or let the size of core be zero?

Hi,

Try with:

$ ulimit -c SIZE_IN_BLOCKS # Limit core size under sh or ksh

$ limit coredumpsize SIZE_IN_KB # Limit core size under csh or tcsh


Kind regards,
Zigor
Zigor Buruaga
Esteemed Contributor

Re: how to avoid producing "core" or let the size of core be zero?

Take also a look at this link:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=6369

HTH
Kind regards,
Zigor
Ashwani Kashyap
Honored Contributor

Re: how to avoid producing "core" or let the size of core be zero?

The core file creation process is part of the kernel and it simply takes
everything in the program's memory and writes it as a file named 'core' in
the current directory. Oone way to prevent this from happening, do the
following:

cd
touch core
chmod 0 core
chown root core

Now, core files can't be created because the file has no permissions for
any user (except the superuser) and the file can't be changed by the user
since it's owned by root. It is a zero-length file so it occupies no space.
And to keep from having cron messages about not being able to remove a
directory called core, change the above find command to:

find / -name "core" -type f -exec rm {} \;

However, the easier technique is to use the POSIX shell builtin called
ulimit. Normally, ulimit is a programming interface (section 2 of the
man pages) but with ksh and sh-posix, this is much easier to change at
the command line. ksh does not have the full complement of options (it
only supports the maximum file size that can be created), while POSIX
shell has almost a dozen options. To limit core files to zero, use:

ulimit -c 0

>From now on, any process that is started from this shell prompt will
produce a zero-length core file. Try this (with the POSIX shell)
to prove it:

ulimit -c 0
sleep 500 &
ps

kill -3

This will produce a zero-length core file.
whuijun
Occasional Advisor

Re: how to avoid producing "core" or let the size of core be zero?

Ashwani Kashyap ,
thanks for your informations.
but I found after I issued as the following:

>ulimit -c 0
>sleep 500 &
[1] 3834

>ps

>kill -3 3834

but I didn't find any core produced.why?

thanks again.

Bill Hassell
Honored Contributor

Re: how to avoid producing "core" or let the size of core be zero?

ulimit -c 0 is working exactly as expected. The maximum size of all core files produced from this shell and children will be zero (which is no core file at all). So to answer your original question, make sure ulimit -c 0 is present in all login environments. (this is infinitely simpler than creating directories called 'core' or similar.

However, you need to determine what program is creating the core files (hint: file core). The reason is that ulimit is effective in the environment in which it is run, which means that it must be added to batch jobs run by cron and perhaps to bootup processes.

If you need to preserve a core file to determine the reason for the program's failure, I would use this in /etc/profile:

ulimit -Sc 0

which means that a programmer/developer can override the current ulimit value (-S is the softlimit value).


Bill Hassell, sysadmin
whuijun
Occasional Advisor

Re: how to avoid producing "core" or let the size of core be zero?

first,really thanks for your warm heart.

but I don't know how to make sure "make sure ulimit -c 0 is present in all login environments."

could you tell me how to do?

thanks again.
Bill Hassell
Honored Contributor

Re: how to avoid producing "core" or let the size of core be zero?

ulimit -a

If ulimit -a gives an error, you are running ksh which does not have the flexibility of the POSIX shell. However, /etc/profile is run by the POSIX shell so ulimit can be set there and will still affect ksh and all child processes. You can see the ulimit settings in ksh by typing /usr/bin/ulimit -a


Bill Hassell, sysadmin
whuijun
Occasional Advisor

Re: how to avoid producing "core" or let the size of core be zero?

I think I didn't express what I mean.

I mean I don't know how to let ulimit -c 0 is present in all login environments.

could you tell this in detail?
Bill Hassell
Honored Contributor

Re: how to avoid producing "core" or let the size of core be zero?

Edit the file: /etc/profile and add the following line in it:

ulimit -Sc 0

This will work for all 'normal' logins using sh or ksh as the shell. This assumes that your users do NOT use csh, and do not use remsh or rlogin to start a session on your system. Try it out by logging in with your personal login and type ulimit -a


Bill Hassell, sysadmin