LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   why different signals send to programs that exceeded memory limit set by setrlimit()? (https://www.linuxquestions.org/questions/programming-9/why-different-signals-send-to-programs-that-exceeded-memory-limit-set-by-setrlimit-829956/)

lonelycorn 09-02-2010 10:20 AM

why different signals send to programs that exceeded memory limit set by setrlimit()?
 
hi all!

i'm having a problem with setrlimit() under linux.

if i used setrlimit(RLIMIT_AS) to set a hard ceiling of virtual memory usage first, then request memory more than that, shouldn't i receive a signal like SIGSEGV?

first i tried the command ulimit in bash, which acted as if i called setrlimit(). i tried 3 programs that overflowed the memory limit i set. i though all the programs would be terminated by a SIGSEGV. but the pascal program received SIGKILL; the C++ program got SIGABRT; the C program, SIGSEGV.

i though there maybe something different between setrlimit() and ulimit, so i wrote a program in C++, fork() first, setrlimit() then execv() in the child, and wait(&status) in the parent. but i got the same result.

i was wondering why these could happen, and could anyone tell me how could i deal with them? i mean, how can i judge that the program exited abnormally because it exceed memory limit?

thx in advance.

entz 09-02-2010 08:19 PM

hello ,

well to be honest , i've not experimented with what you're doing so far , however from what i assuming you're doing

your only hope is to write a wrapper class that encapsulates the signal receiving operation

btw your example is kinda vague you need to provide lots more of info regarding your actual goal that you're trying to accomplish , sometimes things can be solved using much easier techniques ...

lonelycorn 09-02-2010 09:03 PM

sorry i didn't make it clear. my words may be somewhat ambiguous. but thx for your reply.

let me make it clear.

my program was trying to inspect the memory usage of other programs. i mean, execute a program and collect info about its memory usage. of course there is a limit on memory, just in case.

my program would give a summary of memory usage if the program executed successfully within the limit i set, or give a warning like "memory limit exceeded" if not.

first i used fork() to create a child process.

in the child process i used setrlimit(RLIMIT_AS) to set the soft and hard ceiling, then execv() the external program;

the parent process would check the child's memory usage via /proc/<pid>/statm every 10ms. if the child had exited (either normally or abnormally), the parent would use waitpid() to get the status of the child process. then use WEXITSTATUS() and WTERMSIG() to get the exit status and the signal that terminated the child.

i thought the signal would be SIGSEGV if the program overflowed the memory limit, but in fact, SIGKILL for pascal programs, SIGABRT for c++ programs, SIGSEGV for c programs.

how could this happen?


All times are GMT -5. The time now is 07:58 AM.