nohup

nohup run a command immune to hangups, with output to a terminal

nohup preceeds the command to execute.

Ctrl-Z/fg/bg/&

A command can be run asynchronously with the suffix &. The interpreter then returns to the prompt and waits for a next command while the previous one still runs. The command is said to be in the background.

To put the command back to the foreground, the command fg must be used.

sleep 1
sleep 10 &
ps
fg

A running process (job) can be stopped with Ctrl-Z (=type the Control key then Z).

Then the prompt is back and the job is in stopped state.

Two choices are possible:

  • run in the background using the bg command

  • run in the foreground using the fg command

The job can also be killed using the command:

kill %

If several jobs are stopped or are running in the background, they can be referred to by numbers:

kill %2
fg %3