How to detach a process from terminal's shell?

Usually using & at the end of a command (like command &) is enough to send a process to the background but this does not detach the process from its parent; to detach a process completely from its parent (like the terminal’s shell) a combination of & and disown can be used, example with gedit:

gedit &
disown

Additionally if the terminal session is meant to be used afterward the command can be silenced with command &>/dev/null to avoid any output from the launched application while using the terminal for something else, this is especially useful if we are willing to use a TUI application (text-based user interface) afterward, like a text editor (nano, vim or micro).

Alternative 1:

nohup cmd &

Alternative 2:

screen -S <session name> -d -m <your command>

With screen the child process can be reattach as well with screen -r <session name> (additional info are available on this QA)

Alternative 3:

kstart5 from KDE, available in the package kde-cli-tools can help

kstart5 my-command &

We can as well manage multiple aspect of an x window if we are running a gui

Bonus: replacing the parent process with the child:

This can be achieved with exec example:

exec command;

Share this post on:

Related posts:

Using a different network interface for a specific application
Recover deleted files and undoing an rm * -rf command