Unix Shell - need help understanding bash ulimit -c

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > October 2006 > need help understanding bash ulimit -c





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author need help understanding bash ulimit -c
Jason Roscoe

2006-10-19, 7:23 pm

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;
}
Michael Paoli

2006-10-22, 7:20 am

Jason Roscoe wrote:
> 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)?
>
> % 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;
> }


raise(3)
signal(7)
The entries in the "Action" column of the table specify the
default
action for the signal, as follows:
Term Default action is to terminate the process.
Ign Default action is to ignore the signal.
Core Default action is to terminate the process and dump core.
Stop Default action is to stop the process.
Signal Value Action Comment

-------------------------------------------------------------------------
SIGSEGV 11 Core Invalid memory reference
kill(2)
setrlimit(2)
ulimit(1)
news:comp.unix.programmer
Followup-to:comp.unix.programmer

Dave Gibson

2006-10-22, 7:20 am

Jason Roscoe <jason.roscoe@gmail.com> wrote:
> 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.


[snip: limiting coredump size to 512 * 1024]

> Segmentation fault (core dumped)
> % ls -l core
> -rw------- 1 jacr swdvt 2265088 2006-10-19 14:24 core
> %


du -h core

It's a sparse file.

[snip: using malloc to force program size beyond known coredump limit]

The allocated memory contains all zero bytes, use memset to initialise
the memory.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com