> However, your point about programs invoked by make inheriting the > setrlimit() is definitely something that seems problematic. Perhaps GNU > make could change the stack limit back to what it was after it forks but > before it execs its child. I wonder what happens if you change a limit to > something too small for the current processes resources?
It doesn't look specified by http://www.opengroup.org/onlinepubs/009695399/functions/getrlimit.html. This test suggests that it works fine on my Linux box. I presume the limit check is normally done on a faulting access off the end of the stack, so setrlimit would need some to have some different and special code to check the current stack usage if it wanted to apply the check immediately. It seems a bit unlikely that anyone would have gone to that effort, thus stopping you from doing something useful in this sort of situation. #include <alloca.h> #include <errno.h> #include <iostream> #include <stddef.h> #include <string.h> #include <sys/time.h> #include <sys/resource.h> void useLotsOfStack(size_t size); size_t getAndDisplayStackLimit() { rlimit resourceLimit; if (getrlimit(RLIMIT_STACK, &resourceLimit) < 0) { std::cerr << "getrlimit failed with " << errno << std::endl; } std::cout << "rlim_cur == " << resourceLimit.rlim_cur << std::endl; std::cout << "rlim_max == " << resourceLimit.rlim_max << std::endl; return resourceLimit.rlim_cur; } void setStackLimit(size_t size) { rlimit resourceLimit; resourceLimit.rlim_cur = size; if (setrlimit(RLIMIT_STACK, &resourceLimit) < 0) { std::cerr << "setrlimit failed with " << errno << std::endl; exit(1); } getAndDisplayStackLimit(); } int main() { size_t initialLimit = getAndDisplayStackLimit(); //useLotsOfStack(initialLimit * 10); setStackLimit(initialLimit * 100); useLotsOfStack(initialLimit * 10); setStackLimit(initialLimit); useLotsOfStack(initialLimit * 10); } void useLotsOfStack(size_t size) { memset(alloca(size), 0, size); } ------------------------------------- Martin's Outlook, BlueArc Engineering _______________________________________________ Bug-make mailing list Bug-make@gnu.org http://lists.gnu.org/mailman/listinfo/bug-make