Background processes in linux
October 19, 2009 | linuxauthor: Karol Zielinski | comments: 0 | views: 1005
Tags: background, linux, process, script
Why to add process to background? How to do it, while executing script and when it is already running? Just a few quick examples.
Because of two reasons:
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.
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.