Skip to content

Run a process in background on Linux

Simple background process

command &


top &

use jobs to see background PID

[1] 14814

Switch between foreground and background

Ctrl - Z

Process suspended, and return to the terminal

Check background process


Switch to background process

fg <job编号>

Let background process run in the background

bg <job编号>

Stop background process

kill %<job编号>

Run a background process and keep it running after logout

For example, a program that continuously outputs, as follows

while :
    echo hello
    sleep 1

hope to continue to execute after closing the terminal

nohup ./ &

The default program output is in the nohup.out file

Exit the terminal and log in again to check the process

ps aux | grep

杀死进程,使用kill + 进程号


yum install screen
apt install screen

Input screen, enter a new virtual terminal, and execute the task.

Detach the current screen

<Ctrl> + <A>, <D>

See all background terminals

screen -list

Resume the last closed terminal

screen -r

  1. License under CC BY-NC 4.0
  2. Copyright issue feedback, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try iOS App