0

As per the comment in my previous topic, my question was answered but I need to make another topic: So I used readlink on /proc/self/exe but is if you want to find the path to the executable. The buffer is yours and has no effect on anything else. My question, how do I change the executable name top/argv[0] shows.

I don't have access to the main function so no access to argv

Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • 1
    There seem to be two previous questions: [Changing `argv[0]` with WinAPI](http://stackoverflow.com/questions/29158052/changing-argv0-with-winapi) and [Finding `argv[0]` so I can change it](http://stackoverflow.com/questions/29158026/finding-pointer-to-argv0-so-i-can-change-it). You might care to note that the value in `argv[0]` does not necessarily have anything much to do with the name of the executable that you run. For example: `execl("/bin/sleep", "rip van winkle", "30", (char *)0);` will leave you with `sleep` running but the value in `argv[0]` is `rip van winkle`, not `sleep`. – Jonathan Leffler Mar 20 '15 at 04:51

1 Answers1

1

You can use prctl to set the name shown by top.

#include <sys/prctl.h>

void function()
{
    ...
    prctl(PR_SET_NAME, "new name", 0, 0, 0);
    ...
}

Note that this won't change the name shown by ps, or the contents of /proc/<pid>/exe. Also, it only changes the name of the current thread, and must be a maximum of 16 bytes. See man prctl and look for PR_SET_NAME for more details.

craig65535
  • 3,439
  • 1
  • 23
  • 49
  • Thanks Craig. My hope was to change the executable path so Firefox restart uses this path. So this didn't work :( I think this is why: http://stackoverflow.com/a/17120029/1828637 – Noitidart Mar 20 '15 at 07:39