How can I limit core files? Updated: 04/03/01


In the POSIX shell (/usr/bin/sh):

$ ulimit -c 0

To disable core dump generation for all POSIX shell users on the system,
add the following line to your /etc/profile:

ulimit -c 0 2>/dev/null # swallow ksh error msg

In the C shell (/usr/bin/csh):

% limit coredumpsize 0

To disable core dump generation for all C shell users on the system, add
the following line to your /etc/csh.login:

limit coredumpsize 0

There is no coredump limit facility available in the Korn shell
(/usr/bin/ksh) or the Bourne shell (/usr/old/bin/sh).

As originally shipped, HP-UX 10.01/10/20 create a 0-byte core file if the
core dump limit has been set to 0. The following patches will change
the behavior to not creating a core file at all if the limit is 0 (the
commonly expected behavior):

o 10.20 700: PHKL_22701
o 10.20 800: PHKL_22702
o 10.10 700: PHKL_23477
o 10.10 800: PHKL_23478
o 10.01 700: PHKL_23512
o 10.01 800: PHKL_23513

Prior to 10.01, HP-UX had no built in function to limit core file
generation from the standard shells.

One way to limit core file generation is to create a directory called
"core" with 000 permissions in the directory in which you expect a core
dump to occur. Additionally, two programs are available (nocore and
corelimit) that can be used as wrappers around other programs that you
may expect to dump. And, many publicly available shells (tcsh, bash,
etc..) allow core file limits. Or, you can place a link called "core"
to /dev/null in the directory you expect the core dump to occur.

Here is the source for corelimit. It is completely unsupported; the
Response Center will disavow all knowledge of you and your mission should
you call them with a problem relating to this. Build it in the usual way
(cc -o corelimit corelimit.c) and use it like so: "corelimit hpterm 0".
This example will limit the core file size of all children of the hpterm
process to 0.

#include <stdio.h>
#include <sys/resource.h>
#define RLIMIT_CORE 4 /* core file size */

main(argc, argv)
int argc;
char **argv;
{
int res;
struct rlimit rlp;
if (argc != 3) {
fprintf(stderr, "%s: wrong number of parameters\n", argv[0]);
fprintf(stderr, "\tformat: %s command core_size\n", argv[0]);
exit(-1);
}
rlp.rlim_cur = atoi(argv[2]);
res = setrlimit(RLIMIT_CORE, &rlp);
if (res < 0) {
perror("setrlimit: RLIMIT_CORE");
exit(-2);
}
system(argv[1]);
}

To start all of CDE with core dumps disabled:

o compile corelimit (above) and copy the binary to /usr/local/bin/
o edit /usr/dt/config/dtrc.d/90_dtlogin_st

replace:
exec $DTLOGIN $VL_ARGS </dev/null >/dev/null 2>&1
with:
/usr/local/bin/corelimit exec $DTLOGIN $VL_ARGS </dev/null \
>/dev/null 2>&1

[an error occurred while processing this directive]