Background a Process/Program

At times it is useful to see the output of what a program produces by typing its command line name in the terminal (for instance for debugging), at other times typing a program in the terminal just takes up space that could ordinarily be utilized for something else. Launching programs from the terminal can be put in the background easily with a bash script.

nohup is used to prevent hangups and then you redirect the output of the command to /dev/null (the great Linux blackhole). Here’s the script:

Then in the terminal use the bgcmd command with whatever program needed to be put in the background:

Backgrounding Already Running Processes

Already running applications can be backgrounded as well. First type Ctrl + Z to release the application, then use bg to background it’s output.

Keep in mind though that if the terminal or tab is closed the program will close with it. Also too the bg command doesn’t suppress all output.

About Gen2ly

<3's linux

Posted on 2008-02-01, in Command Line, Linux, Script. Bookmark the permalink. 9 Comments.

  1. nice tip

  2. Hi Dirk,

    replace ‘$1’ (first parameter) with ‘$*’ (all parameters) and you can forget about the quoting ;)


  3. Thanks for the detail, I added it to the post.

  4. > Keep in mind any command that has a space will need put in parenthesis.

    You can get around this. Change your script to this:

    nohup $@ &> /dev/null &

    This will capture all the arguments given to backprocess ($@), not just the first one ($1). :)

  5. Guess I’m too late…

  6. Thanks!

  7. human mathematics

    Can you use bg to “sleep” processes, like if I have a lot of PDF’s open that I want to read “later” can I bg them to save memory?

  8. Hi would you mind letting me know which webhost you’re working with?
    I’ve loaded your blog in 3 different internet browsers and
    I must say this blog loads a lot faster then most.
    Can you suggest a good internet hosting provider at a honest price?
    Kudos, I appreciate it!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 58 other followers

%d bloggers like this: