Friday, April 26, 2024
35
rated 0 times [  35] [ 0]  / answers: 1 / hits: 4025  / 2 Years ago, tue, september 6, 2022, 9:11:17

I am a newbie in Ubuntu. I have learned a command



nohup [command] - run <command> immune to hangup signal



I can't understand the meaning of "immune to hangup signal". What type of signal it is talking about? And please tell me how to use this command with an example.


More From » command-line

 Answers
1

Let us consider you have opened a gedit text editor from a terminal and working on it. If you close the terminal before closing gedit, the gedit also gets closed as soon as closing the terminal. So what is going on here? The gedit runs as a child process under the terminal. When you close the terminal a hang up signal (SIGHUP) is sent to the process which kills the child process.



On the other hand if you want your child process (here gedit) to keep on running even after closing the parent terminal, you would want your process immune to hangup signal. So that closing the terminal do not close the child process. nohup does exactly this job.



nohup does not disconnect a command from terminal, it makes your script ignore SIGHUP, and redirects stdout/stderr to a file nohup.out, so that the command can continue running in the background after you log out. If you close the shell/terminal or log off, your command is no longer a child of that shell. It belongs to init process. If you search in pstree you'll see it is now owned by process 1 (init). That cannot be brought back to the foreground because the foreground no longer exists.


[#9286] Thursday, September 8, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cupwire

Total Points: 365
Total Questions: 126
Total Answers: 125

Location: Malaysia
Member since Thu, Feb 16, 2023
1 Year ago
;