2010-06-19 57 views
6

我有两个脚本说'S1'和'S2'。我执行这些脚本的,顺序执行后台进程unix

nohup的S1 &

nohup的S2 &

但我想他们按顺序执行。即,S2应该只在成功完成S1时执行。我应该如何去做这件事?我如何知道S1何时执行完毕?任何例子将不胜感激。谢谢。

回答

9

您可以执行它们,顺序,就像这样:

(nohup S1 && nohup S2) & 

尝试

(echo 1 && sleep 1 && echo 2) & 

double ampersand operator is described here

请注意,当使用&&时,S2仅在S1完成“成功”(返回代码0)时才会运行。这似乎是你想要的。如果您想要S2运行,而不管S1是否成功,请使用;而不是&&

+0

非常感谢!我会检查一下。 – wowrt 2010-06-19 11:02:18

+0

你好,斯蒂芬!你能帮我解决这个问题吗?http://unix.stackexchange.com/questions/101411/how-to-run-new-background-command-sequentially-if-i-already-have-a-nohup-backgro/ 101421?noredirect = 1#comment154602_101421?我将非常感激。 – user15964 2013-11-17 02:51:58