So I have this task of changing the process name during runtime in C, and I've stumbled upon this: http://www.uofr.net/~greg/processname.html
Now before anything else, I am aware of the dangers of altering argv[0] (but have a long way to go about Linux and UNIX stuffs) so please don't lecture about it, I just want to know why it isn't working on Ubuntu.
Here is the test source I've used:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main(int argc, char *argv[]) {
int argv0size = strlen(argv[0]);
int onetwothree = 1;
char* abc = (char *) malloc(sizeof(char) * (17 + 1));
sprintf(abc,"ApplicationName%.3d",onetwothree);
strncpy(argv[0], abc ,argv0size);
getchar();
}
I've tested it on Mac OS X and Ubuntu only, and it's working on Mac OS X. I don't know why it's not working on Ubuntu. What could be the possible reasons for it not working?
I'm using gcc as compiler.