clone -> wait

S

sanitotte

Grünschnabel
Hallo zusammen,

um mit dem Systemaufrufen clone() und wait() ein wenig vertraut zu werden habe ich ein kleines Programm geschrieben, daß einen Clone erzeugt, anschließend auf dessen Abarbeitung warten soll und sich dann beendet.

Allerdings bekomme ich von wait() immer die Fehlermeldung ECHILD zurück.

Hat jemand eine Ahnung warum?

Ich poste hier mal den Source:

Code:
#include <float.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 


#include <time.h>                   /* for output of time: printf(ctime....); */ 
#include <sched.h>                  /* for priorities and clone               */ 
#include <signal.h>                 /* for signals                            */ 
#include <sys/time.h>               /* for timer                              */ 
#include <asm/msr.h>                /* for time measuring with the Intel TSC  */ 
#ifndef __USE_GNU                   /* for Mutex                              */ 
#define __USE_GNU 
#endif 
#include <pthread.h>                /* for threads                            */ 
#include <unistd.h>                 /* for usleep                             */ 


#include <sys/types.h>                 /*used for clone wait */ 
#include <sys/wait.h>                 /*used for wait */ 
#include <errno.h>                    /*used for errno */ 

int clone_test(void *arg) 
{ 
  //Nummer des Clones ermitteln 
  int nr = (int)arg; 

  printf("\nTest: Ich bin der Clone Nummer %x!\n\n", nr); 

  int i,j; 
  //ca. 5s verzögerung 
  for (i = 0; i < 50000; i++) 
  { 
    for (j = 0; j < 120000; j++) 
    { 
      int z; 
      z = i * j; 
    } 
  //LifeSign ca. jede Sek. 
    if (i % 10000 == 0) printf("Clone-Lifesign!\n"); 
  } 


  printf("\nTest: Ich war der Clone Nummer %x!\n\n", nr); 
//  return(1); 
  exit(0); 
} 




int main(/*int argc, char* argv[]*/) 
{ 
  printf("\nTest: Ich bin der Original-Process!\n\n"); 

  void* stack1[4000]; 

  //Clone aktivieren 
  int clonepid = clone(clone_test, stack1+4000, CLONE_VM, (void*)1); 

  printf("Clone hat die PID: %i\n", clonepid); 

  int status; 
  int x = wait(&status); printf("X: %i\n",x); 

  perror("clone:"); 

  printf("\nTest: Ich war der Original-Process!\n\n"); 
  return(1); 
}
 

Ähnliche Themen

C Code Hilfe!!! gesucht bei Dezimalzahl in Binärzahl for loop

Unix Webserver mit HTML Seite erstellen

Prozesskommunikation mit PIPES - wie funktioniert das?

Ausführbare C-Datei von Mac OS auf Embedded Linux ausführen

Aufgabe in C

Zurück
Oben