How to send commands / processes to the background

Many times when we work in a terminal we want to execute a command but then to be able to close the terminal and that what we execute is NOT closed, for example, execute a script in the terminal and then close the terminal but that the script continues to run ... how to achieve this?

To achieve this we simply have to put an & at the end of the line, for example, we have a script called wifi-log.sh and to run it and keep it in the background it would be:

./wifi-log.sh &

See here a screenshot:

command-in-background

Here we see clearly that after we execute the above line nothing else appears, except [1] 29675 What does this mean?

29675 is the PID (process number) of the script that we execute, that is, if we want to kill the script and stop executing it, we simply put:

kill 29675

And voila, it stopped running.

I mean and in summary, to send a process (command, several commands or script) to the background (or background) we must put at the end of the line & and then press Enter

This is not something new, far from it but… it is always good to be clear, also, this post will serve me for another one that I will publish shortly.


Add as preferred source in Google