Saturday, January 9, 2010

Running processes in background

While normal usage on linux, you may come across situations where you wish, what if we could run the process in background.

Like I use a script to login to use the internet. That script runs in the terminal, so what a normal user would do is open the terminal until he wants the script to keep running, which sometimes bugs a lot.

The better way is running s script in backgroud..
For ex, if the script name is myscript.py

$./myscript.py &
This will run the script in background. To see all programs running in background, type
$bg

To bring it to the foreground, type

$fg
So, problem solved...

But what if you forgot to append '&' and script has already started running. Now, if you wish to send the script to background, you will have to do two things. First, suspend the script to background and then make it run..
Below is the example for a script 'Cyberoam.py' with all the commands..

shadyabhi@shadyabhi-desktop:~$ ./Cyberoam.py
Enter your ID: 200801076
Password:
Login ATTEMPT at: 09-01-2010 -> 14:14:17
Next attempt after: 3500seconds
Message from CYBEROAM: You have successfully logged in
^Z
[1]+  Stopped                 ./Cyberoam.py
shadyabhi@shadyabhi-desktop:~$ bg
[1]+ ./Cyberoam.py &
shadyabhi@shadyabhi-desktop:~$ fg
./Cyberoam.py

2 comments:

  1. Amiable fill someone in on and this post helped me alot in my college assignement. Gratefulness you as your information.

    ReplyDelete
  2. Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.

    ReplyDelete