Job Control Commands: fg, bg and ctrl-z

September 16th, 2014

Warning: This post is 10 years old. Some of this information may be out of date.

I have a script polling a Beanstalkd queue and needed to put it into the background, and bring it to the front whilst debugging it.

I use screen to run the job in a virtual terminal and run the command and send it to the background with '&':

    php worker.php &

This will start the script and push it to the background.

To get the process back, simply run the fg command:

    $ fg
    php worker.php

The problem is that I can't now send the process to the background again with the fg command. Instead you can use ctrl-z (control + z) to send it to the background. The first time you ctrl-z it will suspend the process. Hit bg again to push it to the background and resume it.