TD5 fini
This commit is contained in:
parent
038b4fe071
commit
082dde3ef7
7
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/.vscode/settings.json
vendored
Normal file
7
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"signal.h": "c",
|
||||||
|
"stdio.h": "c",
|
||||||
|
"stdlib.h": "c"
|
||||||
|
}
|
||||||
|
}
|
BIN
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/M311.lnk
Normal file
BIN
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/M311.lnk
Normal file
Binary file not shown.
BIN
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demoAlarm
Normal file
BIN
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demoAlarm
Normal file
Binary file not shown.
BIN
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demoKill
Normal file
BIN
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demoKill
Normal file
Binary file not shown.
@ -0,0 +1,25 @@
|
|||||||
|
/**********************************************************/
|
||||||
|
/* DUT INFORMATIQUE - M311 - R. CHIGNOLI */
|
||||||
|
/* demo_alarm.c : Utilisation du signal SIGALRM par alarm */
|
||||||
|
/**********************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void rep_SIGALRM ()
|
||||||
|
{ printf ("\n*** Processus %d : Signal SIGALRM recu\n\n", getpid());
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main (int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
assert (argc == 2);
|
||||||
|
signal (SIGALRM, rep_SIGALRM);
|
||||||
|
printf ("\n*** Processus %d : Je m' endors ......\n", getpid());
|
||||||
|
res = alarm (atoi(argv[1]));
|
||||||
|
for (;;);
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
/************************************************/
|
||||||
|
/* */
|
||||||
|
/* demo_kill.c : Utilisation de la routine kill */
|
||||||
|
/* */
|
||||||
|
/************************************************/
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <signal.h>
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
printf ("\nJe commence et j'attends 3 secondes...\n");
|
||||||
|
sleep (3);
|
||||||
|
printf ("\n... puis je me suicide par kill - %d - \n", getpid());
|
||||||
|
kill (getpid(), SIGKILL);
|
||||||
|
printf ("\n... je suis mort\n");
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
/******************************************************/
|
||||||
|
/* DUT INFORMATIQUE - M311 - R. CHIGNOLI */
|
||||||
|
/* demo_kill_grp_1.c : Utilisation de la routine kill */
|
||||||
|
/******************************************************/
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{ int res;
|
||||||
|
res = fork ();
|
||||||
|
if (res != 0)
|
||||||
|
{
|
||||||
|
printf ("\nPERE No %d ( GRPID = %d ) : j'attends 5 secondes...\n",
|
||||||
|
getpid(), getpgrp());
|
||||||
|
sleep (5);
|
||||||
|
printf ("\nPERE No %d ( GRPID = %d ) : ... puis je me suicide par kill\n\n", getpid(), getpgrp());
|
||||||
|
kill (0, SIGKILL);
|
||||||
|
printf ("\nPERE No %d ( GRPID = %d ) : ... je suis mort\n\n", getpid(), getpgrp());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf ("\nFILS No %d ( GRPID = %d ) : Je boucle indefiniment ...\n",
|
||||||
|
getpid(), getpgrp());
|
||||||
|
for(;;);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
/******************************************************/
|
||||||
|
/* DUT INFORMATIQUE - M311 - R. CHIGNOLI */
|
||||||
|
/* demo_kill_grp_2.c : Utilisation de la routine kill */
|
||||||
|
/******************************************************/
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main () {
|
||||||
|
int res;
|
||||||
|
res = fork ();
|
||||||
|
if (res != 0){
|
||||||
|
printf ("\nPERE No %d ( GRPID = %d ) : j'attends 3 secondes...\n", getpid(), getpgrp());
|
||||||
|
sleep (3);
|
||||||
|
printf ("\nPERE No %d ( GRPID = %d ) : ... puis je me suicide par kill\n", getpid(), getpgrp());
|
||||||
|
kill (0, SIGKILL);
|
||||||
|
printf ("\nPERE No %d ( GRPID = %d ) : ... je suis mort\n", getpid(), getpgrp());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (setpgid (0, getpid()) != 0){
|
||||||
|
perror ("setgpid"); exit (1);
|
||||||
|
}
|
||||||
|
printf ("\nFILS No %d ( GRPID = %d ) : nouveau groupe ...\n", getpid(), getpgrp());
|
||||||
|
printf ("\nFILS No %d ( GRPID = %d ) : J'attends 5 secondes\n", getpid());
|
||||||
|
sleep (5);
|
||||||
|
printf ("\nFILS No %d ( GRPID = %d ) : Et je meurs naturellement !\n\n",
|
||||||
|
getpid());
|
||||||
|
exit (0);
|
||||||
|
}
|
||||||
|
}
|
26
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/bash_trap.sh
Normal file
26
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/bash_trap.sh
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
################################################
|
||||||
|
# @ Author: JunkJumper
|
||||||
|
# @ Link: https://github.com/JunkJumper
|
||||||
|
# @ Copyright: Creative Common 4.0 (CC BY 4.0)
|
||||||
|
# @ Create Time: 22-10-2020 11:55:28
|
||||||
|
# @ Modified by: JunkJumper
|
||||||
|
# @ Modified time: 22-10-2020 11:56:09
|
||||||
|
################################################
|
||||||
|
|
||||||
|
#!/usr/bin/bash
|
||||||
|
#####################################
|
||||||
|
# M311 - CHIGNOLI #
|
||||||
|
# bash-trap.sh : demonstration de #
|
||||||
|
# de la gestion de signaux en bash #
|
||||||
|
#####################################
|
||||||
|
trap 'echo Ignore signal SIGINT' SIGINT
|
||||||
|
trap 'echo Ignore signal SIGSTOP' SIGSTOP
|
||||||
|
trap 'echo Ignore signal SIGUSR1' SIGUSR1
|
||||||
|
trap 'echo FIN ! ; exit' SIGUSR2
|
||||||
|
trap
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
echo Je boucle ...
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
17
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/bash_trap.txt
Normal file
17
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/bash_trap.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
################################################
|
||||||
|
# DUT INFORMATIQUE - M311 - R. CHIGNOLI #
|
||||||
|
# bash_trap : traitement des signaux en bash #
|
||||||
|
################################################
|
||||||
|
|
||||||
|
echo '*******************************************'
|
||||||
|
echo '* J'ignore les signaux SIGQUIT et SIGTERM *'
|
||||||
|
echo '*******************************************'
|
||||||
|
trap 'echo Ignore signal SIGINT' SIGINT
|
||||||
|
trap 'echo Ignore signal SIGTERM' SIGTERM
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
echo je boucle
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
68
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_fork_signal.c
Normal file
68
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_fork_signal.c
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
* @ Author: JunkJumper
|
||||||
|
* @ Link: https://github.com/JunkJumper
|
||||||
|
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
|
||||||
|
* @ Create Time: 22-10-2020 11:55:28
|
||||||
|
* @ Modified by: JunkJumper
|
||||||
|
* @ Modified time: 22-10-2020 11:55:53
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**********************************************************/
|
||||||
|
/* DUT INFORMATIQUE - M311 - R. CHIGNOLI */
|
||||||
|
/* p_fork_signal : Apr<70>s fork, */
|
||||||
|
/* - PERE : Affiche son pid et ppid, */
|
||||||
|
/* Ignore le signal SIGINT et le montre */
|
||||||
|
/* S'arrete <20> la reception du signal SIGUSR1, */
|
||||||
|
/* se met en boucle infinie. */
|
||||||
|
/* - FILS : Affiche son pid et son ppid, */
|
||||||
|
/* Envoie trois signaux SIGINT au pere, */
|
||||||
|
/* Attend un signal SIGTERM de l'utilisateur */
|
||||||
|
/* Se met en boucle infinie. */
|
||||||
|
/* Envoie le signal SIGUSR1 a son pere a */
|
||||||
|
/* l'interception du signal SIGTERM puis */
|
||||||
|
/* meurt. */
|
||||||
|
/**********************************************************/
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <signal.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
|
||||||
|
void repSIGINT() {
|
||||||
|
printf ("\nJ'ignore le signal SIGINT (<Ctrl + \\C>)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main () {
|
||||||
|
int res;
|
||||||
|
res = fork();
|
||||||
|
|
||||||
|
if (res < 0){
|
||||||
|
printf ("ERREUR FORK\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (res == 0)
|
||||||
|
{ /************************** FILS ***********************/
|
||||||
|
printf("Je suis le fils : ");
|
||||||
|
printf("pid : %d\n", getpid());
|
||||||
|
printf("ppid : %d\n",getppid());
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
kill(getppid(), SIGINT);
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ /************************** PERE ***********************/
|
||||||
|
printf("Je suis le père : ");
|
||||||
|
printf("pid : %d\n", getpid());
|
||||||
|
printf("ppid : %d\n",getppid());
|
||||||
|
|
||||||
|
signal(SIGINT, repSIGINT);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(;;);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
62
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_multi_fork.c
Normal file
62
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_multi_fork.c
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/**
|
||||||
|
* @ Author: JunkJumper
|
||||||
|
* @ Link: https://github.com/JunkJumper
|
||||||
|
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
|
||||||
|
* @ Create Time: 22-10-2020 11:55:28
|
||||||
|
* @ Modified by: JunkJumper
|
||||||
|
* @ Modified time: 22-10-2020 11:56:56
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**********************************************************/
|
||||||
|
/* DUT INFORMATIQUE - M311 - R. CHIGNOLI */
|
||||||
|
/* p_multi_fork_signal : Apr<70>s fork, */
|
||||||
|
/* - PERE : Affiche son pid et ppid, */
|
||||||
|
/* Ignore le signal SIGINT */
|
||||||
|
/* S'arrete <20> la reception du signal SIGUSR1, */
|
||||||
|
/* Se met en boucle infinie. */
|
||||||
|
/* - FILS : Affiche son pid et son ppid, */
|
||||||
|
/* Cree 3 (sous)fils */
|
||||||
|
/* Attend un signal SIGTERM de l'un des fils */
|
||||||
|
/* Envoie un signal SIGINT a son pere, */
|
||||||
|
/* Se met en boucle infinie. */
|
||||||
|
/* Envoie le signal SIGUSR1 a son pere a */
|
||||||
|
/* l'interception du signal SIGTERM puis */
|
||||||
|
/* meurt. */
|
||||||
|
/* - Chaque sous-FILS : Affiche son pid et son ppid, */
|
||||||
|
/* Se desolidarise de son pere, */
|
||||||
|
/* Attend un signal SIGUSR1 de l'utilisateur, */
|
||||||
|
/* Se met en boucle infinie. */
|
||||||
|
/* Envoie le signal SIGTERM vers son pere */
|
||||||
|
/* a l'interception du signal SIGUSR1. */
|
||||||
|
/* Se termine en recevant le signal SIGUSR2 */
|
||||||
|
/* de la part de l'utilisateur. */
|
||||||
|
/* NB : <20> la fin du scenario, il ne reste que les trois */
|
||||||
|
/* sous-fils arretable par envoi de signaux SIGUSR2 */
|
||||||
|
/**********************************************************/
|
||||||
|
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <signal.h>
|
||||||
|
/**********************/
|
||||||
|
/* PARTIE A COMPLETER */
|
||||||
|
/**********************/
|
||||||
|
main ()
|
||||||
|
{ int res;
|
||||||
|
/**********************/
|
||||||
|
/* PARTIE A COMPLETER */
|
||||||
|
/**********************/
|
||||||
|
res = fork();
|
||||||
|
if (res < 0) printf ("ERREUR FORK");
|
||||||
|
else
|
||||||
|
if (res == 0)
|
||||||
|
{ // FILS
|
||||||
|
/**********************/
|
||||||
|
/* PARTIE A COMPLETER */
|
||||||
|
/**********************/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // PERE
|
||||||
|
/**********************/
|
||||||
|
/* PARTIE A COMPLETER */
|
||||||
|
/**********************/
|
||||||
|
}
|
||||||
|
}
|
81
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_signal.c
Normal file
81
2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_signal.c
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/**
|
||||||
|
* @ Author: JunkJumper
|
||||||
|
* @ Link: https://github.com/JunkJumper
|
||||||
|
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
|
||||||
|
* @ Create Time: 22-10-2020 11:55:28
|
||||||
|
* @ Modified by: JunkJumper
|
||||||
|
* @ Modified time: 22-10-2020 11:57:03
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**********************************************************/
|
||||||
|
/* DUT INFORMATIQUE - M311 - R. CHIGNOLI */
|
||||||
|
/* p_signal : Modification des actions associees */
|
||||||
|
/* aux signaux SIGINT, SIGSEGV et SIGQUIT. */
|
||||||
|
/**********************************************************/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
SIGINT 2 Term Interruption depuis le clavier.
|
||||||
|
SIGQUIT 3 Core Demande « Quitter » depuis le clavier.
|
||||||
|
SIGILL 4 Core Instruction illégale.
|
||||||
|
SIGABRT 6 Core Signal d'arrêt depuis abort(3).
|
||||||
|
SIGFPE 8 Core Erreur mathématique virgule flottante.
|
||||||
|
SIGKILL 9 Term Signal « KILL ».
|
||||||
|
SIGSEGV 11 Core Référence mémoire invalide.
|
||||||
|
SIGPIPE 13 Term Écriture dans un tube sans lecteur.
|
||||||
|
SIGALRM 14 Term Temporisation alarm(2) écoulée.
|
||||||
|
SIGTERM 15 Term Signal de fin.
|
||||||
|
SIGUSR1 30,10,16 Term Signal utilisateur 1.
|
||||||
|
SIGUSR2 31,12,17 Term Signal utilisateur 2.
|
||||||
|
SIGCHLD 20,17,18 Ign Fils arrêté ou terminé.
|
||||||
|
SIGCONT 19,18,25 Cont Continuer si arrêté.
|
||||||
|
SIGSTOP 17,19,23 Stop Arrêt du processus.
|
||||||
|
SIGTSTP 18,20,24 Stop Stop invoqué depuis tty.
|
||||||
|
SIGTTIN 21,21,26 Stop Lecture sur tty en arrière-plan.
|
||||||
|
SIGTTOU 22,22,27 Stop Écriture sur tty en arrière-plan.
|
||||||
|
|
||||||
|
SIG_DFL = action par defaut pour le signal
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
int stop = 1;
|
||||||
|
|
||||||
|
void repSIGQUIT() {
|
||||||
|
printf ("\nJ'ignore le signal SIGQUIT (<Ctrl \\>)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void repSIGINT() {
|
||||||
|
if(stop == 0) {
|
||||||
|
kill (getpid(), SIGKILL);
|
||||||
|
} else {
|
||||||
|
stop--;
|
||||||
|
printf ("Je m'arrete au 2eme signal d'interruption (<Ctrl C>)\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void repSIGSEGV() {
|
||||||
|
printf ("Je m'arrete au premier signal SIGSEGV\n\n");
|
||||||
|
kill (getpid(), SIGKILL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
//printf ("\nJ'ignore le signal SIGQUIT (<Ctrl \\>)\n");
|
||||||
|
//printf ("Je m'arrete au 2eme signal d'interruption (<Ctrl C>)\n");
|
||||||
|
//printf ("Je m'arrete au premier signal SIGSEGV\n\n");
|
||||||
|
printf("%d\n", getpid());
|
||||||
|
|
||||||
|
signal(SIGQUIT, repSIGQUIT);
|
||||||
|
signal(SIGINT, repSIGINT);
|
||||||
|
signal(SIGSEGV, repSIGSEGV);
|
||||||
|
|
||||||
|
/**********************/
|
||||||
|
/* PARTIE A COMPLETER */
|
||||||
|
/**********************/
|
||||||
|
|
||||||
|
/* boucle de temporisation */
|
||||||
|
for (;;);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user