HELLOW,
I need to do a program in c ++ under linux:
alling the alarm function (sec) will bring the SIGALRM signal to the ordering party after a second.
A program that calculates how much a computer is capable of performing increments of the integer variable of type long in 1 second. The program generates an integer result for the standard output.
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <time.h>
#include <stdio.h>
int t = time(NULL);
void sigalarm_handler(int)
{
printf("alarm fired at t=%ld\n", time(NULL) - t); // write a message when called
}
int main(void)
{
// install our interrupt handler
signal(SIGALRM, sigalarm_handler);
// we want an alarm in 3 seconds
printf("alarm requested t=%ld\n", time(NULL) - t); // write start time
alarm(3);
// sleep for 10 seconds or until signal arives
sleep(10);
printf("ending at t=%ld\n", time(NULL) - t); // write signalled/sleep time
return 0;
}