建立:
Ubuntu 12.04,32位; Scala 2.9.1; Java 1.6.0_24
Ubuntu 12.04,32位; Scala 2.9.1; Java 1.6.0_24
描述:
在bash命令行上,命令/usr/bin/timeout 10 scala -version工作正常,在bash脚本中执行时会卡住.
在命令行执行(持续时间<1秒):
user@ubuntu:~$/usr/bin/timeout 10 scala -version Scala code runner version 2.9.1 -- Copyright 2002-2011,LAMP/EPFL user@ubuntu:~$echo $? 1
放入bash脚本的命令卡住了:
testScript.sh:
#!/bin/bash /usr/bin/timeout 10 scala -version echo "finished with $?"
执行testScript.sh(持续时间10秒):
user@ubuntu:~/scripts$./testScript.sh Scala code runner version 2.9.1 -- Copyright 2002-2011,LAMP/EPFL finished with 124 user@ubuntu:~/scripts$
注意:问题不会出现在Java(Scala使用)中,它似乎是Scala特定的问题.
问题:为什么脚本中的超时调用被卡住了?
尝试包含–foreground选项.从男子超时:
原文链接:https://www.f2er.com/bash/383369.html–foreground
When not running timeout directly from a shell prompt,allow COMMAND to read from the TTY and receive TTY signals. In this mode,children of COMMAND will not be timed out.
使用以下测试脚本:
#!/bin/bash /usr/bin/timeout --foreground 10 scala -version echo "finished with $?"它似乎工作正常.
$./test.sh Scala code runner version 2.9.1 -- Copyright 2002-2011,LAMP/EPFL finished with 1没有–foreground脚本会像你所描述的那样挂起.