Sometimes we would find that once we open a shell, and run some processes, then close our shell, those running processes would be closed by os.
It's a trouble if we want to run a service, so let's solve it.
At first, we should find the reason why our processes will be closed at the same time when we close our shell. Once we open a shell, it represents a process, and all the processes we created by the shell will be the jobs of our shell, and listed in our jobs table. If we try to close a session, session will sent HUG signal to all the jobs, and jobs will be closed if they receive HUG signal. So it's the reason why our subprocesses are closed.
There are several way to avoid our subprocess to receive the HUG signal. I will introduce the usage of disown, a command to protect a process from receiving HUG signal.
For example, if we call command top.
Then we press
ctrl-z to suspend the current running process.(ctrl-z could suspend a process, and
fg could put the suspended process to front.)
jobs will show all the jobs and their status in background. Remember the number of jobs, for example:
+ Stopped top
top's job number is 1.
Then we call bg to continue top as a background job.
If you want to switch the top as fronted job, you could call
Then let's understand disown. disown could remove the target job from job table, and once the session is closed, the session will not send HUG signal to those removed jobs.
disown 1 #remove job 1 from job list