dtach, a brilliant daemonizer

Most people use GNU screen (or equivalent) to daemonize processes. There is a better alternative called dtach which should become the definitive way to run a process in the background as a daemon.

Installing dtach is easy. If you’re on gentoo, it is a simple:

$ emerge dtach

dtach --help provides the following output:

Usage: dtach -a <socket> <options>
       dtach -A <socket> <options> <command...>
       dtach -c <socket> <options> <command...>
       dtach -n <socket> <options> <command...>
  -a		Attach to the specified socket.
  -A		Attach to the specified socket, or create it if it
		  does not exist, running the specified command.
  -c		Create a new socket and run the specified command.
  -n		Create a new socket and run the specified command detached.

This basically means that you start dtach like so:

$ dtach -c ~/rtorrent/.socket/dtach rtorrent

The command-shortcut Ctrl+\ detaches the running command and runs it in the background. To re-attach, just enter:

$ dtach -a ~/rtorrent/.socket/dtach

dtach hasn’t got much more functionality, but that’s what makes it superb. Tiny and functional. As you can see, I’m using dtach to run a Seedbox 🙂

One response

  1. […] Dtach is again great at what it does. It’s like daemonize, but it allows you to detach and attach from a running process. I’ve written about this before. […]

Leave a Reply

Create a website or blog at WordPress.com