1

when executing a command with nohup , is that necessary to execute it in background.

If the only thing required is that the command should not hang when closed the terminal, then what is the differnce in ( nohup command & ) and ( nohup command ) ?

Both of the above statements achive this.

2 Answers 2

1

Yes, it's necessary that you execute it in the background, if you wish for the shell to be able to exit.

1
  • In an X window environment, you can close the terminal emulator. That is, just close the terminal window, which sends a HUP signal to all connected programs. You need nohup to ignore this signal.
    – raimue
    Commented Sep 22, 2011 at 18:26
0

The & at the end indicates that the command should be running in the background. That means, you can continue to enter commands into the shell.

For your particular question, it does not make any difference as it seems you want to close the terminal window right afterwards anyway.

3
  • 1
    Not true. (nohup command), if you start it in a terminal window and close it after the execution starts, will be killed. Do this in a window and close it: (nohup sh -c "echo before; sleep 10; echo after") you will never see the "after" output in the file.
    – e40
    Commented Sep 22, 2011 at 20:46
  • Actually, I do see "after" in the nohup.out file and that is exactly what I expected. If it would be as you say, the nohup command would be completely useless. Maybe your terminal emulator is faulty and sends some other signal? What else would kill it as you say? Test this with xterm if you do not believe me.
    – raimue
    Commented Sep 23, 2011 at 8:05
  • yes, i suppose Raim is correct because i also executed the command with nohup but not in background. I got what was expected. The command was executing even after closing the terminal window
    – mandeep
    Commented Sep 23, 2011 at 13:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.