#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
pid_t pid, cpid ; int status, n ;
printf("\n[ Process PID:%d PPID:%d ]\n\n", getpid(), getppid()) ;
switch(pid=fork()) {
case -1:
perror("[ Fork Error ]\n") ;
exit(0);
case 0:
printf("[ Child PID:%d PPID:%d ]\n", getpid(), getppid());
sleep(1);
printf("\n[ Child Process END :%d ]\n\n", getpid());
exit(0xFE) ;
default:
printf("[ Parent PID:%d PPID:%d ]\n", getpid(), getppid() );
for(n=0; n<7; n++)
sleep(3), write(1,". ",4) ;
printf("\n[ Wait Fun ]\n") ;
cpid = wait(&status);
printf("[ CPID : %d ]\t\t[ Status : %x]\n", cpid, status) ;
printf("[ Parent Process END : %d ]\n\n", getpid());
break;
}
exit(0);
}