Have you ever needed to run a command in background on Linux? Execute something that would stay there, no matter what, and that you would be free, without having to leave your machine logged with an open session? I needed that once, and I’ll share how to do it…

To run something in background on Linux, you just need to add & at the end of your command, as I show below:

A practical example would be this one:

If you need to bring that command back to foreground, you just have to use one of these two alternatives:

Simple right? But wait… What is this job id? It’s the process number that was given to your command by being run, and to see it, just type:

The output of the command will be something like the image below:

But attention, cause if you disconnect from the session that you used to issue the command in background, and open another session, the jobs will not work as expected, and you will have to use another command:

The output will be something like the image below:

Exemplo de uso do ps

Ok, now you have everything you need to know… Have a nice job!

Reference: http://www.cyberciti.biz/faq/linux-command-line-run-in-background/

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.