Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

do I need to use nohup and & together

Tags:

linux

shell

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?

like image 809
Jack Avatar asked Dec 11 '22 10:12

Jack


1 Answers

nohup 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 nohup, one also wants the process to be in the background, that's why you see the combination of nohup and & more often than not.

like image 101
pfnuesel Avatar answered Dec 15 '22 01:12

pfnuesel