Bash:在后台运行可执行文件 [英] Bash: run an executable file in background

查看:121
本文介绍了Bash:在后台运行可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含长循环的可执行文件,因此我想在后台运行它,如何在Linux中使用bash脚本来做到这一点?

I have an executable file that contains a long loop, so I want to run it in background, how do I do that with bash script in Linux?

我知道一种方法是 Ctrl + z,然后键入bg,如何在bash脚本中模拟这些按键?

I know one way is Ctrl + z, then I type bg, how to simulate these key pressing in bash script?

推荐答案

Linux中的任何可执行文件都可以在后台运行,如下所示:

Any executable in linux can be run in the background as follows:

 $ ./yourExecutable.exe&

在末尾添加&字符. (假设yourExecutable.exe在当前工作目录中)

Add the & character at end. (Assuming yourExecutable.exe is in the current working directory)

$ ps -ax | grep yourExecutable.exe

您将获得类似以下的输出:

You will get an output like:

9384  pts/7    S+     0:00 grep yourExecutable.exe
25082 pts/7    T      0:00 yourExecutable.exe&

使用SIGKILL杀死第二个进程.那就是您在后台执行的那个.

Kill the second process using SIGKILL. That is the one you executed in the background.

$ kill -9 25082

这篇关于Bash:在后台运行可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆