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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:18:09+00:00 2026-05-11T07:18:09+00:00

Assume all the variables have been declared previously… because they have been. The child

  • 0

Assume all the variables have been declared previously… because they have been. The child process does not print anything which makes me think it’s not being executed. The parent process runs fine, albeit it doesn’t get the shared memory. I apologize for the length of this code…

// create 5 child process for(int k=0;k<5;k++){      // fork a child process     pid = fork();      // error occured on fork     if (pid < 0) {         fprintf(stderr, 'Fork Failed');         return 1;     }     // this is what the child process will run     else if (pid == 0) {         //create a shared mem segment         segment_id = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);          //attach the shared memory segment         shared_memory = (char *) shmat(segment_id, NULL, 0);          printf('this is child');          double x = 0;         double sum = 0;          // Run process that sums the function         for(int i=0; i<n; i++){             // get random number in range of x1-x2             x = rand()%(x2 - x1 + 1) + x1;             sum = sum + f(x);         }          //write output to the shared memory segment         sprintf(shared_memory, '%f', sum);         execlp('/bin/ls', 'ls', NULL);       }      // this is what the parent process will run     else {         //print output from shared memory         printf('\n*%s', shared_memory);          //detach shared memory         shmdt(shared_memory);          //Here we add the shared memory to the array         // To add together at the end         // but since I cant get the memory to share         // the array can't be implemented          //remove the shared memory segment         shmctl(segment_id, IPC_RMID, NULL);          wait(NULL);     } } // End of for statement 
  • 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. 2026-05-11T07:18:10+00:00Added an answer on May 11, 2026 at 7:18 am

    The C stdout stream internally buffers data. It’s likely that your ‘this is child’ message is being buffered, and the buffer isn’t being flushed by execlp, so it just disappears. Try a fflush(stdout); after the printf. Incidentally, you should do this before the fork() as well, so that child and parent don’t both try to write output buffered from before the fork.

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

Sidebar

Related Questions

Assume I have char **argv . First, how can I print out all the
I am running the following piece of code (assume all variables have values) is
Assume you have five products, and all of them use one or more of
I assume it doesn't actually hash the file contents, does it stick all of
there have been hundreds if not thousands of posts concerning the use of PHP's
Is it safe to assume that all implementations of org.springframework.context.MessageSource interface are thread-safe after
First, I can assume that all urls that end with jpeg, jpg, bmp, png
We all know that most applications out there assume class names to follow the
All articles I've read about localization of a WinForms application assume that I already
All the tutorials and examples I've found of XSLT processing seem to assume your

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.