that's does not help.
Main Topics
Browse All TopicsHi Experts,
I am trying to launch 2 apps. by using fork() and execv(); however, it launches only one. The code I wrote below:
pid_t pid;
int status;
const char* pPath_1="/home/test_1/test
const char* pPath_2="/home/test_2/test
char *app_1[] = {"test_1", NULL};
char *app_2[] = {"test_2", NULL};
pid = fork();
if(0 == pid)
{
printf("We are in child process\n");
printf("%d\n", pid);
if (execv (pPath_1, app_1) < 0)
{
printf("execv failed\n");
printf("Error code: %s\n", strerror(errno));
_exit(1);
}
if (execv (pPath_2, app_2) < 0)
{
printf("execv failed\n");
printf("Error code: %s\n", strerror(errno));
_exit(1);
}
}
else
{
printf("We are in parent\n");
printf("%d\n", pid);
wait(&status);
}
Please help me out with this problem. Thanks.
codelearner
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
A successful call execv() replaces your current process with the new one, so the second call to execv() never gets called. You will need to call fork twice:
/* To run child 1 and child 2 sequentially */
c1pid = fork();
if(0 == c1pid)
{
printf("We are in first child process\n");
printf("%d\n", c1pid);
if (execv (pPath_1, app_1) < 0)
{
printf("execv failed\n");
printf("Error code: %s\n", strerror(errno));
}
exit(1);
}
printf("We are in parent\n");
printf("%d\n", c1pid);
waitpid(c1pid, &status1, 0);
c2pid = fork();
if(0 == c2pid)
{
printf("We are in second child process\n");
printf("%d\n", c2pid);
if (execv (pPath_2, app_2) < 0)
{
printf("execv failed\n");
printf("Error code: %s\n", strerror(errno));
}
exit(1);
}
printf("We are in parent\n");
printf("%d\n", c2pid);
waitpid(c2pid, &status2, 0);
/* To run child 1 and child 2 in parallel */
c1pid = fork();
if(0 == c1pid)
{
printf("We are in first child process\n");
printf("%d\n", c1pid);
if (execv (pPath_1, app_1) < 0)
{
printf("execv failed\n");
printf("Error code: %s\n", strerror(errno));
}
exit(1);
}
printf("We are in parent\n");
printf("%d\n", c1pid);
c2pid = fork();
if(0 == c2pid)
{
printf("We are in second child process\n");
printf("%d\n", c2pid);
if (execv (pPath_2, app_2) < 0)
{
printf("execv failed\n");
printf("Error code: %s\n", strerror(errno));
}
exit(1);
}
printf("We are in parent\n");
printf("%d\n", c2pid);
waitpid(c1pid, &status1, 0);
waitpid(c2pid, &status2, 0);
Business Accounts
Answer for Membership
by: KavarPosted on 2006-03-09 at 12:11:45ID: 16148235
take out your _exit(1); statements