Backgrounding in the terminal

Unless you’re running something like tmux or screen, it can be annoying when you need to enter a command while you’re already running a program in your terminal you’re not ready to quit just yet.

If you’re using vim or nano for instance, you can send a signal to suspend the process, by pressing ctrl+Z. This sends the SIGSTOP signal, and immediately returns you to the command line. In there it will give you some information about the process you’ve suspended:

[1]+  Stopped                 vim

You can now do whatever you like in your terminal as usual. You can return to the suspended program as follows:

$ fg

If you have multiple suspended programs, use the number printed in the square brackets after suspending to identify which process you want to resume. If you don’t specify one, the most recently suspended one will be resumed.

$ fg 1 # Foreground a specific suspended program

Direct link to demo video