- Sometimes you want to start a process and forget about it. If you start it from the command line, like this:
- you can’t close the terminal, or it will kill the process. Can you run a command in such a way that you can close the terminal without killing the process?
- close a terminal without killing the command running in it
- One of the following 2 should work:
OR
- If your program is already running you can pause it with Ctrl-Z, pull it into the background with bg and then disown it, like this:
- The reason that the process is killed on termination of the terminal is that the process you start is a child process of the terminal. Once you close the terminal, this will kill these child processes as well.
- You can see the process tree with pstree, for example when running kate & in Konsole:
- To make the kate process detached from konsole when you terminate konsole, use nohup with the command, like this:
- After closing konsole, pstree will look like this:
- and kate will survive.
- An alternative is using screen/tmux/byobu, which will keep the shell running, independent of the terminal.
- You can run the process like this in the terminal
- This will run the program in a new session
- use a variant on screen,the command like this
- The session can be disconnected with Ctrl A Ctrl D and reconnected in the simple case with screen -r. you have this wrapped in a script called session that lives in my PATH ready for convenient access:
- This only works when you know in advance you want to disconnect a program. It does not provide for an already running program to be disconnected.
- prefer:(applicationName &)
Example:
[ad type=”banner”]- Make sure to use parenthesis when type the command!
- You can set a process (PID) to not receive a HUP signal upon logging out and closing the terminal session.
- Use the following command: