#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
//----------------------------------------------------------
int
main ( void )
{
pid_t pid;
//
pid = fork ( ) ;
if ( pid == 0 )
{
printf ( "Io sono il figlio della biforcazione e " "il mio genitore ha il numero "
"PID %i.\n " , ( int ) getppid ( ) ) ;
sleep ( 2 ) ;
printf ( "Sono passati due secondi e il mio " "genitore ha il numero PID %i.\n " ,
( int ) getppid ( ) ) ;
}
else
{
printf ( "Io sono il processo %i e ho avviato una " "biforcazione di me stesso, la quale ha "
"ottenuto il numero PID %i, ma adesso "
"concludo il mio funzionamento.\n " ,
( int ) getpid ( ) , pid) ;
}
return ( 0 ) ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx1bmlzdGQuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgovLy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KaW50Cm1haW4gKHZvaWQpCnsKICAgIHBpZF90ICBwaWQ7CiAgICAvLwogICAgcGlkID0gZm9yayAoKTsKICAgIGlmIChwaWQgPT0gMCkKICAgICAgewogICAgICAgIHByaW50ZiAoIklvIHNvbm8gaWwgZmlnbGlvIGRlbGxhIGJpZm9yY2F6aW9uZSBlICIKICAgICAgICAgICAgICAgICJpbCBtaW8gZ2VuaXRvcmUgaGEgaWwgbnVtZXJvICIKICAgICAgICAgICAgICAgICJQSUQgJWkuXG4iLCAoaW50KSBnZXRwcGlkICgpKTsKICAgICAgICBzbGVlcCAoMik7CiAgICAgICAgcHJpbnRmICgiU29ubyBwYXNzYXRpIGR1ZSBzZWNvbmRpIGUgaWwgbWlvICIKICAgICAgICAgICAgICAgICJnZW5pdG9yZSBoYSBpbCBudW1lcm8gUElEICVpLlxuIiwKICAgICAgICAgICAgICAgIChpbnQpIGdldHBwaWQgKCkpOwogICAgICAgIGV4aXQgKDApOwogICAgICB9CiAgICBlbHNlCiAgICAgIHsKICAgICAgICBwcmludGYgKCJJbyBzb25vIGlsIHByb2Nlc3NvICVpIGUgaG8gYXZ2aWF0byB1bmEgIgogICAgICAgICAgICAgICAgImJpZm9yY2F6aW9uZSBkaSBtZSBzdGVzc28sIGxhIHF1YWxlIGhhICIKICAgICAgICAgICAgICAgICJvdHRlbnV0byBpbCBudW1lcm8gUElEICVpLCBtYSBhZGVzc28gIgogICAgICAgICAgICAgICAgImNvbmNsdWRvIGlsIG1pbyBmdW56aW9uYW1lbnRvLlxuIiwKICAgICAgICAgICAgICAgIChpbnQpIGdldHBpZCAoKSwgcGlkKTsKICAgICAgfQogICAgcmV0dXJuICgwKTsKfQo=