LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 09-02-2010, 10:20 AM   #1
lonelycorn
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 06:16 AM.
 
Old 09-02-2010, 08:19 PM   #2
entz
Member
 
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, 09:03 PM   #3
lonelycorn
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 06:17 AM.
 
  


Reply



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 08:23 AM
file size limit exceeded arunachalam Linux - Software 3 10-01-2007 09:16 AM
File size limit exceeded debeus Slackware 4 11-07-2006 10:36 AM
File size limit exceeded wfernley Linux - Software 5 07-21-2006 03:31 PM
file size limit exceeded mchitrakar Linux - General 2 10-12-2004 12:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:02 PM.

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