bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

need explanation ulimit -c for limiting core dumps


From: jason . roscoe
Subject: need explanation ulimit -c for limiting core dumps
Date: Thu, 19 Oct 2006 15:06:16 -0400

Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H  -I.  -I../bash -I../bash/include 
-I../bash/lib  -g -O2
uname output: Linux galaxy2 2.6.12.4 #2 SMP Tue Oct 17 14:53:07 EDT 2006 i686 
GNU/Linux
Machine Type: i386-pc-linux-gnu

Bash Version: 2.05b
Patch Level: 0
Release Status: release

Description:

Hi,
I'm trying to limit the size of coredumps using 'ulimit -c'.  Can someone 
please explain why a core file gets generated from the coretest program (source 
is below)?

Thanks for any help or suggestions.

Shell interaction
% ulimit -H -c
unlimited
% ulimit -S -c
0
% bash --version
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
Copyright (C) 2002 Free Software Foundation, Inc.
% ulimit -c 512
% ulimit -S -c
512
% ulimit -H -c
512
% ./coretest 2048
rlim_cur,rlim_max = 524288,524288
malloced 2097152 bytes my pid is 21255
Segmentation fault (core dumped)
% ls -l core
-rw-------  1 jacr swdvt 2265088 2006-10-19 14:24 core
% 

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>

int main(int argc, char* argv[])
{
    char* c;
    int mult=1024;
    int sz;
    struct rlimit rlim;   

    if(getrlimit(RLIMIT_CORE,&rlim))
        printf("error getting rlimit\n");

    printf("rlim_cur,rlim_max = %u,%u\n",rlim.rlim_cur,rlim.rlim_max);

    if(argc>1)
        mult=atoi(argv[1]);

    sz=mult*1024;
    c=malloc(sz);
    if(!c)
        {
        printf("unable to malloc\n");
        exit(EXIT_FAILURE);
        }

   printf("malloced %u bytes my pid is %u\n",sz,getpid());
   raise(SIGSEGV);

   return EXIT_SUCCESS;
}

Repeat-By:
   see above

Fix:
        [Description of how to fix the problem.  If you don't know a
        fix for the problem, don't include this section.]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]