Signaux Unix

From Tuxunix
Jump to: navigation, search

Exemple d'execution


tuxedo@macMob:SIGNAL] $./signal_test 
Signal 9 non captur?
Signal 17 non captur?
^C
1250 signal : 2 (Interrupt)
^Z
1250 signal : 18 (Suspended)

1250 signal : 15 (Terminated)
Killed
   1./*
   2. * signal.c for (self)
   3. *
   4. * Made by tuxedo
   5. *
   6. * Started on Tue 28 Oct 2008 22:32:37 tuxedo
   7. * Last update Tue 28 Oct 2008 22:45:36 tuxedo
   8.*/
   9.       
  10.#include <stdio.h>
  11.#include <stdlib.h>
  12.#include <signal.h>
  13.#include <unistd.h>
  14.       
  15.void gestSig(int numSignal){
  16.      
  17.    fprintf(stdout, "\n%ld signal : %d (%s)\n", (long)getpid(), numSignal, sys_siglist[numSignal]);
  18.
  19.}/*gestSig*/       
  20.
  21.       
  22.int main(void){
  23.    int i;
  24.       
  25.    for(i = 1; i < NSIG; i++)
  26.        if(signal(i, gestSig) == SIG_ERR)
  27.            fprintf(stderr, "Signal %d non captur?\n", i);
  28.    while(1)
  29.      pause();
  30.       
  31.    return 0;
  32.       
  33.}/*main*/