Milan Stephan
Fotografie & IT

Zurück zur SP2 Übersicht

T02-troll.c

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

static void handler(int signum) {
	(void) signum;

	int errno_backup = errno;

	const char *buf = "Zum Beenden bitte Ctrl+C druecken!\n";
	write(STDOUT_FILENO, buf, strlen(buf));

	errno = errno_backup;
}


int main(void) {

	struct sigaction action = {
		.sa_handler = handler,
		.sa_flags = SA_RESTART,
	};
	sigemptyset(&action.sa_mask);


	sigaction(SIGINT, &action, NULL);


	while (1) {
		printf(".");
		fflush(stdout);
		sleep(1);
	}

}