Xuan Tung Vu Xuan Tung Vu - 1 year ago 50
Python Question

Why doesn't ulimit -t kill a process sleeping beyond the limit with time.sleep?

I am trying to limit the CPU usage of one python script using

ulimit -t
. The script contains one
statement and it is not killed after the specified time limit. Here is the simplified python script named

import time

while True:

and I run the command as following:

ulimit -v 400000; ulimit -t 30; python test.py

The script keeps running forever. Are there any explanations for this? Thanks.

Answer Source

ulimit -t sets the CPU time limit. While your program is sleeping it doesn't use any CPU time, so that time doesn't count. It will only occupy a few CPU cycles to go to sleep again, that's why it's not killed.

You can't specify a real time limit using ulimit.