1

Suppose I run a process in the background likw ./script &, I can bring it to foreground by running fg.

However, is there a way to move it back to background without stopping it (as in ctrl+z) or opening a new session?

vpillai
  • 75

2 Answers2

2

What you are asking is not possible. You can however do the following

[usr@localhost:~]$ sleep 100 &
[1] 28542
[usr@localhost:~]$ fg
sleep 100
^Z
[1]+  Stopped                 sleep 100
[usr@localhost:~]$ bg
[1]+ sleep 100 &
[usr@localhost:~]$ jobs -l
[1]+ 28542 Running                 sleep 100 &

Another alternative is to use screen or tmux

  • problem with screen is that I need to decide before hand. This was the rare occasion where the bring back is unplanned :) – vpillai Aug 07 '14 at 14:57
2

This is not possible. I usually do CTRL-Z and %1& or bg 1 where '1' is the job number.

If you have a separate terminal and know the process id, you can do kill -20 500; kill -18 500 (if your process id is 500) to first suspend and then start in background.

Karel
  • 1,468