在 CentOS 系统中,你可以使用 ulimit 命令来设置或查看用户进程的资源限制,包括 CPU 时间
要设置 CPU 时间限制,请按照以下步骤操作:
打开终端。
使用 ulimit 命令设置 CPU 时间限制。例如,如果你想将用户进程的 CPU 时间限制设置为 300 秒,可以使用以下命令:
ulimit -t 300 这将仅影响当前 shell 会话中的新进程。如果你想永久更改 CPU 时间限制,请执行以下步骤:
/etc/security/limits.conf 文件:sudo vi /etc/security/limits.conf <username>):<username> soft core 0 <username> hard core 0 <username> soft nproc <max_processes> <username> hard nproc <max_processes> <username> soft nofile <max_files> <username> hard nofile <max_files> <username> soft memlock unlimited <username> hard memlock unlimited <username> soft as unlimited <username> hard as unlimited <username> soft cpu 300 <username> hard cpu 300 将 <username> 替换为实际的用户名,将 <max_processes> 和 <max_files> 替换为你希望设置的相应限制。
保存并关闭文件。
重新登录以使更改生效。
现在,你已经成功设置了 CentOS 系统中用户的 CPU 时间限制。请注意,这些设置仅适用于普通用户。如果你需要为 root 用户设置限制,请使用 root 用户登录并重复上述步骤。