#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>

int main(void) {
	int stat;
	pid_t waitpid;
	pid_t pid = fork();

	if (pid < 0) {
		perror("fork");
		return -1;
	}

	if (pid == 0) {
		/* create zombie */
		printf("child: %d\n", getpid());
		return 0;
	}

	waitpid = wait(&stat);
	if (waitpid < 0) {
		perror("waitpid");
		return -1;
	}

	printf("child %d died\n", waitpid);
	return 0;
}
