LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 01-03-2011, 06:56 PM   #1
codegenie
LQ Newbie
 
Registered: Oct 2010
Distribution: Redhat
Posts: 24

Rep: Reputation: -3
Allocate memory to a program before execution


I went to an interview last week and there was this guy who asked a simple question that i have been trying to solve for a couple of days. I tried google but i just cant get the search keywords right. The result were just useless. Well, the question is :

"How can we allocate a limited memory to a process before we start its execution"

well, the question is related to an X11 system so may be some flags must be set to limit its memory.

Last edited by codegenie; 01-03-2011 at 07:00 PM.
 
Old 01-03-2011, 07:17 PM   #2
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by codegenie View Post
I went to an interview last week and there was this guy who asked a simple question that i have been trying to solve for a couple of days. I tried google but i just cant get the search keywords right. The result were just useless. Well, the question is :

"How can we allocate a limited memory to a process before we start its execution"

well, the question is related to an X11 system so may be some flags must be set to limit its memory.
I'm not sure if I understood the question correctly, but maybe your are looking for something like "ulimit". For example, type "ulimit -a" assuming that you are on a Linux bash shell ("limit" for the C-shell) and you'll get a lot of parameters which could be set before an executable is started. Among others, you could limit the virtual memory, the heap, the stack, etc.

Maybe this helps,
Andi
 
Old 01-03-2011, 10:49 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Yes, I also thought about 'ulimit'.
 
Old 01-04-2011, 12:14 AM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 809

Rep: Reputation: 178Reputation: 178
I read the question in an entirely different way. Rather than limit, before execution, the amount of memory that could be allocated during execution, what if the original question was about allocating a limited amount of memory, um, before execution?

Just declare a global variable with that amount of memory in it. After all, the title of this thread is "Allocate memory to a program before execution".
 
Old 01-04-2011, 06:41 AM   #5
codegenie
LQ Newbie
 
Registered: Oct 2010
Distribution: Redhat
Posts: 24

Original Poster
Rep: Reputation: -3
wje_lq got it right. I asked "how to allocate memory", not to limit an allocated memory. And, btw ulimit allows us to control the number of processes an existing user on the server may be authorized to have. I am not sure it could be used for setting up a memory for a process. Well, What I asked is :

"How can we allocate a fixed(limited) memory to a process before its execution begins."

For eg: If I want to reserve 1GB space for my program at its time of execution, how will I notify the kernel(MMU) about this. I guess I made myself clear now.

And, wje_lq please elaborate on what you said ,
Quote:
Just declare a global variable with that amount of memory in it
 
Old 01-04-2011, 06:49 AM   #6
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by codegenie View Post
wje_lq got it right. I asked "how to allocate memory", not to limit an allocated memory.
Your initial statement
Quote:
well, the question is related to an X11 system so may be some flags must be set to limit its memory.
sounds a bit different, doesn't it? :-)

Quote:
And, btw ulimit allows us to control the number of processes an existing user on the server may be authorized to have. I am not sure it could be used for setting up a memory for a process.
I does allow you to do that. Read the man page!

Andi
 
Old 01-04-2011, 07:05 AM   #7
codegenie
LQ Newbie
 
Registered: Oct 2010
Distribution: Redhat
Posts: 24

Original Poster
Rep: Reputation: -3
My bad to add the last line. I am sorry for that.

I read the man. Can you show how to limit memory resource using ulimit() call.

P.S: I didnt mean limit i meant allocate. I am sorry if it confused you.
 
Old 01-04-2011, 07:09 AM   #8
codegenie
LQ Newbie
 
Registered: Oct 2010
Distribution: Redhat
Posts: 24

Original Poster
Rep: Reputation: -3
I am sorry all. I just found out

ulimit -S -v mem-in-kbytes


Thanks all i guess ulimit is what i wanted.
What confused me about ulimit's functionality is this page.

Last edited by codegenie; 01-04-2011 at 07:12 AM.
 
Old 01-27-2011, 12:42 PM   #9
z1p
Member
 
Registered: Jan 2011
Location: the right coast of the US
Distribution: Ubuntu 10.04
Posts: 80

Rep: Reputation: 23
Quote:
Originally Posted by codegenie View Post
I am sorry all. I just found out

ulimit -S -v mem-in-kbytes


Thanks all i guess ulimit is what i wanted.
What confused me about ulimit's functionality is this page.
Hi codegenie,

You got my interested and have me a bit confused now. ulimit is used to define limits not actually allocate resources. I thought your question was about pre-allocating memory to a program.

ulimit will limit the maximum amount memory that a process can consume, but it does not allocate to a process nor does it guarantee that the memory will be available.

I'm not sure if the problem as I first read it can be accomplished, but I'm guessing it it can be done, it would not be trivial.

-z1p
 
Old 01-27-2011, 12:53 PM   #10
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,142

Rep: Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127
Quote:
Originally Posted by codegenie View Post
I went to an interview last week and there was this guy who asked a simple question that i have been trying to solve for a couple of days. I tried google but i just cant get the search keywords right. The result were just useless. Well, the question is :

"How can we allocate a limited memory to a process before we start its execution"

well, the question is related to an X11 system so may be some flags must be set to limit its memory.
I think the interviewer thought he knew things about this topic that he didn't actually understand.

Whatever he thought was the right answer, is almost certainly wrong. If he understood the topic well enough to know the correct answer himself, he would not have asked the question at all. There are too many obscure twists to any correct answer to make this a useful interview question.

None of that would have helped you in the interview. I probably would have asked for a bunch of clarifications about what he meant (which strategy probably wouldn't have done me much good in an interview either). Interviewers sometimes ask stupid questions, which tend to mislead them about the qualifications of the applicants. Usually the results have no significant correlation with finding the actual best employee from the pool of applicants. I hope I do better when I interview to find someone to fill the current opening in my own group.

BTW, regarding the whole allocate vs. limit question: The thread title certainly puts the focus on allocate, but I expect the original interviewer meant to focus on "limit". Very likely, the wrong answer he thought was right and was looking for, was some simple use of ulimit.

Last edited by johnsfine; 01-27-2011 at 12:57 PM.
 
  


Reply


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
Cannot allocate memory simha Linux - Newbie 4 01-23-2008 10:19 AM
Cannot allocate memory Terroth Linux - General 13 02-09-2005 06:22 AM
Key bindings program (custom pasting, program execution, etc.) jrdioko Linux - Software 2 02-05-2005 10:09 PM
allocate more memory? sockknitter Debian 3 11-06-2004 06:23 PM
Error: cannot allocate memory ion111 Linux - Software 7 07-04-2004 07:33 AM


All times are GMT -5. The time now is 10:13 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration