Answer the question
In order to leave comments, you need to log in
How to use excv?
Good evening! I'm looking for help, I've just recently started writing under Linux and Android in particular, so my question may seem silly to many. I want to run a program that adds two numbers, I wrote a small function for this from another program, but something doesn’t work, I don’t see any messages about entering parameters. The first message I see is about running execv. I want the second program to run in a completely independent process and the first one to exit. This is how I do it:
int RunFile(char const* FileName)
{
string LaunchName(".//");
LaunchName.append(FileName);
char *arg[] = {const_cast<char*>(FileName), NULL};
int res = 0;
int pid = 0;
switch(pid=fork()) {
case -1:
printf("fork error %d\n", pid); /* произошла ошибка */
res = -1; /*выход из родительского процесса*/
break;
case 0:
printf("execv start\n"); /* произошла ошибка */
execv(LaunchName.c_str(), arg);
printf("execv end\n");
res = 0;
break;
default:
exit(0);
break;
}
return res;
}
Answer the question
In order to leave comments, you need to log in
looks ok. You can run the original process under strace -f and see what happens.
Extremely vague description.
execv replaces the current process with a new file.
That is, everything after execv will run _only_ if an error occurs. What is actually written in the mana.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question