File: test-oooooooo.c

package info (click to toggle)
care 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch, trixie
  • size: 1,716 kB
  • sloc: ansic: 15,436; sh: 1,195; makefile: 6
file content (42 lines) | stat: -rwxr-xr-x 621 bytes parent folder | download | duplicates (5)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
	int i;

	for (i = 0; i < 999; i++) {
		int status;
		int fds[2];
		pid_t pid;

		status = pipe(fds);
		if (status < 0) {
			perror("pipe");
			break;
		}

		pid = fork();
		switch (pid) {
		case -1:
			perror("fork");
			exit(EXIT_FAILURE);

		case 0: /* child */
			do status = write(fds[1], "!", 1); while (status > 0);
			perror("write");
			exit(EXIT_FAILURE);

		default: /* parent */
			status = kill(pid, SIGKILL);
			if (status < 0) {
				perror("kill");
				exit(EXIT_FAILURE);
			}
		}
	}

	exit(EXIT_SUCCESS);
}