... because from time to time I'm a web developer, too
About me
Projects
Contact
Links

Background processes in linux

October 19, 2009 | linux
author: Karol Zielinski | comments: 0 | views: 524
Tags: , , ,

Why to add process to background? How to do it, while executing script and when it is already running? Just a few quick examples.

Why to add process to background?

Because of two reasons:

  1. thanks to that we don’t need to open new console, log in again, etc
  2. thanks to that we protect ourself against the ‘Connection reset by peer’ – if some scripts are slow or long-running

Lets have a look at the some examples of background processes

First of all…

we will put our script to the background, while starting it:

./run_our_script.sh &

and check it:

ps -aux

our script should be there.
Easy, isn’t it?

now…
we will put our script to the background, while it is already running in ‘normal mode’:

Press ctrl+z to stop the current job (Yes, you can stop it! Don’t worry.).

and…

jobs

The above command will display the jobs in the shell. Something like:

[1]   Stopped                 one_app
[2]-  Stopped                 two_app
[3]+  Stopped                three_app

Ok, now we want to run ‘two_app’. In such way we can start running the specific background process. So…

bg 2

and check it…

jobs

The above command will display something like:

[1]   Stopped                 one_app
[2]   Running                 two_app
[3]+  Stopped                three_app

That means that everything is ok.
You can check it by “ps -aux”, as well.

Now… if we want to take out our script from the background

jobs

the result:

[1]   Stopped                 one_app
[2]   Running                 two_app
[3]+  Stopped                three_app

So, we just need to put:

fg 2

And everything should be fine. Our script is not in the background any more.

Bookmark and Share
Post Background processes in linux to develway Post Background processes in linux to Delicious Post Background processes in linux to Digg Post Background processes in linux to Facebook Post Background processes in linux to Reddit Post Background processes in linux to StumbleUpon

Related news and resources

Write a comment

Karol Zielinski :: Just a tech stuff Hello, I'm Karol Zielinski, internet evangelist, an entrepreneur, project manager and a web developer from Gdynia, Poland. I like creative design, good advertisement, social media and all kind of stuff around the web.

Most popular posts

Much more links

Karol Zielinski    |   contact me
Gdynia, Poland
RSS - Just a tech stuff - python, java blog - web development blog Karol Zielinski on twitter Karol Zielinski on LinkedIn Karol Zielinski on facebook Karol Zielinski on delicious Karol Zielinski on digg Karol Zielinski on flickr Karol Zielinski on stumbleupon Karol Zielinski on technorati