unkillable.c

DownloadView Raw

/**
 * unkillable.c
 *
 * Demonstrates blocking signals (SIGINT and SIGTERM). Run this program and try
 * killing it with Ctrl+C (^C) or running kill <pid>.
 *
 * Compile: gcc -g -Wall unkillable.c -o unkillable
 * Run: ./unkillable
 */

#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void) {

    signal(SIGTERM, SIG_IGN);
    signal(SIGINT, SIG_IGN);

    while (true) {
        puts("I'm just a process\n"); sleep(1);
        puts("Running till the end of time\n"); sleep(1);
        puts("I'm just a process\n"); sleep(1);
        puts("Got nothin' on my mind\n"); sleep(1);

        puts("Please don't you kill me\n"); sleep(1);
        puts("Don't press control and C\n"); sleep(1);
        puts("Darlin' believe me\n"); sleep(1);
        puts("A process is all that I can be\n"); sleep(1);

        puts("I'm just a process\n"); sleep(1);
        puts("I've got some hopes and dreams\n"); sleep(1);
        puts("I'm just a process\n"); sleep(1);
        puts("My functionality more than it seems\n"); sleep(1);

        puts("Think of my children, don't you know it's wrong?\n"); sleep(1);
        puts("My thread of execution running for so long\n"); sleep(1);
        puts("If you kill me, it'll also kill this song\n"); sleep(1);
        puts("Yeah if you kill me, it'll also kill this song\n"); sleep(1);

        puts("This process life\n"); sleep(1);
        puts("I never wanted to be a part of it\n"); sleep(1);
        puts("Okay that's enough!\n"); sleep(1);
        puts("Control + backslash sends SIGQUIT.\n"); sleep(1);
        puts("\n");
    }

    return 0;
}