#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
int main()
{
pid_t pid; int fd ; FILE *fp;
char str[4444][20] = { "Arminia-209 ", "Ellias-404 ",
"GL-209 ", "Deillous-404 " };
printf("\n[ Processs PID:%d PPID:%d ]\n\n", getpid(), getppid()) ;
fd = open("test.dat", O_RDWR|O_CREAT|O_TRUNC, 0644) ;
fp = fopen("temp.dat", "w") ;
write(fd, str[0], 20) ; fputs(str[1], fp) ;
switch(pid=fork()) {
case -1:
perror("[ Fork Error ]\n") ;
exit(0);
case 0:
printf("[ Child PID:%d PPID:%d ]\n", getpid(), getppid());
printf("[ Child END ]\n");
break;
default:
printf("[ Parent PID:%d PPID:%d ]\n", getpid(), getppid() );
printf("[ Parent END ]\n");
break;
}
write(fd, str[2], 20) ; fputs(str[3], fp) ;
printf("[ Process End : %d ]\n\n", getpid() );
exit(0);
}