Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6045405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:07:16+00:00 2026-05-23T07:07:16+00:00

I run several programs using fork() followed by execve() from a third program. Everything

  • 0

I run several programs using fork() followed by execve() from a third program. Everything these programs were meant to is done, but at the end the third program doesn’t return… i.e the command prompt does not appear.

If I use a wait() command in the calling program then the execve‘s programs return only if the order of wait statements match the order of the end of the execve programs. Why could it be?

Here’s the simplified code:

int main()
{
   int child1,child2,status;
   char*newargv1[] = {./xyz",NULL};
   char *newargv2[] = {./abc",NULL};

   if((child1 = fork())==0)
      execve(newargv1[0],newargv1,NULL);
   if((child2 = fork())==0)
      execve(newargv2[0],newargv2,NULL);

    while(wait(&status) != child1);
    while(wait(&status) != child2);
  }

It works fine if the child1 finishes first. ./xyz and ./abc has some simple processing and control reaches the end.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:07:17+00:00Added an answer on May 23, 2026 at 7:07 am
    while(wait(&status) != child1);
    while(wait(&status) != child2);
    

    In this code – you’ll wait until child1 finishes, but if child2 finishes first – you’ll get the status and discard it. Then, when child1 finishes – you’ll go to the next loop, but then you’ll never get the status for child2 because you already discarded it.

    Instead, keep an array of children, and loop on wait until you got status for each of the members of the array in a single while loop, then you won’t be deadlocked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I run a rather complex project with several independent applications. These use however a
I've read several example programs and tutorials to try and solve my problem but
We have several apps that run on a Windows 2003/2008 server. Some of these
I have a C program that aims to be run in parallel on several
I'm using Netbeans, and trying to get a program Rational to run, so that
If using Haskell as a library being called from my C program, what is
We have several latency-sensitive pipeline-style programs that have a measurable performance degredation when run
I am developing using the PyDev plugin in Eclipse. My program uses several classes
I have a c++ program using gstreamer. The problem is that several of my
I am configuring a new environment to run several intranet web applications. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.