You can do this with an LD_PRELOAD
shim: https://github.com/airlift/procname
The shim simply calls the Linux-specific prctl()
when the process starts:
static void __attribute__ ((constructor)) procname_init()
{
prctl(PR_SET_NAME, "myname");
}
The call has to happen on the main thread, so it isn't possible to do this from Java or even with a JVMTI agent, since those happen on a different thread.