I don't understand why exit &
does not work. Why does it not?
2 Answers
I think it works. But probably it doesn't do what you expect.
$ exit &
Will create a sub-shell process, and make it run as a background job which will just finish right away.
-
12
It does work. &
forks the shell, starting a new process (you could think of it as & exit
, except of course that syntax actually means something else). exit
is a shell built-in that ends the shell process -- in this case the new backgrounded shell.
> exit &
[1] 1709
> ps -p 1709
PID TTY TIME CMD
[1]+ Done exit
There's your job. It's done. It worked.
cd / &
"doesn't work"