0
当打印代码只执行两次打印代码时,如何打印3次?我使用C编码,代码位于我创建的SIGCHLD信号处理程序中。信号处理程序的问题
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;
}
输出为我的主要过程是这样的:
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
和输出的MONITOR过程是这样的:
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
(我取出重复行,所以我不占用太多空间)
谢谢, Hristo
http://stackoverflow.com/questions/2597084/problem-with-signal-handlers-being-called-too-many-times – 2010-04-08 02:13:28
这是重复的,因为有人关闭我的文章,但没有给我一个机会回复。 – Hristo 2010-04-08 02:14:00
如果你的问题第一次被关闭,是什么让你认为它会做得更好?不要发布重复,至少拿出一个真正的标题。 – 2010-04-08 02:14:01