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

  • SEARCH
  • Home
  • 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 8103703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:37:33+00:00 2026-06-05T23:37:33+00:00

AFAICS, the child process inherits stdout/stdin from the parent process on fork(). This leaves

  • 0

AFAICS, the child process inherits stdout/stdin from the parent process on fork(). This leaves me wondering why the following code does NOT work:

int main(int argc, char *argv[])
{
    char *earg[] = {"echo", "Hello", NULL};

    if(fork() == 0) {
        printf("running echo...\n");
        execv("echo", earg);
        printf("done!\n");
        exit(0);
    } else {
        sleep(2);
    }

    return 0;
}   

When running this little program, the two printf() calls appear just fine on the console. But the call to echo somehow gets lost! The output on the console is just:

running echo...
done!

Can somebody explain to me why the echo output doesn’t appear on the console? And how I can fix this?

  • 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-06-05T23:37:35+00:00Added an answer on June 5, 2026 at 11:37 pm

    execv will not search for echo command in the PATH, so it fails, and it prints out "done" (which should not happen if execv is successful). You must supply the full path for execv to work

    You may want to use execvp instead. It will search for the echo command in the PATH variable.

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

Sidebar

Related Questions

How does one call Go code in C from threads that weren't created by
I have seen people use GO statement between batches of SQL code, but AFAICS
We would like to be able to reformat C++ blocks/functions of code directly from
I want to execute a program from my code, and supply it with environment
Not a framework or anything, which AFAICS always carries with it a shipload of
Google Spreadsheets currently does not support the standard function TDIST - i.e. the Student's
I'm trying to understand how to integrate some quickcheck tests with cabal. This gist
I keep looking, but it seems like there's zero interest from compiler developers in
Earlier on, I committed some code which at the time seemed like a good
I'm going to validate and process XML provided by a third party. The XML

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.