Suspending and putting a running process in the background in Linux
How many times does it happen to you where you have spun up a node server or a PHP server in your terminal and then you want to put it in the background so that you can do something else?
For instance, you want to run a git pull
command or you want to run a composer install
command without opening a new terminal window.
Well, if you are using Linux (or Unix), you can do that using the Ctrl / Cmd + Z shortcut. This will suspend the process and you can use the terminal for other purposes.
Here’s what this might look like.
As you can tell, the process created by the php artisan serve
command has been suspended and it’s not running anymore. You can verify this by running the jobs
command where you will see the suspended job.
So now, you can run any other command you want and when you’re done, you can put the suspended job to the background using the bg
command like so and it will resume the job.
Once you put the job in the background, you will still be able to run other commands and the job will continue to run in the background. You can verify this by running the jobs
command again.
But if you want to bring the job back to the foreground like how it was initially, you can do so using the fg
command like so.
And this will bring the job back to the foreground.
Like this article?
Buy me a coffee👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.