Jack
Jack

Reputation: 5890

do I need to use nohup and & together

I see a lot of people are using the following command:

nohup ./sendData.sh >logs/send.log 2>&1 &

Since the nohup has already been used, do I still need to add & on the trail?

Upvotes: 6

Views: 4432

Answers (1)

pfnuesel
pfnuesel

Reputation: 15340

tells the terminal to not hang up, even when the parent terminal is closed. & tells the terminal to send the process to the background. So

command &

will send the command to the background. You can then use the shell to invoke other commands. If the terminal is exited, the jobs are killed.

nohup command

will not send the command to the background, but when you close the terminal, the process will live on until it is finished or killed.

nohup command &

will send the command to the background and the process will not be killed even when you close the terminal. Usually when using , one also wants the process to be in the background, that's why you see the combination of and & more often than not.

Upvotes: 20

Related Questions