Allow to change process name via env using ESCRIPT_NAME #5897
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch allows us to change the name of the process after setting the env var
ESCRIPT_NAME
ESCRIPT_NAME
is already used inerlexec
(see https://github.com/erlang/otp/blob/OTP-24.3/erts/etc/common/erlexec.c#L544 ) to change cmdline, setting argv[0] =ESCRIPT_NAME
;this is nice because you can easily identify your process when using standard unix tooling like
procps
.For example, what you achieve with
ps auwx
is from something like thisto something like this
However, the process name remains unchanged and in
Linux
tools likeiproute2
rely on/proc
to grab the name of the process.This ends up having a lot of processes with the name
beam
and it is not easy to identify who is who, especially if you have a lot of beam processes in your host system.ps
ss
fromiproute2
With the patch, as long as you set the env var, the result is something like this:
I'm not sure about the place in the code where I put the patch, but it seems to me fine.
To change process name, I'm using
ethr_setname
defined inethread.h
which is already used to name threads (usingpthread_setname_np
) and it should be portable across systems.Any thought on this?