allswellthatendswell
2016-05-18 12:27:52 UTC
{ edited by mod to shorten lines to ~70 chars. -mod }
I wrote and tested the following C++ program after reading the Stack
Overflow article ,
http://stackoverflow.com/questions/31747247/change-real-process-name-in-c-on-linux.
I discovered my program could not programatically change the Ubuntu
16.04 System Monitor
process name from cli or mono to an unique name such as "fancy_name".
How can we
fix my botched C++ program for the use case where multiple Linux
processes
have an identical name and we would like to kill processes by process
name
using pgrep? My architect does not wish to use UNIX scripts for this
purpose.
Also, my architect would like to why the System Monitor or top displays
a command line prefaced with /usr/bin/cli or /usr/bin/mono even though I
did not specify it in my C++ execle invocation?
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <csignal>
#include <string.h>
#include <sys/prctl.h>
using namespace std;
int main(int argc, char* argvp[])
{
char lockfile[4096];
char environment_variable[4096];
char exe[4096];
cout << argvp[1] << endl;
if (strcmp(argvp[1] , "-start") == 0)
{
sprintf(exe,"%s.exe",argvp[2]);
cout << exe << endl;
ifstream myReadFile;
myReadFile.open(exe);
if (!myReadFile.good())
{
cout << "-start Unrecognized C# executable " << exe << endl;
return 0;
}
char *argv[] = { "/usr/lib/mono/4.5/mono-service.exe",
exe,
0
};
sprintf(environment_variable,"LD_LIBRARY_PATH=%s",argvp[3]);
cout << environment_variable << endl;
char *envp[] =
{
environment_variable,
0
};
cout << argv[0] << endl;
execle("/usr/lib/mono/4.5/mono-service.exe",
"fancy_name",
exe,
(char *)0,
envp
);
perror("Oops!");
}
return 1;
}
Any help is greatly appreciated.
I wrote and tested the following C++ program after reading the Stack
Overflow article ,
http://stackoverflow.com/questions/31747247/change-real-process-name-in-c-on-linux.
I discovered my program could not programatically change the Ubuntu
16.04 System Monitor
process name from cli or mono to an unique name such as "fancy_name".
How can we
fix my botched C++ program for the use case where multiple Linux
processes
have an identical name and we would like to kill processes by process
name
using pgrep? My architect does not wish to use UNIX scripts for this
purpose.
Also, my architect would like to why the System Monitor or top displays
a command line prefaced with /usr/bin/cli or /usr/bin/mono even though I
did not specify it in my C++ execle invocation?
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <csignal>
#include <string.h>
#include <sys/prctl.h>
using namespace std;
int main(int argc, char* argvp[])
{
char lockfile[4096];
char environment_variable[4096];
char exe[4096];
cout << argvp[1] << endl;
if (strcmp(argvp[1] , "-start") == 0)
{
sprintf(exe,"%s.exe",argvp[2]);
cout << exe << endl;
ifstream myReadFile;
myReadFile.open(exe);
if (!myReadFile.good())
{
cout << "-start Unrecognized C# executable " << exe << endl;
return 0;
}
char *argv[] = { "/usr/lib/mono/4.5/mono-service.exe",
exe,
0
};
sprintf(environment_variable,"LD_LIBRARY_PATH=%s",argvp[3]);
cout << environment_variable << endl;
char *envp[] =
{
environment_variable,
0
};
cout << argv[0] << endl;
execle("/usr/lib/mono/4.5/mono-service.exe",
"fancy_name",
exe,
(char *)0,
envp
);
perror("Oops!");
}
return 1;
}
Any help is greatly appreciated.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]