POSIX system(3) 调用异步 shell 命令会立即返回吗? [英] Will POSIX system(3) call to an asynchronous shell command return immediately?
本文介绍了POSIX system(3) 调用异步 shell 命令会立即返回吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,system("sh/mydir/some-script.sh &")
推荐答案
system("sh /mydir/some-script.sh &")
执行
/bin/sh -c 'sh /mydir/some-script.sh &'
system
将在外壳返回后立即返回,这将在启动内外壳后立即返回.两个 shell 都不会等待 some-script.sh
完成.
system
will return as soon as outer shell returns, which will be immediately after it launches the inner shell. Neither shell will wait for some-script.sh
to finish.
$ cat some-script.sh
sleep 1
echo foo
$ /bin/sh -c 'sh some-script.sh &' ; echo bar ; sleep 2
bar
foo
这篇关于POSIX system(3) 调用异步 shell 命令会立即返回吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文