如何在Bash中超时复杂过程?(与自己的儿童处理过程)
此处上下文中的过程是“ Android构建环境”。 但是,要超时正常任务
#Timeout command 'do_task' in 10 seconds
timeout 10s do_task
,当我在Android构建环境中尝试相同的操作时,它似乎不起作用。 相反,这就是发生的事情:
box@boxputer:/media/box/backup/cr81x$ source build/envsetup.sh
box@boxputer:/media/box/backup/cr81x$ lunch aosp_arm-eng
Trying dependencies-only mode on a non-existing device tree?
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=12
TARGET_DEVICE=generic
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.13.0-44-generic-x86_64-Zorin-OS-16.1
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=SQ3A.220605.009.A1
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/EmulatedCamera device/generic/goldfish device/generic/goldfish-opengl
============================================
box@boxputer:/media/box/backup/cr81x$ timeout 10s mka bacon
timeout: failed to run command ‘mka’: No such file or directory
在这里,“ MKA培根”是构建命令,“ make”或“ m”,但它们都会导致与上述相同的错误。
我还尝试的
# Spawn a child process:
(dosmth) & pid=$!
# in the background, sleep for 10 secs then kill that process
(sleep 10 && kill -9 $pid) &
( cmdpid=$BASHPID;
(sleep 10; kill $cmdpid) \
& while ! ping -w 1 www.goooooogle.com
do
echo crap;
done )
内容还包括此特定的stackoverflow线程。
我还尝试了在a 相关线程
时, ,它引入了一个自己的问题(下面的代码),
mka bacon &
sleep 10s
但是,这确保了该过程直到10秒通过。 说我在5秒内完成了构建。该过程仍然不会退出。它直到10秒才退出,这不是一个构建产生错误时的理想情况。
当我尝试从的其他答案时这个特定的stackoverflow线程,该过程在10秒后终止,但是整个终端故障,构建仍然运行(在此阶段,即使CTRL+C也无法正常工作) 我的猜测是,构建环境通过不同的PID催生了自己的儿童过程?
如果您想知道什么是envsetup.sh,这是它的糊状
The process in context here is 'android build environment'.
To timeout normal tasks, one would do
#Timeout command 'do_task' in 10 seconds
timeout 10s do_task
However, when I try the same with android build environment, it doesn't seem to work.
This is what happens instead:
box@boxputer:/media/box/backup/cr81x$ source build/envsetup.sh
box@boxputer:/media/box/backup/cr81x$ lunch aosp_arm-eng
Trying dependencies-only mode on a non-existing device tree?
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=12
TARGET_DEVICE=generic
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.13.0-44-generic-x86_64-Zorin-OS-16.1
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=SQ3A.220605.009.A1
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/EmulatedCamera device/generic/goldfish device/generic/goldfish-opengl
============================================
box@boxputer:/media/box/backup/cr81x$ timeout 10s mka bacon
timeout: failed to run command ‘mka’: No such file or directory
Here, 'mka bacon' is the build command, 'make' or 'm' could also be used, but they all result in the same error as mentioned above.
What I've tried additionally includes
# Spawn a child process:
(dosmth) & pid=$!
# in the background, sleep for 10 secs then kill that process
(sleep 10 && kill -9 $pid) &
( cmdpid=$BASHPID;
(sleep 10; kill $cmdpid) \
& while ! ping -w 1 www.goooooogle.com
do
echo crap;
done )
and other answers from This Particular Stackoverflow thread.
I've also tried another solution on a related thread
while one gave me success, it introduced a problem of its own(code below)
mka bacon &
sleep 10s
This however ensures that the process isn't terminated until 10 seconds have passed.
Say I finish the build in 5 seconds. The process still won't exit. It won't exit till 10 seconds have passed, which isn't a desirable situation when a build produces an error.
And when I try the other answers from This Particular Stackoverflow thread, The process terminates after 10 seconds, but the entire terminal glitches, and the build still runs(at this stage even Ctrl+C doesn't work)
My guess is that the build environment spawns its own child-processes with different PID's for the build?
If incase you're wondering what envsetup.sh is, Here's its paste
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
超时需要二进制执行。
根据您的提示
,我认为MKA只是一个别名或功能。您可以找出
键入MKA
的方法。当您找到它时,将其用作超时的参数。
Timeout needs a binary to execute.
Based on your hint
I assume, that mka is just an alias or function. You can find out, what it is and does with
type mka
.When you found it, use that instead as arguments for timeout.