update
This commit is contained in:
107
SCR/controle/devoir39/TaF39
Normal file
107
SCR/controle/devoir39/TaF39
Normal file
@@ -0,0 +1,107 @@
|
||||
Créez un répertoire cntr_r3.05, et pour chaque exercice un sous-répertoire (Ex1,
|
||||
Ex2, etc.) pour y placer vos réponses.
|
||||
|
||||
Les exercices sont indépendants. Vous rendrez une archive compressée à la fin de
|
||||
l'épreuve sur le site :
|
||||
|
||||
http://www.iut-fbleau.fr/site/site/DEVOIR
|
||||
|
||||
# EX1
|
||||
1) Ecrivez un programme gdf1.c qui implante le diagramme de processus
|
||||
conforme à la sortie suivante de la commande ps :
|
||||
|
||||
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
|
||||
0 S 1000 28865 28785 0 80 0 - 1039 hrtime pts/0 00:00:00 a.out
|
||||
1 S 1000 28868 28865 0 80 0 - 1039 hrtime pts/0 00:00:00 \_ a.out
|
||||
1 S 1000 28871 28868 0 80 0 - 1039 hrtime pts/0 00:00:00 | \_ a.out
|
||||
1 S 1000 28870 28865 0 80 0 - 1039 hrtime pts/0 00:00:00 \_ a.out
|
||||
1 S 1000 28873 28870 0 80 0 - 1039 hrtime pts/0 00:00:00 | \_ a.out
|
||||
1 S 1000 28872 28865 0 80 0 - 1039 hrtime pts/0 00:00:00 \_ a.out
|
||||
|
||||
2) Expliquez (dans gdf2.txt) ce que provoque kill -TERM 28865.
|
||||
|
||||
3) Modifiez votre programme (gfd3.c) pour que le processus correspondant à 28873 utilise un
|
||||
tube pour communiquer son PID au processus correspondant à 28871.
|
||||
|
||||
# EX2
|
||||
Le sous-repertoire 'src/' de votre répértoire de travail contient le source du
|
||||
programme 'cachetst.c'. Ce programme peut être utilisé pour tester certaines
|
||||
propriétés de la mémoire cache. Il crée une liste de structures et effectue
|
||||
plusieurs passages par cette liste en faisant un test sur chaque élément.
|
||||
|
||||
La longueur de la liste et le nombre de passages (itérations) doivent être
|
||||
donnsés sur la ligne de commande. Compilez et lancez ce programme avec par
|
||||
exemple les valeurs '1000' '1000' sur la ligne de commande pour voir ce qu'il
|
||||
calcule. Augmentez ces valeurs en prenant '10000' '100000' pour voir que le
|
||||
temps de calcul est assez long.
|
||||
|
||||
Votre travail consiste à rajouter une partie de code à ce programme (appelez le
|
||||
'vcachetst.c') pour qu'il affiche chaque seconde le nombre de tests actuellement
|
||||
passés (la valeur de la variable 'z').
|
||||
|
||||
Mettez le source du programme 'vcachetst.c' dans le sous-repertoire 'src/'
|
||||
|
||||
# EX3
|
||||
Un groupe d'étudiants en informatique révise son contrôle machine de scr. Ils ne
|
||||
peuvent réviser qu'en mangeant de la pizza. Chaque étudiant exécute en boucle :
|
||||
|
||||
```c
|
||||
while(1){
|
||||
|
||||
prendre_une_part_de_pizza();
|
||||
reviser_et_manger_la_part_de_pizza();
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
Quand il n'y a plus de pizza, les étudiants dorment. Celui qui prend la dernière
|
||||
part commande une nouvelle pizza.
|
||||
|
||||
Écrire un programme en C qui crée les processus fils étudiants (leur nombre est
|
||||
passé à la ligne de commande). Les parts de pizza, numérotés de 1 à 8, sont
|
||||
placées dans un tube par le pére. Les fils connsomment chaque part depuis le
|
||||
tube. Un autre tube permet à celui qui prend la dernière part d'en commander une
|
||||
autre.
|
||||
|
||||
Exemple de trace d'exécution
|
||||
|
||||
```
|
||||
[denis@portabledenis test]$ ./pizza 10
|
||||
student 1 takes piece 1
|
||||
student 8 takes piece 2
|
||||
student 0 takes piece 3
|
||||
student 3 takes piece 4
|
||||
student 9 takes piece 5
|
||||
student 2 takes piece 6
|
||||
student 4 takes piece 7
|
||||
student 5 takes piece 8
|
||||
student 5 orders a pizza
|
||||
pizza ordered!
|
||||
pizza delivered!
|
||||
student 6 takes piece 1
|
||||
student 7 takes piece 2
|
||||
student 9 takes piece 3
|
||||
student 0 takes piece 4
|
||||
student 5 takes piece 5
|
||||
student 2 takes piece 6
|
||||
student 1 takes piece 7
|
||||
student 6 takes piece 8
|
||||
student 6 orders a pizza
|
||||
pizza ordered!
|
||||
pizza delivered!
|
||||
student 4 takes piece 1
|
||||
student 3 takes piece 2
|
||||
student 8 takes piece 3
|
||||
student 7 takes piece 4
|
||||
student 9 takes piece 5
|
||||
student 5 takes piece 6
|
||||
student 2 takes piece 7
|
||||
student 6 takes piece 8
|
||||
student 6 orders a pizza
|
||||
pizza ordered!
|
||||
pizza delivered!
|
||||
student 0 takes piece 1
|
||||
student 8 takes piece 2
|
||||
student 7 takes piece 3
|
||||
...
|
||||
```
|
BIN
SCR/controle/devoir39/alexisWAMSTER_SCR3_05.tar.gz
Normal file
BIN
SCR/controle/devoir39/alexisWAMSTER_SCR3_05.tar.gz
Normal file
Binary file not shown.
BIN
SCR/controle/devoir39/cntr_r3.05/Ex1/exe
Executable file
BIN
SCR/controle/devoir39/cntr_r3.05/Ex1/exe
Executable file
Binary file not shown.
17
SCR/controle/devoir39/cntr_r3.05/Ex1/gdf1.c
Normal file
17
SCR/controle/devoir39/cntr_r3.05/Ex1/gdf1.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
int main(){
|
||||
int i;
|
||||
int x1, x2;
|
||||
for (i=0; i<3; i++){
|
||||
x1 = fork();
|
||||
if (i<2 && x1==0){
|
||||
x2 = fork();
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
12
SCR/controle/devoir39/cntr_r3.05/Ex1/gdf2.txt
Normal file
12
SCR/controle/devoir39/cntr_r3.05/Ex1/gdf2.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
kill -TERM 28865
|
||||
Cette commande permet de tuer le processus ayant pour PID 28865. Dans l'exemple ce processus correspond au main (le père de tous).
|
||||
Ainsi ses 3 enfants se retrouverons orphelin et seront adopter par le pid 1. on aurais donc l'arbre suivant:
|
||||
|
||||
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
|
||||
0 S 1000 1 1 0 80 0 - 1039 hrtime pts/0 00:00:00 1
|
||||
1 S 1000 28868 28865 0 80 0 - 1039 hrtime pts/0 00:00:00 \_ a.out
|
||||
1 S 1000 28871 28868 0 80 0 - 1039 hrtime pts/0 00:00:00 | \_ a.out
|
||||
1 S 1000 28870 28865 0 80 0 - 1039 hrtime pts/0 00:00:00 \_ a.out
|
||||
1 S 1000 28873 28870 0 80 0 - 1039 hrtime pts/0 00:00:00 | \_ a.out
|
||||
1 S 1000 28872 28865 0 80 0 - 1039 hrtime pts/0 00:00:00 \_ a.out
|
||||
|
34
SCR/controle/devoir39/cntr_r3.05/Ex1/gdf3.c
Normal file
34
SCR/controle/devoir39/cntr_r3.05/Ex1/gdf3.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
int main(){
|
||||
int i;
|
||||
int x1, x2;
|
||||
int ecrit, lu;
|
||||
int p[2];
|
||||
|
||||
pipe(p);
|
||||
for (i=0; i<3; i++){
|
||||
x1 = fork();
|
||||
if (i==0 && x1==0){
|
||||
x2 = fork();
|
||||
if (x2 == 0){
|
||||
read(p[0],&lu,sizeof(int));
|
||||
printf("%d received %d\n", getpid(), lu);
|
||||
close(p[0]);
|
||||
}
|
||||
}
|
||||
if (i==1 && x1==0){
|
||||
x2 = fork();
|
||||
if (x2==0){
|
||||
ecrit = getpid();
|
||||
write(p[1],&ecrit,sizeof(int));
|
||||
close(p[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
87
SCR/controle/devoir39/cntr_r3.05/Ex2/cachetst.c
Normal file
87
SCR/controle/devoir39/cntr_r3.05/Ex2/cachetst.c
Normal file
@@ -0,0 +1,87 @@
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <x86intrin.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define PLSIZE 63
|
||||
|
||||
|
||||
|
||||
struct lst {
|
||||
struct lst * next;
|
||||
long int payload[PLSIZE];
|
||||
} l;
|
||||
|
||||
|
||||
struct lst * mkws(int size)
|
||||
{
|
||||
int i,j;
|
||||
struct lst * ws0,*ws;
|
||||
|
||||
if (size == 0)
|
||||
return NULL;
|
||||
|
||||
srand(time(0));
|
||||
ws = calloc(1,sizeof(struct lst));
|
||||
ws->next = NULL;
|
||||
|
||||
for (i=0;i<PLSIZE;i++)
|
||||
ws->payload[i]=(rand())%2;
|
||||
|
||||
for (j=1;j<size;j++) {
|
||||
ws0=ws;
|
||||
ws = calloc(1,sizeof(struct lst));
|
||||
if (ws==NULL) {
|
||||
fprintf(stderr,"Can't add element...\n");
|
||||
exit(1);
|
||||
}
|
||||
for (i=0;i<PLSIZE;i++)
|
||||
ws->payload[i]=(rand())%2;
|
||||
ws->next = ws0;
|
||||
}
|
||||
return ws;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
struct lst * ws, * ws0;
|
||||
|
||||
long long int start, end, dif;
|
||||
|
||||
long int i, x, z = 0, size, it;
|
||||
|
||||
if (argc != 3) {
|
||||
printf("Usage: %s <list size> <iterations>\n",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
size=strtol(argv[1],NULL,0);
|
||||
|
||||
ws = mkws(size);
|
||||
if (ws == NULL) {
|
||||
printf("NIL list created...\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
it = strtol(argv[2],NULL,0);
|
||||
|
||||
start = __rdtsc();
|
||||
for (i = 0; i < it; i++) {
|
||||
ws0 = ws;
|
||||
while (ws0 != NULL) {
|
||||
x = ws0->payload[3];
|
||||
x++;
|
||||
z++;
|
||||
ws0 = ws0->next;
|
||||
}
|
||||
}
|
||||
end = __rdtsc();
|
||||
|
||||
dif = end - start;
|
||||
printf("Cycles/element = %lf\n", ((double) dif)/((double) size*it));
|
||||
exit(0);
|
||||
}
|
BIN
SCR/controle/devoir39/cntr_r3.05/Ex2/exe
Executable file
BIN
SCR/controle/devoir39/cntr_r3.05/Ex2/exe
Executable file
Binary file not shown.
104
SCR/controle/devoir39/cntr_r3.05/Ex2/vcachetst.c
Normal file
104
SCR/controle/devoir39/cntr_r3.05/Ex2/vcachetst.c
Normal file
@@ -0,0 +1,104 @@
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <x86intrin.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define PLSIZE 63
|
||||
|
||||
int z=0;
|
||||
|
||||
//ce bloc de code vient d'un exercice de tp que j'ai recuperer
|
||||
int set_signal_handler(int signo, void (*handler)(int)) {
|
||||
struct sigaction sa;
|
||||
sa.sa_handler = handler; // call `handler` on signal
|
||||
sigemptyset(&sa.sa_mask); // don't block other signals in handler
|
||||
sa.sa_flags = SA_RESTART; // restart system calls
|
||||
return sigaction(signo, &sa, NULL);
|
||||
}
|
||||
|
||||
void sig_alarm(int signum){
|
||||
printf("nombre de tests actuellement passes : %d\n",z);
|
||||
alarm(1);
|
||||
}
|
||||
|
||||
struct lst {
|
||||
struct lst * next;
|
||||
long int payload[PLSIZE];
|
||||
} l;
|
||||
|
||||
|
||||
struct lst * mkws(int size)
|
||||
{
|
||||
int i,j;
|
||||
struct lst * ws0,*ws;
|
||||
|
||||
if (size == 0)
|
||||
return NULL;
|
||||
|
||||
srand(time(0));
|
||||
ws = calloc(1,sizeof(struct lst));
|
||||
ws->next = NULL;
|
||||
|
||||
for (i=0;i<PLSIZE;i++)
|
||||
ws->payload[i]=(rand())%2;
|
||||
|
||||
for (j=1;j<size;j++) {
|
||||
ws0=ws;
|
||||
ws = calloc(1,sizeof(struct lst));
|
||||
if (ws==NULL) {
|
||||
fprintf(stderr,"Can't add element...\n");
|
||||
exit(1);
|
||||
}
|
||||
for (i=0;i<PLSIZE;i++)
|
||||
ws->payload[i]=(rand())%2;
|
||||
ws->next = ws0;
|
||||
}
|
||||
return ws;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
struct lst * ws, * ws0;
|
||||
|
||||
long long int start, end, dif;
|
||||
|
||||
long int i, x, size, it;
|
||||
|
||||
if (argc != 3) {
|
||||
printf("Usage: %s <list size> <iterations>\n",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
set_signal_handler(SIGALRM,sig_alarm);
|
||||
alarm(1);
|
||||
|
||||
size=strtol(argv[1],NULL,0);
|
||||
|
||||
ws = mkws(size);
|
||||
if (ws == NULL) {
|
||||
printf("NIL list created...\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
it = strtol(argv[2],NULL,0);
|
||||
|
||||
start = __rdtsc();
|
||||
for (i = 0; i < it; i++) {
|
||||
ws0 = ws;
|
||||
while (ws0 != NULL) {
|
||||
x = ws0->payload[3];
|
||||
x++;
|
||||
z++;
|
||||
ws0 = ws0->next;
|
||||
}
|
||||
}
|
||||
end = __rdtsc();
|
||||
|
||||
dif = end - start;
|
||||
printf("Cycles/element = %lf\n", ((double) dif)/((double) size*it));
|
||||
exit(0);
|
||||
}
|
BIN
SCR/controle/devoir39/cntr_r3.05/Ex3/exe
Executable file
BIN
SCR/controle/devoir39/cntr_r3.05/Ex3/exe
Executable file
Binary file not shown.
80
SCR/controle/devoir39/cntr_r3.05/Ex3/pizza.c
Normal file
80
SCR/controle/devoir39/cntr_r3.05/Ex3/pizza.c
Normal file
@@ -0,0 +1,80 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
/*
|
||||
//ce bloc de code vient d'un exercice de tp que j'ai recuperer
|
||||
int set_signal_handler(int signo, void (*handler)(int)) {
|
||||
struct sigaction sa;
|
||||
sa.sa_handler = handler; // call `handler` on signal
|
||||
sigemptyset(&sa.sa_mask); // don't block other signals in handler
|
||||
sa.sa_flags = SA_RESTART; // restart system calls
|
||||
return sigaction(signo, &sa, NULL);
|
||||
}
|
||||
|
||||
void sig_hand(int sig) {
|
||||
}*/
|
||||
|
||||
void commander_une_pizza(int* p){
|
||||
int i;
|
||||
|
||||
printf("pizza ordered!\n");
|
||||
for (i=1; i<=8; i++){
|
||||
write(p[1],&i,sizeof(int));
|
||||
}
|
||||
printf("pizza delivered!\n");
|
||||
//kill(getppid(), SIGUSR1);
|
||||
}
|
||||
|
||||
|
||||
void prendre_une_part_de_pizza(int numEtudiant, int* p){
|
||||
int numPartPizza;
|
||||
read(p[0],&numPartPizza,sizeof(int));
|
||||
printf("student %d takes piece %d\n",numEtudiant, numPartPizza);
|
||||
//rendre atomique cette partie (mais je n'y arrive pas)
|
||||
if (numPartPizza == 8){
|
||||
commander_une_pizza(p);
|
||||
}
|
||||
else{
|
||||
//kill(getppid(), SIGUSR1);
|
||||
}
|
||||
}
|
||||
|
||||
void reviser_et_manger_la_part_de_pizza(void){
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char ** argv){
|
||||
int Nbetudiant;
|
||||
int i;
|
||||
int pid;
|
||||
int p[2];
|
||||
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s <NbEtudiants>\n",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Nbetudiant = strtol(argv[1],NULL,0);
|
||||
//set_signal_handler(SIGUSR1,sig_hand);
|
||||
|
||||
pipe(p);
|
||||
commander_une_pizza(p);
|
||||
|
||||
for (i=0; i<Nbetudiant; i++){
|
||||
pid = fork();
|
||||
if (pid == 0){
|
||||
while (1){
|
||||
prendre_une_part_de_pizza(i, p);
|
||||
reviser_et_manger_la_part_de_pizza();
|
||||
}
|
||||
}
|
||||
}
|
||||
while (1){
|
||||
// le professeur dort pendant que les eleves revises
|
||||
sleep(1);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user