Blame view

Signaux/Mémo.txt 2.7 KB
0ae69087   pfrison   Ajout des fichiers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  #include <signal.h>
  
  --- codes signaux
  Signal CTRL+C = SIGINT (ou 2)
  
  codes complets :
  (voir à la fin / pas très utile)
  
  --- Envoi de signaux :
      int kill(pid_t pid, int sig); // pid_t ~= int
  
  pid : >0 processus précis
        =0 processus dans le même groupe que notre processus
        <0 tous les processus du groupe "-pid"
  
  
  --- Reception de signaux :
  Définition d'un handler (fonction appelé lors de la recpetion d'un signal) :
      void handler(int sig){
          //...
      }
  
  Enregistrement du handler dans sigaction :
      struct sigaction action;
      action.sa_handler;
  
  La fonction sigaction :
      int sigaction(int sig_to_listen, const struct sigaction *sigaction, struct sigaction *sigaction_anc); //sigaction_anc = NULL (très, très) souvent
  
  Déclaration du sigaction pour détecter les signaux (ex: SIG_INT) :
      sigaction(SIGINT, &action, NULL);
  
  --- Attendre un signal
  la fonction :
      int pause (void);
  
  
  --- Commandes terminal utiles
  voir la liste des processus :
      ps / ps -a
  
  tuer un processus avec un signal particulier :
      kill -<signal> <pid> / kill -s <signal> <pid>
      Note : le signal 9 (kill -9 <pid>) tue n'importe quel processus imédiatement
  
  --- Utilisation du squelette
  Remplacer les balises "TODO" par les valeurs souhaitées
  
  
  
  
  --- Tous les codes de signaux
  
  (venant de l'aide de la commande "man 7 signal")
  
  Signal     Value     Action   Comment
  ──────────────────────────────────────────────────────────────────────
  SIGHUP        1       Term    Hangup detected on controlling terminal
                                or death of controlling process
  SIGINT        2       Term    Interrupt from keyboard
  SIGQUIT       3       Core    Quit from keyboard
  SIGILL        4       Core    Illegal Instruction
  SIGABRT       6       Core    Abort signal from abort(3)
  SIGFPE        8       Core    Floating-point exception
  SIGKILL       9       Term    Kill signal
  SIGSEGV      11       Core    Invalid memory reference
  SIGPIPE      13       Term    Broken pipe: write to pipe with no
                                readers; see pipe(7)
  SIGALRM      14       Term    Timer signal from alarm(2)
  SIGTERM      15       Term    Termination signal
  SIGUSR1   30,10,16    Term    User-defined signal 1
  SIGUSR2   31,12,17    Term    User-defined signal 2
  SIGCHLD   20,17,18    Ign     Child stopped or terminated
  SIGCONT   19,18,25    Cont    Continue if stopped
  SIGSTOP   17,19,23    Stop    Stop process
  SIGTSTP   18,20,24    Stop    Stop typed at terminal
  SIGTTIN   21,21,26    Stop    Terminal input for background process
  SIGTTOU   22,22,27    Stop    Terminal output for background process