From 082dde3ef748a2629997ba95d68b3ba34f2ad78c Mon Sep 17 00:00:00 2001 From: JunkJumper Date: Thu, 22 Oct 2020 11:57:36 +0200 Subject: [PATCH] TD5 fini --- .../.vscode/settings.json | 7 ++ .../Demonstrations/M311.lnk | Bin 0 -> 2329 bytes .../Demonstrations/demoAlarm | Bin 0 -> 17008 bytes .../Demonstrations/demoKill | Bin 0 -> 16816 bytes .../Demonstrations/demo_alarm.c | 25 ++++++ .../Demonstrations/demo_kill.c | 19 ++++ .../Demonstrations/demo_kill_grp_1.c | 28 ++++++ .../Demonstrations/demo_kill_grp_2.c | 32 +++++++ .../bash_trap.sh | 26 ++++++ .../bash_trap.txt | 17 ++++ .../p_fork_signal.c | 68 +++++++++++++++ .../p_multi_fork.c | 62 ++++++++++++++ .../S3T_TP_05_PROCESSUS-4-SIGNAUX/p_signal.c | 81 ++++++++++++++++++ 13 files changed, 365 insertions(+) create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/.vscode/settings.json create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/M311.lnk create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demoAlarm create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demoKill create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_alarm.c create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_kill.c create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_kill_grp_1.c create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_kill_grp_2.c create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/bash_trap.sh create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/bash_trap.txt create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_fork_signal.c create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_multi_fork.c create mode 100644 2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_signal.c diff --git a/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/.vscode/settings.json b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/.vscode/settings.json new file mode 100644 index 0000000..ce95e61 --- /dev/null +++ b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "signal.h": "c", + "stdio.h": "c", + "stdlib.h": "c" + } +} \ No newline at end of file diff --git a/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/M311.lnk b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/M311.lnk new file mode 100644 index 0000000000000000000000000000000000000000..456caced55e1eb0f9cdf719f55ac396c13ecacaf GIT binary patch literal 2329 zcmd^9OK1~O6uqfR)rCeHi@(}v3HVDoHJ~*bNX_3&W^`db-)t+pE_S z3FsR&%?MRNuNwSeK!U|8YjY~+#X+l)!m_7E^eW^U)^KKdg*8?!WY*Cdy={lUCqtnI z`{t7n6@y*BgGFImCs^$jm^y|zPi5K9oLBrm;=EJ444igwFpCM;2FwAtH27N%aN7zL z0poyyZ23MeFIgcJ#?Za1`ZYympI1?WvLty$RnKKrwAvf?O4Vxa(5k*o7unF&5##7$ zQ2*!>)n6uG9hEko>qj=D_#D{5I+TP2B^j22d5T(rG{q=^$ffYaVbxO;JS{*9dv2g+ z^g2ByM{Dur7T?~OTyC!vtb%?mXU+|LdfKsP&BZ|7u9cIc3Ru%%!kmI zzTV%hm!S&qXpSBRcZCvBJ_=U`+|=$r`L(~OE7drEKl}|W%+IS57+E1^T97;9zeucB zrqJvJcyq#_rRTGMma%)Vpe}Rd{h1Q@Cj;8%_<;`Poqf}Rscg7-xNd*WKdKcl$Mc+z z!{z9qB(j}C{yFnzoHd5A5%bNoCFe~cj@hOF8r#tCj_2I~@9o6a%?q5_d($pGqCWY_ zjQ)1`=W+lmtpxN+_!nvVdHu0IH$FCR@+M=d3+rCtdC+eGGEwPlXp}AR)AIqZ! Z&-eS&jiPvxc*d5$deUP#KmXI&z5(=JG)e#f literal 0 HcmV?d00001 diff --git a/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demoAlarm b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demoAlarm new file mode 100644 index 0000000000000000000000000000000000000000..2d0b17c5ee3ed8506e65ce0660b64e30d3ad39ac GIT binary patch literal 17008 zcmeHOeQ;b=6~CM9M_SrVfK~%l`m7W~X|^GyC51`Z&F2e~wlPhhDCOlP`;x5eM`rge zCMX&wfV0*>#}CGT96O3L@CP%+8Ak_aAP53F>VPw72f+zgaD#OSeqd3_`aAdCvw8cn ztHVG3<2#x6&ON{Laqm0tzL$IV-TV2jzV4bpKrjWxK|#{#dIyOp#nN@E02UFg;sTs6 z6CW1qAg_^_qmMWYT8AcT%6YBAgW%-%kkWhkhm;+2ZXt21G)c86w3YKIRo{%_>_;N`omYP6l^^p3RUdQC zC*_2Wr&T;J?}UzsIoT5Rzi!8cwD@t80SGn=(CwlQYL6JjzGPuXL_OqiLZFzs|4`q3%V7>mOtey0VIq8VA+ zgiF$lr$kR*Z+nN)5^f3a6GrdgAtPpGtnql(wlaf3ZSP1V8i`7cWHbBX$^7&@$=5l=gA8ld`UgejQ1=2Sj5pY&hnWX9Gvz1>bWfSiyKw6NObrpIv>uF~BSN$YorNHro+qZph*Kh*-w}i~ zN9gR>%lEG%iq?ozAbUEPA`z!V7!q0{J>nDz-&jKZf}a6D1AYel4EP!FGvH^y&%pc5 zfIfS!RzI=!l|4e}_srWh#pm_er)!@og(>cP4XWbKvpCmnkDx^I1nCzSilCh@kxWC= z#pk8`E0Sr*xHvE6pOH*M#l_Q7{xQikL|i;2<;O^-q2c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~Rz z(bB30!S7o(`7y~UY063c%!n(HSGwLmNO?evt9=aef0YP!9!EX;?Z-nPY~^dpp7(|E z|62b7IoZ4Ob4S_dRebrsQpBTwW>Wjz_KWZy*KGAMxdHM@?Qem6EgRXfKWpa9{J=o4 zU(9SI(aogZPg_ZH*hUgd>w}4OUo@e|%yc%VNAtr1|N71(4AY1O@7ul&`%o$w(I%F- z9?fQ>Bf60?vm;_48%-K|ET2q{z{SSturwW}F(aAQ=^x~1m#%jm3h(RGJNI|!*vR5E zjtRZvk^SL)-R(||+%W?YHZbX(5fvfQaY*QUdJeROd-MZcT@QEm>b>E%o=%D?_u2I4 z^0L|QxwD2g@PtD4eK^)`9;Zw)12IiKWd%6?X{9ok{M<_H9Z|oe1Ve zl4i6IXl5-OVhTH*jBG{(Q)$x(hTFOu&FG-w22=T9Up|g4YuFeSByK308xq0TNDA>R zG_#iGaU+|Hr&A6_hc0U*qU4~cOu`gFdF4Tn!ND|G(-_8?`X-Fh@*V|^A=Mj)VhF;V znh>maf#g4Smt)BceC=QPb5@Cv{?-YPuaW8`^*QcGK= z3D@DEu{!(nxR6nU&R+OE$g-^wjALw<)`EWyr|$JrdI#&+Y#l zWRw%0Z_-buEDFiTUZ}11QUGK3*OVXQal0{SS9o#8<$qEcFmii24D*a%clq=0F(Zu| z?1k%R*|$L0+t2d@M)#gR_w~Q1{Q3R~O+{9iP%HztoB8j9p!(V0z3=!zHdN@Y{}q=% z&r2Bj`Qb3``hNxmjpgYXqQc`<-jD3IXP)sj_|)NGf1c+|HBz*h{$_DAJo~=^1@%4l z=lKxt_nx5Spm6_WKfaGN?k5xW=Xuk$E#!so+7^`0?9ccXG +#include +#include +#include +#include + +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 (;;); +} diff --git a/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_kill.c b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_kill.c new file mode 100644 index 0000000..915ad3f --- /dev/null +++ b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_kill.c @@ -0,0 +1,19 @@ +/************************************************/ +/* */ +/* demo_kill.c : Utilisation de la routine kill */ +/* */ +/************************************************/ +# include +# include +# include +# include + +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; +} diff --git a/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_kill_grp_1.c b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_kill_grp_1.c new file mode 100644 index 0000000..60ecbd0 --- /dev/null +++ b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_kill_grp_1.c @@ -0,0 +1,28 @@ +/******************************************************/ +/* DUT INFORMATIQUE - M311 - R. CHIGNOLI */ +/* demo_kill_grp_1.c : Utilisation de la routine kill */ +/******************************************************/ +# include +# include +#include +#include + +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(;;); + } +} diff --git a/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_kill_grp_2.c b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_kill_grp_2.c new file mode 100644 index 0000000..944c787 --- /dev/null +++ b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/Demonstrations/demo_kill_grp_2.c @@ -0,0 +1,32 @@ +/******************************************************/ +/* DUT INFORMATIQUE - M311 - R. CHIGNOLI */ +/* demo_kill_grp_2.c : Utilisation de la routine kill */ +/******************************************************/ +# include +# include +#include +#include + +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); + } +} diff --git a/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/bash_trap.sh b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/bash_trap.sh new file mode 100644 index 0000000..b1bfc7a --- /dev/null +++ b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/bash_trap.sh @@ -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 + diff --git a/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/bash_trap.txt b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/bash_trap.txt new file mode 100644 index 0000000..2dc317e --- /dev/null +++ b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/bash_trap.txt @@ -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 + diff --git a/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_fork_signal.c b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_fork_signal.c new file mode 100644 index 0000000..7b4a496 --- /dev/null +++ b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_fork_signal.c @@ -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�s fork, */ +/* - PERE : Affiche son pid et ppid, */ +/* Ignore le signal SIGINT et le montre */ +/* S'arrete � 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 +# include +# include +# include + +void repSIGINT() { + printf ("\nJ'ignore le signal SIGINT ()\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; +} diff --git a/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_multi_fork.c b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_multi_fork.c new file mode 100644 index 0000000..86cf367 --- /dev/null +++ b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_multi_fork.c @@ -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�s fork, */ +/* - PERE : Affiche son pid et ppid, */ +/* Ignore le signal SIGINT */ +/* S'arrete � 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 : � la fin du scenario, il ne reste que les trois */ +/* sous-fils arretable par envoi de signaux SIGUSR2 */ +/**********************************************************/ + +# include +# include +/**********************/ +/* 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 */ + /**********************/ + } +} diff --git a/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_signal.c b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_signal.c new file mode 100644 index 0000000..e8b3a1c --- /dev/null +++ b/2020-2021/S3T_TP_05_PROCESSUS-4-SIGNAUX/p_signal.c @@ -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 +#include +#include +#include + +/* + +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 ()\n"); +} + +void repSIGINT() { + if(stop == 0) { + kill (getpid(), SIGKILL); + } else { + stop--; + printf ("Je m'arrete au 2eme signal d'interruption ()\n"); + } +} + +void repSIGSEGV() { + printf ("Je m'arrete au premier signal SIGSEGV\n\n"); + kill (getpid(), SIGKILL); +} + +int main(){ + //printf ("\nJ'ignore le signal SIGQUIT ()\n"); + //printf ("Je m'arrete au 2eme signal d'interruption ()\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 (;;); +}