9 Comments

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 these ads

About Gen2ly

<3's linux

9 comments on “Background a Process/Program

  1. Hi Dirk,

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

    Cheers,
    Patrick.

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

  3. > 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). :)

  4. Guess I’m too late…

  5. 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?

  6. 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:

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

Join 51 other followers

%d bloggers like this: