Tfe

Ongi etorri tfe-ren webgunera...

Old stuff/ecole_etude_fac_de_pau/licence_3/systeme-d-exploitation/tp3/3.c

(Deskargatu)
#include <signal.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>


void fonction(int n)
{
  printf("\nPas de question, pas de reponses\n");
  exit(-1);
}


int main(int argc, char** argv)
{
  struct sigaction action;
  char buffer[100];
  action.sa_handler = fonction;
  sigemptyset(&action.sa_mask);
  if(sigaction(SIGALRM,&action,NULL) == -1)
    {
      perror("Erreur sigaction SIGALRM\n");
      exit(-1);
    }
  alarm(5);
  printf("Entrez une question: ");
  fgets(buffer,100,stdin);
  printf("question recu: %s\n",buffer);

  return 0;
}