Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bring a background program to foreground

Tags:

linux

shell

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

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.

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.

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.

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

Thanks all!!

like image 710
nevesly Avatar asked Dec 31 '12 08:12

nevesly


People also ask

How do we bring background process to foreground?

We can reconnect a background job to our terminal with the Linux command fg. This command will bring job 2 into the foreground. If no job ID is given, fg will assume we're referring to the current (suspended) job.

How do I bring a background process to the foreground in Windows?

While hold Alt, tap Tab once and then mouse-click on the one you're interested in. It will come to the front.

Which command brings a background job into the foreground and foreground job to background?

You can use the jobs command to list the jobs that are currently running or suspended in the background. You can use the fg command to bring a background job to the foreground. Note: The foreground job occupies the shell until the job is completed, suspended, or stopped and placed into the background.


2 Answers

Use the jobs command 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
[1]  + Running                       ./temp.sh
[2]  - Running                       ./temp.sh
[3]    Running                       ./temp.sh
[4]    Running                       ./temp.sh

fg is the command to bring it back to the foreground as shown below.

>fg 1
[CTRL -c]

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

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

Also you can check here for more

like image 151
Vijay Avatar answered Nov 03 '22 23:11

Vijay


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

like image 27
m4t1t0 Avatar answered Nov 03 '22 23:11

m4t1t0