Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-02-2010, 11:20 AM   #1
LQ Newbie
Registered: Sep 2010
Posts: 2

Rep: Reputation: 0
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.

Last edited by lonelycorn; 09-03-2010 at 07:16 AM.
Old 09-02-2010, 09:19 PM   #2
Registered: Mar 2007
Location: Milky Way , Planet Earth!
Distribution: Opensuse
Posts: 453
Blog Entries: 3

Rep: Reputation: 40
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 ...
Old 09-02-2010, 10:03 PM   #3
LQ Newbie
Registered: Sep 2010
Posts: 2

Original Poster
Rep: Reputation: 0
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?

Last edited by lonelycorn; 09-03-2010 at 07:17 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set memory cache limit for nfs server libin88 Linux - Server 1 10-24-2008 09:23 AM
file size limit exceeded arunachalam Linux - Software 3 10-01-2007 10:16 AM
File size limit exceeded debeus Slackware 4 11-07-2006 11:36 AM
File size limit exceeded wfernley Linux - Software 5 07-21-2006 04:31 PM
file size limit exceeded mchitrakar Linux - General 2 10-12-2004 01:47 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration