我有一个包含长循环的可执行文件,所以我想在后台运行它,如何在 Linux 中使用 bash 脚本执行此操作?
我知道一种方法是Ctrl+ z,然后我输入bg,如何在 bash 脚本中模拟这些按键?
linux中的任何可执行文件都可以在后台运行,如下所示:
$ ./yourExecutable.exe&
Run Code Online (Sandbox Code Playgroud)
&在末尾添加字符。(假设yourExecutable.exe在当前工作目录中)
$ ps -ax | grep yourExecutable.exe
Run Code Online (Sandbox Code Playgroud)
您将获得如下输出:
9384 pts/7 S+ 0:00 grep yourExecutable.exe
25082 pts/7 T 0:00 yourExecutable.exe&
Run Code Online (Sandbox Code Playgroud)
使用SIGKILL. 那就是你在后台执行的那个。
$ kill -9 25082
Run Code Online (Sandbox Code Playgroud)