Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practice04 / ex2.c
blob: 21f5f0e18ef3bd54a8ed5453ff793dff946cfe20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <sys/wait.h> // wait
#include <sys/types.h> // pid_t
#include <stdio.h> // printf
#include <unistd.h> // getpid, getppid, fork

int main(int argc, char* argv[]) {
	printf("%d\n", getpid());

	pid_t f = fork();
	printf("%d %d\n", f, getpid());
	if (f == 0) { // in child
		printf("Parent: %d\n", getppid());
	}
	else {
		int status;
		wait(&status);
		printf("Child exit status: %d\n", status);
	}
}