1

I tried using ^Z to send and application to the background(to then use fg to restore) but I notice that it says "Stopped" and in another terminal while monitoring htop, everything just freezes.

Is there a way I can send to background without stopping/suspending the process?

3
  • Ctrl-Z sends SIGSTOP to the application. I'm afraid that there is no other way to send an application into background. Commented Apr 10, 2014 at 4:02
  • @devnull kill -s SIGSTOP from another terminal? Commented Apr 10, 2014 at 9:42
  • @Graeme I'm not sure what you mean, but if you have the PID of the process in question then you could say kill -STOP <PID> from another terminal. Commented Apr 10, 2014 at 10:00

1 Answer 1

3

Executing a background job

Appending an ampersand ( & ) to the command runs the job in the background.

For example, when you execute a find command that might take a lot time to execute, you can put it in the background as shown below. Following example finds all the files under root file system that changed within the last 24 hours.

find / -ctime -1 > /tmp/changed-file-list.txt & 

Sending the current foreground job to the background using CTRL-Z and bg command

You can send an already running foreground job to background as explained below:

Press CTRL+Z which will suspend the current foreground job. Execute bg to make that command to execute in background. For example, if you’ve forgot to execute a job in a background, you don’t need to kill the current job and start a new background job. Instead, suspend the current job and put it in the background as shown below.

find / -ctime -1 > /tmp/changed-file-list.txt [CTRL-Z] [2]+ Stopped find / -ctime -1 > /tmp/changed-file-list.txt bg 

View all the background jobs using jobs command

You can list out the background jobs with the command jobs. Sample output of jobs command is

jobs [1] Running bash download-file.sh & [2]- Running evolution & [3]+ Done nautilus . 

Taking a job from the background to the foreground using fg command

You can bring a background job to the foreground using fg command. When executed without arguments, it will take the most recent background job to the foreground.

fg

If you have multiple background jobs, and would want to bring a certain job to the foreground, execute jobs command which will show the job id and command.

In the following example, fg %1 will bring the job#1 (i.e download-file.sh) to the foreground.

jobs [1] Running bash download-file.sh & [2]- Running evolution & [3]+ Done nautilus . # fg %1 

Kill a specific background job using kill %

If you want to kill a specific background job use, kill %job-number. For example, to kill the job 2 use

kill %2 

All the above contents are taken from this link.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.