0

I initially thought command & was the command to 'daemonize' a command, but it turns out command -D is the proper command. What exactly does command & do? I can't find anything on that specific option anywhere, and would like to know if it has a name and just the technical specifics on it

1
  • The term you're looking for is 'background'. From the bash manual: "If a command is terminated by the control operator &, the shell executes the command in the background in a subshell." Jun 26, 2017 at 17:14

1 Answer 1

4

I was slightly confused at first as command is a shell built-in command (it executes a utility as a command and not as, say, a shell function if such a function happened to exist).

You use

$ utility &

to start utility as an asynchronous process (background process/job).

From the bash manual:

If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0.

From the dash manual:

If a command is terminated by the control operator ampersand (&), the shell executes the command asynchronously -- that is, the shell does not wait for the command to finish before executing the next command.

The format for running a command in background is:

command1 & [command2 & ...]

(this happens to be identical to the POSIX description of &)

Some utilities, usually daemons, may have flags that makes them go into the background and -D may be a common flag for these to use, but I've also often seen --daemon or -d. Sometimes -d (or whatever flag) prevents the utility to background itself, such as sshd -d which prevents the SSH daemon process from backgrounding itself and instead makes it run as a foreground process and send all log output to standard output rather than to syslog (the -d flag stands for "debug" here).

However, there is no standard for these flags and each utility that supports these operations may implement them through different flags. You need to read the manual for the particular utility that you are dealing with.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .