LinuxQuestions.org
Help answer threads with 0 replies.
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 12-30-2020, 04:23 AM   #1
postcd
Member
 
Registered: Oct 2013
Posts: 527

Rep: Reputation: Disabled
prlimit including childs?


Hello,
i was searching for the way to limit the memory the python script and its childs can use. (in my case it would be 5GB).

The script is launched ./script.sh which contains various conditions and one of it launch the py script:
runtime/bin/python3 "$SCRIPT_DIR/$SCRIPT" --dist_type bundle_linux64 "$@"

First i tried:

prlimit --verbose --memlock=100 ./script.sh
New MEMLOCK limit for pid 1449761: <100:100>

obviously it does nothing:
Code:
me     1449761  0.0  0.0   9720  3344 pts/0    S+   10:57   0:00 /bin/bash ./script.sh
the resulting .py process that eats 3GB of memory already looks like:
Code:
me     1449763 61.0  7.0 3447140 1149744 pts/0 Dl+  10:57   9:55 runtime/bin/python3 /home/me/apps/appname/core/start.py --dist_type bundle_linux64
So i am guessing i would have to edit that command inside bash script to something like:
Code:
prlimit --verbose --memlock=5000000 runtime/bin/python3 "$SCRIPT_DIR/$SCRIPT" --dist_type bundle_linux64 "$@"
The prlimit has also other parameters per its manual page:

Quote:
-l, --memlock[=limits]
Maximum locked-in-memory address space

-v, --as[=limits]
Address space limit.
which prlimit command you would suggest for around 5GB memory limiting? Or you would suggest other command to control it? I am OK with the script exceeding such memory be killed (know about data loss/damage possibility).

PS: some people also use this script to kill process when it use too much memory: https://github.com/pshved/timeout , my recent attempt with it looks like:
Code:
cd /home/me/apps/appname/
wget https://raw.githubusercontent.com/pshved/timeout/master/timeout;chmod +x timeout
./timeout -m 5000000 ./script.sh
After a few days of runtime i did Ctrl+C and see:
SIGNAL CPU 31130.78 MEM 3533244 MAXMEM 4987268 STALE 40537 MAXMEM_RSS 1970184
(process managers shown the process memory usage under 5GB)

Last edited by postcd; 01-02-2021 at 06:58 AM.
 
Old 12-30-2020, 05:31 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Hi

I don't think you want --memlock, try -as instead.

In bash, there's a builtin ulimit command. The -v option is for address space (memory used), and the number is kilobytes. Setting it will prevent any children using more memory than the limit. The limit lasts until the script is finished. Try this:

Code:
ulimit -v $((5*1024*1024))
runtime/bin/python3 ...
 
1 members found this post helpful.
  


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
[SOLVED] waiting for multiple childs - C - waitpid wakatana Programming 7 03-01-2011 03:38 PM
Suidical Childs in Perl KneeLess Programming 6 06-13-2004 06:22 PM
Apache 2.0.47 childs segfault markus1982 Linux - Networking 3 10-20-2003 01:52 PM
why can not fork new childs? nenejung Programming 2 08-05-2003 12:58 PM
why can not fork new childs? nenejung Programming 2 07-30-2003 05:13 AM

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

All times are GMT -5. The time now is 08:19 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
Open Source Consulting | Domain Registration