`ulimit -e` 和 `renice` 之间的区别?

qua*_*nta 5 process ionice limit nice ulimit

我想以低 CPU 和磁盘 I/O 运行备份脚本。

这有什么不同吗:

#!/bin/bash

ulimit -e 19
ionice -c3 -p $$
Run Code Online (Sandbox Code Playgroud)

和这个:

#!/bin/bash

ionice -c3 -p $$
renice -n 19 -p $$
Run Code Online (Sandbox Code Playgroud)

cuo*_*glm 7

There is big difference between them.

  • ulimit -e only set the RLIMIT_NICE, which is a upper bound value to which the process's nice value can be set using setpriority or nice.

  • renice alters the priority of running process.

Doing strace:

$ cat test.sh
#!/bin/bash

ulimit -e 19
Run Code Online (Sandbox Code Playgroud)

Then:

$ strace ./test.sh
...................................................
read(255, "#!/bin/bash\n\nulimit -e 19\n", 26) = 26
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
getrlimit(RLIMIT_NICE, {rlim_cur=0, rlim_max=0}) = 0
getrlimit(RLIMIT_NICE, {rlim_cur=0, rlim_max=0}) = 0
setrlimit(RLIMIT_NICE, {rlim_cur=19, rlim_max=19}) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
read(255, "", 26)                       = 0
exit_group(0)
Run Code Online (Sandbox Code Playgroud)

You can see, ulimit only call setrlimit syscall to change the value of RLIMIT_NICE, nothing more.

Note