Ich habe ein Programm mit undefiniertem Verhalten (vfork() wird in unangemessener Weise verwendet):
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
int main ( int argc, char *argv[] )
{
pid_t pid;
printf("___________befor fork______________.\n");
if((pid=vfork()) < 0)
perror("fork");
else if(pid > 0)
printf("parent\n");
else
printf("child\n");
printf("pid: %d, ppid: %d\n", getpid(), getppid());
//exit(0);
return 0;
}
Wenn ich die exit(0)
Funktion stattdessen zurück - Ausgabe ist:
___________befor fork______________.
child
pid: 4370, ppid: 4369
parent
pid: 4369, ppid: 2924
Wenn ich die return 0
- Ich erhalte eine unendliche Ausgabe wie diese:
___________befor fork______________.
child
pid: 4455, ppid: 4454
parent
pid: 4454, ppid: 2924
___________befor fork______________.
child
pid: 4456, ppid: 4454
parent
pid: 4454, ppid: 2924
___________befor fork______________.
child
pid: 4457, ppid: 4454
parent
pid: 4454, ppid: 2924
and so on ...
Ich weiß, dass Sie nicht verwenden können return
im Kind nach der vfork()
Funktion. Aber ich verstehe nicht, warum das Elternteil nicht nach return
anrufen?
Danke.