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 8819869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:28:12+00:00 2026-06-14T05:28:12+00:00

I am trying to access the EXIT STATUS of the forked child process from

  • 0

I am trying to access the EXIT STATUS of the forked child process from the parent, but I am getting weird answers. Sometimes, I get 256 or sometimes I get a negative number depending upon whether I specify &status or just status. I know I am really close. Can someone provide me with a little help how I will get the EXIT_STATUS

Here is my code

pid_t  pid;
int *status;
if((pid = fork()) < 0)
    fprintf(stdout, "Error forking child process\n");

else if (pid == 0)
{
    execvp(input[0], input);
    fprintf(stdout, "Invalid process!!\n");
    _exit(EXIT_FAILURE);

}
else
{
    while (waitpid(-1, status, 0) != pid);
    fprintf(stdout, "The status is %d\n", &status);
}
  • 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-14T05:28:14+00:00Added an answer on June 14, 2026 at 5:28 am

    You’re seeing this behavior because you do not initialize the pointer you’re using, and therefore you are invoking undefined behavior, which means that, quite literally, anything at all might happen. Try changing status to be an int (instead of an int*):

    int status;
    /* ... */
    while (waitpid(-1, &status, 0) != pid);
    fprintf(stdout, "The status is %d\n", status);
    

    Your code, on the other hand:

    int * status;
    

    This creates a pointer to int and does not initialize it.

    while (waitpid(-1, status, 0) != pid);
    

    Here you pass this pointer to waitpid(), which will write at the
    pointed-to location. Since you have not initialized
    the pointer, it’s writing to an unspecified memory
    location! This may crash the process or overwrite
    allocated memory elsewhere, which may lead to a
    spontaneous crash later, or data corruption!

    fprintf(stdout, "The status is %d\n", &status);
    

    This prints out the address of the pointer variable — not
    the value it points to! Using *status instead of
    &status may allow this part to work, but you’re
    still using an uninitialized pointer.

    I would strongly suggest that you turn your compiler’s warning settings up to the maximum (pass -Wall with gcc) to make it warn on everything. It would have caught the usage of an uninitialized pointer, and it may have also warned you about using the %d format specifier with a pointer-type value.

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

Sidebar

Related Questions

Trying to access a Servlet from a button on HTML page //Html Page FORM
I am trying to access all the data from database listOfFolder table folder and
I'm trying to access the resources of a derived abstract class (from PhoneApplicationPage) in
I have been trying to get video to work and have been getting an
I'm trying to access information on a web browser from another thread. When trying
Am trying to access an API using CURL I can access the API from
I'm trying to figure how to access a widget from within a signal handler.
I am trying to access some images for from image panel using a relative
I am trying to access a method of an object ( myEOS.calc(...) ) from
My problem lies with trying to access Scanner scan created in one method from

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.