&
$ foo &
nohup
$ nohup foo
What nohup does, on the other hand, is to effectively separate the process from the terminal:
It closes standard input (the program will not be able to read any input, even if it is run in the foreground. it is not halted, but will receive an error code or EOF).
It redirects standard output and standard error to the file nohup.out, so the program won't fail for writing to standard output if the terminal fails, so whatever the process writes is not lost.
It prevents the process from receiving a SIGHUP (thus the name).
Job Specification (jobspec)
The character % introduces a job specification (jobspec)
%n # Job number n
%string # prefix of the job name is "string"
(If a prefix matches more than one job, bash reports an error)
%?string # job containing the "string"
%% # refer to the shell's notion of the current job
Test
until ping -c1 $IP &>/dev/null; do echo "waiting"; done
Ctrl+C 係 stop 唔到佢 !!
Ctrl+Z # 出馬
^Z [1]+ Stopped ping -c1 $IP &> /dev/null
kill %%
[1]+ Stopped ping -c1 $IP &> /dev/null
jobs # 只有碡一次 jobs 才 show "Terminated"
[1]+ Terminated ping -c1 $IP &> /dev/null
disown
type disown
disown is a shell builtin
# remove "jobs -l"
disown
# Remove jobs from the table of active job.
disown jobID
# remove all jobs
disown -a
-h Mark each jobID so that SIGHUP is not sent to the job if the shell receives a SIGHUP.