From 2c76beb6856733f812fc62ce1ef79c446caaafef Mon Sep 17 00:00:00 2001 From: boscherl Date: Thu, 21 Oct 2021 16:27:13 +0200 Subject: [PATCH] Controle machine ASR --- CtrlProc-2021/.vscode/settings.json | 5 ++ CtrlProc-2021/Exo2/a.out | Bin 0 -> 16488 bytes CtrlProc-2021/Exo2/pere | Bin 0 -> 16488 bytes CtrlProc-2021/Exo2/pere.c | 77 ++++++++++++++++++++++++++++ CtrlProc-2021/Exo3/exo3 | Bin 0 -> 16696 bytes CtrlProc-2021/Exo3/exo3.c | 63 +++++++++++++++++++++++ 6 files changed, 145 insertions(+) create mode 100644 CtrlProc-2021/.vscode/settings.json create mode 100755 CtrlProc-2021/Exo2/a.out create mode 100755 CtrlProc-2021/Exo2/pere create mode 100644 CtrlProc-2021/Exo2/pere.c create mode 100755 CtrlProc-2021/Exo3/exo3 create mode 100644 CtrlProc-2021/Exo3/exo3.c diff --git a/CtrlProc-2021/.vscode/settings.json b/CtrlProc-2021/.vscode/settings.json new file mode 100644 index 0000000..d4a224b --- /dev/null +++ b/CtrlProc-2021/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "ctype.h": "c" + } +} \ No newline at end of file diff --git a/CtrlProc-2021/Exo2/a.out b/CtrlProc-2021/Exo2/a.out new file mode 100755 index 0000000000000000000000000000000000000000..1cba7066cff2565655c0d87153fb111c479ab512 GIT binary patch literal 16488 zcmeHOYiu0V6~4QU6Z6R0d4YL)8eRtBjT4g80bFJs+ZneGq=^l!nq<7*9ows}cbDDS zU?Tw*E)lEX619l(gI1vur65t!r=b0T!6;R#C{3tT+=MDt1ns(|U;U>< z$!?V*wZGh<^20DT7xkS}<}C5z((wnO>wcjDpSs{i;z#vKt?v zelW7W*q(;YP&9cg;!|hM8$>lwPqa9_wGfc2zvu6ptmcBTXYM>zmfE4Q7(THL?rXuV(n*nA&t_ zukeqFN#xkyCwwKcpJXtR1#OqZ2h)!Juhvc1KGb#T(ycEXoX+&l-2TKz51v9B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D;l=Lv`?Z` zxJ6P zQPLK68-5!v;c)jy31OPBAA_@x8#T)AzEB%MN*r+uNeNN9JETN~TTDs_5zLGZ+u?pd zJFRetYq0agN~c6n4(7o`Hke8$;q2^D2i2dA!Hy@`lA^3aZCy<`+=FO76wVBZV01JA zO(?X}O0&yKXJW}jiC}^*ZN(PtkzG`!GHObAR~$iN9ZP-=SJ8+B#MJi7Pm_%Z51JFXw;g Ni^}2>mxD_b{|1@qV)_68 literal 0 HcmV?d00001 diff --git a/CtrlProc-2021/Exo2/pere.c b/CtrlProc-2021/Exo2/pere.c new file mode 100644 index 0000000..a13487e --- /dev/null +++ b/CtrlProc-2021/Exo2/pere.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include +#include +#include + +/* Je laisse volontairement cette fonction statique, qui empêche mon programme de fonctionner car je n'ai pas complété l'exercice, elle +aurait normalement servie à afficher le premier processus à avoir terminer grâce aux signaux + +static void first_proc(int sig); + +static void first_proc(int sig){ + switch (sig){ + case SIGUSR1: + printf("Le premier fils a terminé en premier"); + break; + + case SIGUSR2: + printf("Le second fils a terminé en premier"); + break; + + default: + break; + + } +}*/ + +int main(int argc, char *argv[]){ + pid_t pid1, pid2; + + pid1 = fork(); + + pid2 = fork(); + + /* De même que plus haut dans mon programme, il s'agit ici de la gestion d'erreur dans le cas ou ma fonction fonctionnait + + if(signal(SIGUSR1,first_proc) == SIG_ERR) { + perror("Error sig"); + exit(-1); + } + + if(signal(SIGUSR2,first_proc) == SIG_ERR) { + perror("Error sig"); + exit(-1); + } */ + + if(pid1==0) { + printf("Processus père de pid : %d, avec fils1 de pid : %d\n", getpid(), getppid()); + if(execlp("ls", "ls", "-l", NULL) == -1) { + perror("exec"); + exit(-1); + } + } else { + wait(NULL); + } + + printf("\n"); + + if(pid2==0){ + printf("Processus père de pid : %d, avec fils2 de pid : %d\n", getpid(), getppid()); + if(execlp("ps", "ps", "-l", NULL) == -1) { + perror("exec"); + exit(-1); + } + } else { + wait(NULL); + } + + printf("\n"); + + return EXIT_SUCCESS; +} + + + diff --git a/CtrlProc-2021/Exo3/exo3 b/CtrlProc-2021/Exo3/exo3 new file mode 100755 index 0000000000000000000000000000000000000000..e003cae7b02d69d0687709ae9bfa0bbd18c83a47 GIT binary patch literal 16696 zcmeHOeQ+Da6<^7AVm=}nNK*3=as*7B6f1U|cpRwVWLwU;wMm*d0b0UEmd>^&vgAtV z#AYVNt(pv~Ye<=Cp-kEd{6RA<%uq@p159yh>Xf!q!pDH2bkHz_N=*v}0yPw(zPGpU ze7Z;-${+oQ+vM);`@N6dd$+sZ)$QIA=<0C0T#Ql~yP9$C90QSs;P86VU`%GsY!Tcq zX3N+DfXm^Mh1gDK+=hT?rO+z_igwkQDMBwYU`CW`h!pKgr8!XmQC4MWqFn`M1#hSC z3#UX$Zk8vZF(irKO?ns=AQ83NVQjK>T+Fg9h4he!%Y%ZF9kOUQC+y~g9np*^k0`|x ztB+T+h^L*(Aj2f{J7adc5n*Si?Lwa@mVs%@aXtK5%G)ID4och&v(vQ(%!pEXUjsXg z%co8Bnm3E`O1+0_5r3j0ylize(%ZClbu?TTjl_mW>PDKI>YCR2l5yV}UInaIJzUtP zHe9=vxyRTfVr1`Pt^(dIcu?U9br-{hVMqJ3s&_3r`t5%$ZEAdL+fTe{Z*O>2H|pSX zpik7ngcx3wP(~MFpN2jFN>UNUJ%F8C1jpuB49EUi49E9Z4Bu7)KdS`ZRs!Ey0)HBC z2`+oWI2NnVRV8qYX)*m7z$Lis3EO5d{Tl&aVOIwJ3nlcG5;)UFB0Ae0gxgSLNMl1< zA`wrpzIb9MQ`Mv%4DD1y13T5eU?j@=HGL=&W61;y4#}hnAQ{QjiUGd!FWt~R}IyoiWoFE{43*k%wbn8q~*}| z%UB9<>hI@8B8#wxObBc-=gZigf*-yhat3<22Y5_0F4K58EB@}yigB0lg95)*=4R&j zN&L(;29E6j+YY6S1&4yol(pbznkZwl7TjaO=PWoqD~hXSLunxpF_dvYvfyH9=Xk9J zw~izA7M%Z`+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iQHx zZ#jD>Zx_P{Q1~gJoE;DWmW0AmpvCl;mB4EOcQX&Gw{9u~Y?Z)w*l^r7iu%;gfaPfm z++FN^wqG`QY8NWU7c=TNhLo{=kU>AxZwbGH>z`-tTP6ILkojMp3qRAkV8`;qmym~f zTFlQh7oT@pJzwH}mN0ue$_RZLFE|Ug_ju+UbKgJV3m_ma?3FSh25o|l?8ec_)?O|G z{c|Bc8PTz6Jh=jJsn7-IKHzvY8THs#>Kd4XrMZioE{y!A@{5Lodc5|Gx=IM?S zxLyL^3phTnz1$xFF3r0&bH6Cz=Lx`9m|F9hmrCeoOW-Wn8>x%Mbfa#b#zbS5hFtb1MZv!MPMu(#V)E zIXb8Zdx7c+gAPy*PPb@@A?D-Vqdzw68%o6C5%p0E)H@u3GhA@`#nAG%cGh7B@}c@b zFgd_{;n5frVNg9`NOoz7WF#IdU{sJLv}h0wL~bamGanDNPuE5uj~xeOao&u4+JNXP z17WZw&ag20jA21}a2yQ5j^`MDuCFnjmAf9})IM@jHt((cc%sIw51Vr+FSx zi4+C3+g}Ix2QUYx`qR3EC_TTJuAA!tavOvUZYm{vTDK7WJq8yN))BMx{Iq_E0EUlD z_OuQn`Yy<(0MaDC8)sQDYk&Sb0Ym#%6hfLLJ3(pPhSh>u;c52w0ERK4=fkN8PlD3=RG_>p z$|F4hm(^Ypc0@C%WJxyn>}Mde+SB}n=yB1W$pzUH|A5V&=8Z&Q(`iAnx8Gk0do%u$ zP#5&4f+a%nC;oBBVExJdpkzpht~FTmZZH37kXY?!Btw;G#$e66z5M4v0<%8e2T+OD z33N`^u1`GC*TBYWv8VOZY#n-=Z!ZQn&y)QL5MbM(*F@_VI(MDHhl3=VquKuGJ)Q&^ zs*pXM|C +#include +#include +#include +#include +#include + +/* Ce programme n'est pas complet : j'arrive à récupérer les chiffres et lettres +sur la sortie standard (sauf la première étrangement) mais je n'ai pas le temps pour le terminer */ + + +int main(int argc, char *argv[]){ + pid_t pid1, pid2; + char a; + int tube[2], l=0, c=0; + + pid1 = fork(); + pid2 = fork(); + + if(pipe (tube) != 0){ + perror("error pipe"); + exit(-1); + } + + if(pid1 == 0){ + printf("Processus père de pid : %d, avec fils1 de pid : %d\n", getpid(), getppid()); + close(tube[1]); + while(read (tube[0], &a, 1) > 0){ + if(isdigit (a)){ + c++; + } else if (isalnum(a)) { + l = l; + } + printf("%d chiffres\n", c); + } + } + else if (pid2 == 0){ + printf("Processus père de pid : %d, avec fils2 de pid : %d\n", getpid(), getppid()); + close(tube[1]); + while(read (tube[0], &a, 1) > 0){ + if(isalnum(a)){ + l++; + } else if (isdigit (a)){ + c = c; + } + printf("%d lettres\n", l); + + } + } + else { + close (tube[0]); + while (read (0, &a, 1) >0) + if (isalnum(a)) + write (tube[1], &a, 1); + + close(tube[1]); + wait(NULL); + } + + + return EXIT_SUCCESS; +} +