What could cause the app to launch twice?

I am studying BEAM’s shutdown behaviour, using a toy app (named s throughout) built using mix release. I’ve been starting it with _build/prod/rel/s/bin/s daemon and was triggering various SIGnals, via kill $(pgrep -f 'sname s'). Then i noticed something “odd”, which is that
ps aux | grep erts | grep -v ElixirLS
shows 2 instances of my app running, one via run_erl and the other via beam.smp.

Q1. Why is that and what is the difference between a process being ran via run_erl vs beam.smp?
Q2. Why is ps aux showing run_erl's args all escaped, with prepended \? F.e. \-mode embedded.
Q3. Why wouldn’t beam.smp respond to kill's default TERM signal? That is, why doesn’t kill $(pgrep -f 'sname s') terminate it as it does the other, run_erl process? kill -s KILL does work though, as expected.

Thanks :pray:

USER               PID  %CPU %MEM       VSZ    RSS   TT  STAT STARTED      TIME COMMAND
me               82413   0.0  0.0   4431248    512   ??  S    12:56PM   0:00.00 /path/s/_build/prod/rel/s/releases/0.1.0/../../erts-12.1.5/bin/run_erl -daemon /path/s/_build/prod/rel/s/tmp/pipe/ /path/s/_build/prod/rel/s/tmp/log/  /path/s/_build/prod/rel/s/releases/0\.1\.0/\.\./\.\./erts\-12\.1\.5/bin/erl \-elixir ansi_enabled true \-noshell \-s elixir start_cli \-mode embedded \-setcookie SAME_COOKIE\=\=\=\= \-sname s \-config /path/s/_build/prod/rel/s/releases/0\.1\.0/sys \-boot /path/s/_build/prod/rel/s/releases/0\.1\.0/start \-boot_var RELEASE_LIB /path/s/_build/prod/rel/s/lib \-args_file /path/s/_build/prod/rel/s/releases/0\.1\.0/vm\.args \-extra \-\-no\-halt
me               82419   0.0  0.0 409242080   6576 s000  Ss+  12:56PM   0:01.21 /path/s/_build/prod/rel/s/erts-12.1.5/bin/beam.smp -- -root /path/s/_build/prod/rel/s -progname erl -- -home /Users/me -- -kernel shell_history enabled -- -elixir ansi_enabled true -noshell -s elixir start_cli -mode embedded -setcookie SAME_COOKIE==== -sname s -config /path/s/_build/prod/rel/s/releases/0.1.0/sys -boot /path/s/_build/prod/rel/s/releases/0.1.0/start -boot_var RELEASE_LIB /path/s/_build/prod/rel/s/lib -- -extra --no-halt

Above COMMANDs with each arg on a separate line:

COMMAND
/path/s/_build/prod/rel/s/releases/0.1.0/../../erts-12.1.5/bin/run_erl -daemon \
/path/s/_build/prod/rel/s/tmp/pipe/ \
/path/s/_build/prod/rel/s/tmp/log/  \
/path/s/_build/prod/rel/s/releases/0\.1\.0/\.\./\.\./erts\-12\.1\.5/bin/erl \
  \-elixir ansi_enabled true \
  \-noshell \-s elixir start_cli \
  \-mode embedded \
  \-setcookie SAME_COOKIE\=\=\=\= \
  \-sname s \
  \-config /path/s/_build/prod/rel/s/releases/0\.1\.0/sys \
  \-boot /path/s/_build/prod/rel/s/releases/0\.1\.0/start \
  \-boot_var RELEASE_LIB /path/s/_build/prod/rel/s/lib \
  \-args_file /path/s/_build/prod/rel/s/releases/0\.1\.0/vm\.args \
  \-extra \-\-no\-halt

/path/s/_build/prod/rel/s/erts-12.1.5/bin/beam.smp -- \
  -root /path/s/_build/prod/rel/s -progname erl -- \
  -home /Users/me -- \
  -kernel shell_history enabled -- \
  -elixir ansi_enabled true \
  -noshell -s elixir start_cli \
  -mode embedded \
  -setcookie SAME_COOKIE==== -sname s \
  -config /path/s/_build/prod/rel/s/releases/0.1.0/sys \
  -boot /path/s/_build/prod/rel/s/releases/0.1.0/start \
  -boot_var RELEASE_LIB /path/s/_build/prod/rel/s/lib -- \
  -extra --no-halt
> elixir -v
Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [dtrace]

Elixir 1.13.1 (compiled with Erlang/OTP 24)

It is only launched once. The real one is beam.smp one; the other one is the daemon wrapper. Most people don’t use the daemon mode nowadays but the start mode under an external process supervisor, such as systemd, runit, daemontools, etc.

3 Likes