GNU-screen alternative dtach

A GNU/screen can be sometimes to much of software for a specific purpose. For (de)taching terminal sessions there is a alternative tool called dtach. programs can be detached - run in the background - and then later reattached. dtach serves exactly for that one particular purpose. Running task while being AFK.

dtach has one big difference compared to running screen. The session naming syntax depends dtach using a UNIX socket. Socket connection name is automatically the dtach session name. Create a new dtach session. Naming the session is mandatory. No session name? No dtach session. It is as easy as that.

This is written in the dtach man file about sessions and Unix-domain sockets:

user % man dtach

... Sessions are represented by Unix-domain sockets in the filesystem. No other permission checking other than the filesystem access checks is performed. dtach creates a master process that monitors the session socket, the program, and any attached terminals. ...

In the example below, it is explained how to start /bin/bash using dtach. BASH is used in this example to distinguish between inside dtach and outside of it

This is the syntax of dtach:

dtach -c <socket> <options>

The -c session name is a UNIX socket, and calling -c is unconditional session creation.

user % dtach -c dtach-bash bash

A socket is created in the users home directory for the session per default if calling socket without absolute path.

read more