質問箱/32

Top > 質問箱 > 32

#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	pid_t child;
	int status;

	if((child = fork()) == -1){
		perror("fork");
		exit(EXIT_FAILURE);
	}else if(child == 0){
		puts("in child");
		printf("\tchild pid = %d\n", getpid());
		printf("\tchild ppid = %d\n", getppid());
		exit(EXIT_SUCCESS);
	}else{
		waitpid(child, &status, 0);
		printf("in parent\n");
		printf("\tparent pid = %d\n", getpid());
		printf("\tparent ppid = %d\n", getppid());
		printf("\tchild exited with %d\n", status);
	}
	exit(EXIT_SUCCESS);
}


URL B I U SIZE Black Maroon Green Olive Navy Purple Teal Gray Silver Red Lime Yellow Blue Fuchsia Aqua White

xrea