1

I want to be able to modify the application's process name programmatically. Normal C++ applications implement the main function which we can use to access the commandline arguments.

int main(int argc, char **argv)
....

Where we can then proceed to access the arguments such as using argv[0] etc and modify it as necessary.

Is it possible to also access such commandline arguments or equivalent in Android using Kotlin/Java/C/C++?

I have searched online and it seems that the Android environment does not allow this (as far as I have searched).

This has something to do with an application not being started with exec() calls and is started by the zygote process.

https://blog.codecentric.de/en/2018/04/android-zygote-boot-process/

I just want to know if it is doable in Android.

I have tried the following

prctl(PR_SET_NAME, "newname");
pthread_setname_np(pthread_self(),"newname");

However, doing a ps -ef will still show the original process name

localacct
  • 611
  • 5
  • 13
  • `argv[0]` is not the "process name". At kernel level, [`task_struct::comm`](https://stackoverflow.com/a/5407530/15416) is a 16 byte name, but `argv[0]` is typically the shell-provided name used to start the process. – MSalters Jun 17 '19 at 12:23
  • Hi, thanks for the correction. So is there any way to change that name in Android? Or what will be the appropriate ways to change a process/thread name programmatically? Would prctl and pthread_setname_np be the ways to do it? – localacct Jun 18 '19 at 05:57

0 Answers0