Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practice13 / ex1.c
blob: 4ea65cbf3298340035c02db47ccb5c8ca6317160 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

void handler(int a) {}

int main() {
	signal(SIGUSR1, &handler);

	int fpid = fork();
	if (fpid == 0) {
		while (1) {
			pause();
			printf("child\n");
		}
	}
	else {
		while (1) {
			printf("parent\n");
			kill(fpid, SIGUSR1);
			sleep(1);
		}
	}
	return 0;
}