gpt4 book ai didi

linux - 在 Bash 中将进程限制为 0.5 秒

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:14:59 25 4
gpt4 key购买 nike

如何在 Bash 中将进程的 CPU 时间限制在 1 秒以内?我使用的是版本 4.1.5(1),如果我输入 ulimit -t 0.5 command,我会得到:

-bash: ulimit: 0.5: invalid number

我正在使用 ulimit -t 1 command 作为不完美的替代品,但出于技术原因我不需要打扰你,我非常喜欢 command在它占用 CPU 半秒或更短时间后停止。

特定于 Linux 的答案就可以了。

最佳答案

也许你不能。底层系统调用 ( setrlimit ) 仅提供整秒分辨率。

 RLIMIT_CPU
CPU time limit in seconds. When the process reaches the soft
limit, it is sent a SIGXCPU signal. The default action for this
signal is to terminate the process. However, the signal can be
caught, and the handler can return control to the main program.
If the process continues to consume CPU time, it will be sent
SIGXCPU once per second until the hard limit is reached, at
which time it is sent SIGKILL.

关于linux - 在 Bash 中将进程限制为 0.5 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6189341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com