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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:21:46+00:00 2026-05-14T04:21:46+00:00

how can something print 3 times when it only goes the printing code twice?

  • 0

how can something print 3 times when it only goes the printing code twice? I’m coding in C and the code is in a SIGCHLD signal handler I created.

void chld_signalHandler() {
 int pidadf = (int) getpid();
 printf("pidafdfaddf: %d\n", pidadf);

 while (1) {
  int termChildPID = waitpid(-1, NULL, WNOHANG);

  if (termChildPID == 0 || termChildPID == -1) {
   break;
  }

  dll_node_t *temp = head;
  while (temp != NULL) {
   printf("stuff\n");
   if (temp->pid == termChildPID && temp->type == WORK) {
    printf("inside if\n");

    // read memory mapped file b/w WORKER and MAIN
    // get statistics and write results to pipe
    char resultString[256];

    // printing TIME
    int i;
    for (i = 0; i < 24; i++) {
     sprintf(resultString, "TIME; %d ; %d ; %d ; %s\n",i,1,2,temp->stats->mboxFileName);
     fwrite(resultString, strlen(resultString), 1, pipeFD);
    }

    remove_node(temp);
    break;
   }
   temp = temp->next;
  }
  printf("done printing from sigchld \n");
 }
 return;
}

the output for my MAIN process is this:

MAIN PROCESS 16214 created WORKER PROCESS 16220 for file class.sp10.cs241.mbox
pidafdfaddf: 16214
stuff
stuff
inside if
done printing from sigchld 
MAIN PROCESS 16214 created WORKER PROCESS 16221 for file class.sp10.cs225.mbox
pidafdfaddf: 16214
stuff
stuff
inside if
done printing from sigchld 

and the output for the MONITOR process is this:

MONITOR: pipe is open for reading
MONITOR PIPE: TIME; 0 ; 1 ; 2 ; class.sp10.cs225.mbox
MONITOR PIPE: TIME; 0 ; 1 ; 2 ; class.sp10.cs225.mbox
MONITOR PIPE: TIME; 0 ; 1 ; 2 ; class.sp10.cs241.mbox
MONITOR: end of readpipe 

( I’ve taken out repeating lines so I don’t take up so much space )

Thanks,
Hristo

  • 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-14T04:21:46+00:00Added an answer on May 14, 2026 at 4:21 am

    From the small amount of information we have…

    1. The main process creates worker process with pid = 16220
    2. Worker process 16220 runs and terminates
    3. The signal handler runs and apparently the second node in the “head” list has a record for process id 16220 (“stuff” prints twice and “inside if” prints once).
    4. The main process creates worker process with pid = 16221
    5. Worker process 16221 runs and terminates
    6. The signal handler runs and apparently the second node in the “head” list has the record for process id 16221 (“stuff” prints twice and “inside if” prints once).

    That is about all we can glean from the data you have provided. If you were to pass a stat parameter for to waitpid you could see why the worker processes terminated by printing out termChildPID and the termination reason in the handler.

    If your question is why does “stuff” print twice then take a look at what “head” points to.

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

Sidebar

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.