bash sudo nohup 不错 <-- 以什么顺序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/350381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sudo nohup nice <-- in what order?
提问by Jonah Braun
So I have a script that I want to run as root, without hangup and nicely. What order should I put the commands in?
所以我有一个脚本,我想以 root 身份运行,没有挂断,而且很好。我应该按什么顺序放置命令?
sudo nohup nice foo.bash &
sudo nohup 不错的 foo.bash &
or
或者
nohup nice sudo foo.bash &
nohup 好 sudo foo.bash &
etc.
等等。
I suspect it doesn't matter but would like some insight from those who reallyknow.
我怀疑这无关紧要,但希望真正了解的人有一些见解。
采纳答案by Felipe Alvarez
If negative niceness is desired, I would do: sudo nohup nice command because according to `info coreutils' nohup should preceednice. If I want a negative nice value, sudo must come before, since only root is able to use negative nice values.
如果负正派需要的话,我会做:须藤nohup这个漂亮的命令,因为根据'信息的coreutils'的nohup应该preceed不错。如果我想要一个负的 nice 值,sudo 必须在前面,因为只有 root 能够使用负的 nice 值。
If positive niceness is desired, I would do simply: nohup nice sudo command This ensures that nohup and nice are not run with root privileges.
如果需要积极的 niceness,我会简单地做: nohup nice sudo command 这确保 nohup 和 nice 不会以 root 权限运行。
回答by Adam Crume
sudo may not respect niceness. At least, it doesn't on my machine (Ubuntu 9.04). Running this:
sudo 可能不尊重善良。至少,它不在我的机器上(Ubuntu 9.04)。运行这个:
nice sudo nice
sudo nice nice
prints out 0 and 10. (Note that 'nice' with no command prints out the current niceness.)
打印出 0 和 10。(请注意,没有命令的 'nice' 打印出当前的好度。)
回答by Draemon
the sudo should go last so that nohup and nice aren't running with root privileges.
sudo 应该放在最后,这样 nohup 和 nice 就不会以 root 权限运行。
so the latter
所以后者
回答by Draemon
~ $ sudo nohup nice whoami
nohup: ignoring input and appending output to `nohup.out'
~ $ sudo cat nohup.out
root
The difference between the first and second way you've done it is who owns the nohup.out file. sudofirst will make it owned by root, nohupbefore sudo will make it owned by your user.
您完成的第一种和第二种方式之间的区别在于谁拥有 nohup.out 文件。sudo首先将其归root所有,nohup然后sudo将使其归您的用户所有。
回答by Partly Cloudy
Disagreewith other answers. I recommend:
不同意其他答案。我建议:
sudo nohup nice foo.sh
sudo nohup nice foo.sh
I have observed nohup sudo#fail-- ie nohup is not always transferred to sudo'd sub-sub-processes (this was for certain /etc/init.d scripts on Ubuntu which delegated to yet other scripts). Not sure why, certainly surprising, but was the case and took a good wee while to debug.
我观察到nohup sudo #fail——即 nohup 并不总是转移到 sudo 的子进程(这是针对 Ubuntu 上的某些 /etc/init.d 脚本,它委托给其他脚本)。不知道为什么,当然令人惊讶,但情况确实如此,并且花了很长时间进行调试。
(I note others report niceness not being passed through, so seems best to put it last ... although if in doubt on your OS put nice earlier, because nice not taking effect is usually less of a problem than nohup not taking effect!)
(我注意到其他人报告说 nice 没有通过,所以似乎最好把它放在最后......尽管如果你对你的操作系统有疑问,请早点把 nice,因为 nice 不生效通常比 nohup 不生效更重要!)
Note that sudo nohupleaves nohup.out owned by root, also as has been mentioned, but that's fixed with a:
请注意,sudo nohup将 nohup.out 保留给 root 拥有,正如已经提到的,但这已通过以下方式修复:
sudo nohup nice foo.sh >> /tmp/foo.stdout.log 2>> /tmp/foo.stderr.log
sudo nohup nice foo.sh >> /tmp/foo.stdout.log 2>> /tmp/foo.stderr.log
回答by mat
I guess all of them do an exec* syscall to pass the ball to the next one, so, whatever the order, it won't leave any hanging processes.
我猜他们所有人都执行 exec* 系统调用以将球传递给下一个,因此,无论顺序如何,都不会留下任何挂起的进程。
I'd say that nohup should be last so that the two other don't clober the signal handler. (I'm sure nice does not play with signals, but sudo does.)
我想说 nohup 应该放在最后,这样另外两个就不会破坏信号处理程序。(我确定 nice 不会处理信号,但 sudo 会。)
Then, sudo and nice, it all depends on which way you want to alter the scheduling priority with nice.
然后,sudo 和 nice,这一切都取决于您希望使用 nice 更改调度优先级的方式。
- If you want to raise the priority (that is, give a negative value to nice) do sudo before.
- If you want to lower the priority (give nice a positive value) do it before sudo, as you don't need root privileges.
- 如果您想提高优先级(即给 nice 一个负值),请先执行 sudo。
- 如果您想降低优先级(给 nice 一个正值),请在 sudo 之前进行,因为您不需要 root 权限。

