2012-04-15 10 views
8

Son sonuçlara ulaşmak için birden fazla G/Ç borusu kullanan (her işlem için bir boru) bir mapceduce programı yazıyorum. İşlemleri oluştururken sorun yaşıyorum. Özellikle, aşağıdaki hatayı alıyorum: Ben threadFunction seçme kullanan bir iplikfork() - birden çok işlem ve sistem çağrısı

pthread_t newThread; 
pthread_create(&newThread,NULL,threadFunction,values); 
pthread_join(newThread,NULL); 

oluşturma Bundan sonra

while (values[inc]!=NULL) //provided array of text lines 
{ 
    if ((pid = fork()) == -1) { 
     perror("fork error"); 
     exit(EXIT_FAILURE); 
    }  

    else if (pid == 0) {    /* start of child process  */ 
     printf("Child process...\n"); 
     /* pipes[inc][1] is a file descriptor to which myMap writes some data 
      using the write() system call 
      mr is a struct that holds other function pointers */ 
     mr->myMap(pipes[inc][1],values[inc]); 
     exit(0); 
    } 
    else {       /* start of parent process  */ 
     printf("Parent process...\n"); 

     if ((wpid = wait(&status)) == -1) 
     /* Wait for child process.  */ 
      perror("wait error"); 
     else {      /* Check status.    */ 
      if (WIFSIGNALED(status) != 0) 
       printf("Child process ended because of signal %d\n", 
         WTERMSIG(status)); 
      else if (WIFEXITED(status) != 0) 
       printf("Child process ended normally; status = %d\n", 
         WEXITSTATUS(status)); 
      else 
       printf("Child process did not end normally\n"); 
     } 
     //close(fd[1]); 

     printf("Parent process ended\n"); 
    } 
    inc++; 
} 

(:

wait error: Interrupted system call 

Bu süreçler çoğaltılır benim kodudur) Hangi dosya tanıtıcısının okunmaya hazır olduğunu bulup, okuyarak veriyi bir sözlüke koyar.

formu gdb debugger program çıkışı çalıştırırken:

Parent process... 
Child process... 
wait error: Interrupted system call 
Parent process ended 
Parent process... 
Child process ended normally; status = 0 
Parent process ended 
Parent process... 
Child process... 
Child process... 
wait error: Interrupted system call 
Parent process ended 

Ben sorunu çözmek için nasıl bilmiyorum. Baska öneri?

Teşekkürler!

cevap

9

wait() çağrınızı döngü içine almanız ve bir hata döndürdüğünde (-1) ve errno == EINTR döngüye devam edin. Başka bir hata, gerçek bir hatadır ve bu şekilde ele alınmalıdır. sinyalleri neden olabilir profilleme sayaçları gibi

Şeyler ancak sinyal muhtemelen kesintiye neden sürecine yönlendirilmesini devlet bir çocuk süreç değiştirir çağrılan bildiği gibi, hangi SIGCHLD olduğunu.

DÜZENLEME: Tamam, kod cevabını yazacağım:

do 
{ 
    wpid = wait(&status); 
} 
while (wpid == -1 && errno == EINTR); 
if (wpid == -1) 
{ 
    perror("wait error"); 
    return -1; 
} 
else 
{ 
    // we have wait status 
    ... 
} 
+0

Ne demek istediğini emin değilim. Lütfen detaylandırın. – Krzysiek

+1

@Rafcio Cevabımı güncelledim. – trojanfoe

+1

Teşekkürler. Mantıklı! :) – Krzysiek