I found a use of exec some_cmd &
in this script:
...
exec elixir \
-pa _build/prod/consolidated \
--no-halt \
--erl "+A$THREAD_COUNT" \
--erl "+K true" \
--erl "-smp auto" \
--erl "+scl false" \
--erl "+spp true" \
--erl "+swt low" \
--erl "+sbwt long" \
--sname $NODE \
--cookie $COOKIE \
-S mix run \
--no-compile \
$@ \
&
...
exec some_cmd
replaces the shell with some_cmd
. some_cmd &
spawns some_cmd
as a child process in background.
So what happens when combining them?
I gave it a try with bash 3.2 and the result shows that it looks like it spawns a background process:
# script
echo "Shell PID: $$"
exec sh -c 'echo "Child PID: $$"' &
BG_PID=$!
echo "Background process PID: $BG_PID"
# output
Shell PID: 8852
Background process PID: 8853
Child PID: 8853
Though I'm not sure whether it is exactly the same as some_cmd &
.
The exec
command has no effect in this case. Normally, exec
would prevent bash from forking before calling execve
, but in this case bash forks anyway because you said &
.
So exec some_cmd &
is the same as some_cmd &
.
You might use exec
with &
anyway if you need to use one of the exec
flags. Type help exec
to see what flags exec
supports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With