运行 通过终端在 Raspberry pi 中同时执行多个 cmdline 命令或文件

running multiple cmdline commands or files simultaneously in Raspberry pi through terminal

我创建了一个文件,其中 运行 是一个烧瓶服务器,启动 Alexa 示例应用程序,另一个是 运行 端口转发服务器的 cmdline 命令。

它们是:

led.py, sudo bash startsampleapp.sh 命令为:autossh -M 0 -R 80:localhost:8000 serveo.net

所以我想 运行 来自一个文件的所有这三个我尝试使用子进程、多处理和 os 但似乎没有用它不会领先于 led.py.这 3 应该同时 运行 因为要启动 Alexa 我需要通过此命令 运行 Alexa 示例应用程序:"sudo bash startsampleapp.sh" 当我们要求 Alexa 做某事时 serveo.net 将得到请求并将其转发到 led.py(flask 服务器)。所以请帮助我解决这个问题。

我试过像这样创建 bash 文件:

#!usr/bin/bash

python led.py &
sudo bash startsampleapp.sh &
autossh -M 0 -R serveo.serveo.net:localhost:8000 serveo.net

它应该在并行进程中启动它们,但不起作用。

我找到的解决方案是分别打开 3 个终端和 运行 那 3 个东西。

我创建了一个 bash 文件 main.sh,其中包含:

#!/bin/bash

lxterminal -e python led.py &
lxterminal -e autossh -M 0 -R serveo.serveo.net:80:localhost:8000 serveo.net &
lxterminal -e sudo bash startsampleapp.sh

谢谢大家

可以通过获取进程 ID 并使用 sudo killall -9 ID 命令来杀死它们。