2016-04-24 12 views
1

ich diese Funktion aufrufen bin mit zu klonen()Invalid Argument Fehler bei der Verwendung von clone()

clone (fun, (char*)stack + 0x500000, SIGCHLD | CLONE_FILES | CLONE_FS, arg);

wo Spaß ist, eine Funktion: int Spaß (void *), stack = malloc (0x500000), und arg ist vom Typ void *.

Ich frage mich, was andere mögliche Ursachen für ungültiges Argument perror sind.

Ich habe Stapel überprüft ist nicht NULL.

+1

Sie diesen Stapel überprüfen haben! = NULL? – socketpair

+0

Die Ausgabe "Ungültiges Argument" von 'perror()' entspricht der gleichen Fehlernummer wie das Makro 'EINVAL'. Haben Sie die Handbuchseite für 'clone()' gelesen? Es zählt eine große Anzahl von Gründen für diesen Code auf, aber die meisten von ihnen betreffen bestimmte schlechte Kombinationen von Flags. Das, was nicht der Fall ist, ist, dass das 'child_stack'-Argument Null (NULL) ist. Beachten Sie, dass 'malloc()' 'NULL zurückgibt, wenn es fehlschlägt. –

+0

@socketpair Ich überprüfte Stapel ist nicht NULL. – ballballbobo

Antwort

1

Mann Klon:

The child_stack argument specifies the location of the stack used by 
    the child process. Since the child and calling process may share mem‐ 
    ory, it is not possible for the child process to execute in the same 
    stack as the calling process. The calling process must therefore set 
    up memory space for the child stack and pass a pointer to this space to 
    clone(). Stacks grow downward on all processors that run Linux (except 
    the HP PA processors), so child_stack usually points to the topmost 
    address of the memory space set up for the child stack. 
Verwandte Themen