Linux 如何将后台程序带到前台

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14099343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:09:26  来源:igfitidea点击:

How to bring a background program to foreground

linuxshell

提问by nevesly

I am working on CentOS6, and running a django server for my development on a tmux session as:

我在 CentOS6 上工作,并在 tmux 会话上为我的开发运行一个 django 服务器:

python manage.py runserver 0.0.0.0:8000

python manage.py runserver 0.0.0.0:8000

So I can read my debug string print on it.

所以我可以读取我的调试字符串打印在它上面。

While there is an unknown reason which made my tmux session lost, and I cannot to bak to my working session using "tmux attach" command.

虽然有一个未知的原因导致我的 tmux 会话丢失,但我无法使用“tmux attach”命令进入我的工作会话。

I still can find my server is running by ps command, but I have no permission to kill this in order to run a new server on the same port.

我仍然可以发现我的服务器正在通过 ps 命令运行,但我无权杀死它以便在同一端口上运行新服务器。

So, I want to call this backgound server to frontgound again.

所以,我想再次调用这个后台服务器到前台。

As I never use ctrl+z or other ways to take process background, so even I use jobs command, there are no jobs.

由于我从不使用 ctrl+z 或其他方式获取进程后台,因此即使我使用作业命令,也没有作业。

But I dont know if I can do this, and how to do this...

但我不知道我是否可以做到这一点,以及如何做到这一点......

Thanks all!!

谢谢大家!!

回答by m4t1t0

You can use the command jobsto obtain a list of your jobs, then you can use fg <number of job>to bring that job to the front.

您可以使用该命令jobs来获取您的作业列表,然后您可以使用该命令fg <number of job>将该作业置于最前面。

回答by Vijay

Use the jobscommand to find the list of background processes that are started by you. for eg: there is script which simply sleeps for 10 secs in 5 iterations.I ran it 4 times in the background.

使用该jobs命令查找由您启动的后台进程列表。例如:有一个脚本在 5 次迭代中只休眠 10 秒。我在后台运行了 4 次。

>jobs
[1]  + Running                       ./temp.sh
[2]  - Running                       ./temp.sh
[3]    Running                       ./temp.sh
[4]    Running                       ./temp.sh

fgis the command to bring it back to the foreground as shown below.

fg是将其带回前台的命令,如下所示。

>fg 1
[CTRL -c]

as seen above i have ended the process and it no longer exists. now if i again run jobs

如上所示,我已经结束了这个过程,它不再存在。现在如果我再跑jobs

>jobs
[2]  + Running                       ./temp.sh
[3]    Running                       ./temp.sh
[4]  - Running                       ./temp.sh
>

Also you can check herefor more

你也可以在这里查看更多