In the case of
(tty &)
a subshell is started which starts another tty
process in the background without job control and terminal, hence there is a "not a tty" error. The tty
process becomes detached with PPID 1
In the case of
(tty) &
a subshell is started and runs in the background. This background shell starts a tty
process and after tty finishes and reports to the terminal, the subshell finishes in the background.
--
tty
is a simple command. Whether or not a particular command (like startx
) needs a ( ... &)
construct to become detached / disowned from a parent process depends on the command itself. There are a number of ways for a process to in turn start a subprocess and detach that, so the command may not need it.
X &
runs X without a controlling terminal, it seems(tty)&
would run the subshell without a controlling terminal, and therefore thetty
command wouldn't have a controlling terminal either. Is the difference due to whether the background process is started by the session leader? – Animation