This blog is subject the DISCLAIMER below.

Sunday, February 18, 2007

Linux Shell Tip #1

As you use linux you will have to type commands into the shell. In this series of posts i am going to tell you how to overcome some annoyances when using the linux shell.

If you open gedit (a simple text editor) through the command line (by typing gedit) you will find that the terminal is still open. And if you close the terminal gedit will be closed too.

To override this behaviour you can type :
nohup gedit

This way if you close the terminal gedit will not be closed.

So what happens and how does nohup solve it??

When you run any program through the shell, this program is opened as a child process to the shell process. That means that the shell is a parent process to the program you have just run. So when you close the parent process(The shell in our case), a hangup signal is sent to the child process (Your program) which closes as a result.

nohup (means "no hangups") lets your program ignore those hangup signals, so that you can close the shell safely without mistakenly closing the program you have run.

Ofcourse, nohup is not constrained to gedit only. You can use it for any other program:
nohup "Your command"

4 comments:

Ahmed M. Farrag said...

heyyyy..... that's a useful piece of information... thanks

Charlie said...

I find it annoying that when I open some code in a text editor from the shell, I need another shell to compile it! Is there a command that allows you to continue to use the shell for other things while it is running a child operation?
Thanks

m-hewedy said...

@charlie
of course, just add ampersand after the cmd name, ex:
instead of typing;
% xmms
type :
% xmms &

if you forgot to add the "&" , so you should
1- press ctrl + z
2- then type bg (return) ( of course return means press the enter key )

bg here means put the last running process in the background.

Charlie said...

Great, that does the trick. Thanks a lot