i don't understand how...
Posted
by Hristo
on Stack Overflow
See other posts from Stack Overflow
or by Hristo
Published on 2010-04-08T02:10:19Z
Indexed on
2010/04/08
2:13 UTC
Read the original article
Hit count: 373
output
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
© Stack Overflow or respective owner