LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-19-2014, 02:14 PM   #1
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 401

Rep: Reputation: Disabled
Memory allocation for a command


Hi
How can I allocate (physical) memory to a command? For instance, if I want the 'cp' command to not to use memory more than 1 GB then how can I do it?
Regards
 
Old 11-19-2014, 02:41 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Someone is going to suggest ulimit, but i'd suggest:

You can use the timeout program for this.

https://github.com/pshved/timeout
 
Old 11-19-2014, 03:00 PM   #3
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 401

Original Poster
Rep: Reputation: Disabled
I have just tried your suggestion 'timeout'. However there is no confirmation that 'timeout' is actually allocating memory, as when I give memory 100 MB and when 1 GB, both times, 'ps aux' is showing that 'cp' is utilizing 7 percent memory.
 
Old 11-19-2014, 03:01 PM   #4
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
You can use ulimit to do this (just a wrapper for setrlimit). As an example:
Code:
(ulimit -d 10000 -m 10000 -v 10000; [command])
Make sure to run ulimit within its own script, or run it before cp/etc within its own function, as this is used to set global limits. The -d flag is your data segment size, -m is maximum memory size, and -v is max virtual memory size. Use ulimit -a to see what all can be set.

You can also use cgroups as well, see here for more information: https://www.kernel.org/doc/Documenta...ps/cgroups.txt

Ninja edit: Thanks to szboardstretcher for reminding me of timeout, almost forgot about that!

Last edited by corp769; 11-19-2014 at 03:03 PM.
 
Old 11-20-2014, 01:50 PM   #5
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 401

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by corp769 View Post
You can use ulimit to do this (just a wrapper for setrlimit). As an example:
Code:
(ulimit -d 10000 -m 10000 -v 10000; [command])
Make sure to run ulimit within its own script, or run it before cp/etc within its own function, as this is used to set global limits. The -d flag is your data segment size, -m is maximum memory size, and -v is max virtual memory size. Use ulimit -a to see what all can be set.

You can also use cgroups as well, see here for more information: https://www.kernel.org/doc/Documenta...ps/cgroups.txt

Ninja edit: Thanks to szboardstretcher for reminding me of timeout, almost forgot about that!
Thanks a lot
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Application Virtual address space memory allocation - memory does not get free chamara82 Linux - General 4 01-01-2011 08:19 PM
Memory allocation morfeus80 Linux - Newbie 5 01-28-2008 02:51 PM
memory allocation gecoool Programming 2 10-24-2005 09:47 AM
memory allocation docGonzo2000 Linux - General 1 05-16-2003 09:24 PM
memory allocation. raven Programming 5 09-08-2002 01:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:24 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