39 lines
621 B
C++
39 lines
621 B
C++
#include<stdio.h>
|
|
#include <sys/types.h>
|
|
#include <signal.h>
|
|
#include <unistd.h>
|
|
#include <iostream>
|
|
#include <cstdlib>
|
|
using namespace std;
|
|
|
|
// function that prints gibberish
|
|
// for 10 seconds and then kills
|
|
// the program
|
|
void alarmFunction(int alarmVal);
|
|
|
|
|
|
// kills program
|
|
void killFunction(int killPID);
|
|
|
|
int main()
|
|
{
|
|
signal(SIGINT,alarmFunction);
|
|
while (1);
|
|
}
|
|
|
|
void alarmFunction(int alarmVal)
|
|
{
|
|
signal(SIGINT, SIG_IGN);
|
|
signal(SIGALRM,killFunction);
|
|
alarm(10);
|
|
while (1)
|
|
{
|
|
printf(" I love coding! ");
|
|
}
|
|
}
|
|
|
|
void killFunction(int killPID)
|
|
{
|
|
printf("\n");
|
|
exit(0);
|
|
} |