This blog is subject the DISCLAIMER below.

Wednesday, February 21, 2007

Linux Shell Tip #2

In the previous post, I mentioned a case when you have run a program through the shell and you want to close the shell without closing your program.

So before you close the shell, you may notice that you can't type any other command untill you close the running program.

What if you need to use the shell for another purpose?

This is when you need to place an ampersand "&" at the end of the command. so for the gedit example i have mentioned before, the command would be like this:

gedit &

The ampersand (&) placed at the end of the command starts the process as a background process which means that this process will not capture your keyboard input in the shell, so you can use the shell for typing any other commands.

Remember that if u close the shell the programs you have run will close. To overcome this situation you will need to use nohup in association with the "&". So if you want to run gedit the command will:

nohup gedit &

and the general form of it would be:

nohup "your command" &

Now you can:

# Use the shell for any purpose after running the programs you want.
# Close the shell without disrupting the operation of the programs you have run.

1 comment:

Mohammad Alaggan said...

If one forgot to add & he can do this :
Ctrl+Z to suspend the job, then enter the command "bg" to move that job to work in the background.