1

I run several python script on a linux server with lots of RAM and CPU cores. How could I specify a maximum number of RAM and a maximum number of CPU cores for each of them ? I could use linux bash scripts or python code to achieve this.

1 Answer 1

10

You can use Linux command nice to choose the priority that you want on your process.

nice -n 10 python yourScript.py

Positive number gives less priority to the process.

-20 is the most favorable to the process and 19 is the least favorable to the process.

This will avoid to have a process consuming all your CPU when other process need it.

For the RAM you can use the command ulimit which allow to limit resources.

Limit the RAM to 1GB (1000000 number is in kB)
ulimit -m 1000000 && python yourScript.py

You can check actual limit in your shell with option -a.

Sign up to request clarification or add additional context in comments.

1 Comment

use -v instead of -m flag. check link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.