[Python-Dev] Preventing recursion core dumps

Thomas Wouters thomas@xs4all.net
Fri, 11 Aug 2000 16:08:51 +0200


On Fri, Aug 11, 2000 at 09:28:09AM -0500, Guido van Rossum wrote:

> It would be good if there was a way to sense the remaining available
> stack, even if it wasn't portable.  Any Linux experts out there?

getrlimit and getrusage do what you want to, I think. getrusage() fills a
struct rusage:


            struct rusage
            {
                 struct timeval ru_utime; /* user time used */
                 struct timeval ru_stime; /* system time used */
                 long ru_maxrss;          /* maximum resident set size */
                 long ru_ixrss;      /* integral shared memory size */
                 long ru_idrss;      /* integral unshared data size */
                 long ru_isrss;      /* integral unshared stack size */
                 long ru_minflt;          /* page reclaims */
                 long ru_majflt;          /* page faults */
                 long ru_nswap;      /* swaps */
                 long ru_inblock;         /* block input operations */
                 long ru_oublock;         /* block output operations */
                 long ru_msgsnd;          /* messages sent */
                 long ru_msgrcv;          /* messages received */
                 long ru_nsignals;        /* signals received */
                 long ru_nvcsw;      /* voluntary context switches */
                 long ru_nivcsw;          /* involuntary context switches */
            };

and you can get the actual stack limit with getrlimit(). The availability of
getrusage/getrlimit is already checked by configure, and there's the
resource module which wraps those functions and structs for Python code.
Note that Linux isn't likely to be a problem, most linux distributions have
liberal limits to start with (still the 'single-user OS' ;)

BSDI, for instance, has very strict default limits -- the standard limits
aren't even enough to start 'pine' on a few MB of mailbox. (But BSDI has
rusage/rlimit, so we can 'autodetect' this.)

-- 
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!