Le PETIT avancement

This commit is contained in:
Arnaud NGWALA NGWALA 2023-09-29 12:32:18 +02:00
parent a918c301ce
commit ff442426c1
3 changed files with 46 additions and 0 deletions

24
SCR3.1/TP4/mytimeout.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
void kill_son(int){
if
int main(int argc, char **argv){
if (argc < 3){
printf("Usage : %s <nbsec> <com> [arg]", argv[0]);
return EXIT_FAILURE;
}
int secondes = (int) strtod(argv[1], NULL);
pid_t p;
p = fork();
switch(p){
case 0 :
execl("/usr/bin/sh" , "-c", argv[2])
case -1:
default:

View File

@ -11,9 +11,12 @@ uint64_t shots = 0,
shots_in = 0;
double pi = 0, t1;
sigset_t inset, quiset, alset;
void int_handler(int){
alarm(0);
sigprocmask(SIG_BLOCK, &inset, NULL);
char c;
printf("Le programme tourne depuis %f secondes, voulez-vous vraiment l'arrêter ? (O)ui / (N)on", tstamp() - t1);
c = getchar();
@ -22,21 +25,26 @@ void int_handler(int){
}
else{
return;
sigprocmask(SIG_UNBLOCK, &inset, NULL);
alarm(5);
}
}
void alarm_handler(int){
sigprocmask(SIG_BLOCK, &alset, NULL);
printf("Valeur de pi en cours = %f\n", pi);
printf("Nombre de tirs effectués = %f\n", (double) shots);
alarm(5);
sigprocmask(SIG_UNBLOCK, &alset, NULL);
}
void quit_handler(int){
alarm(0);
sigprocmask(SIG_BLOCK, &quiset, NULL);
shots = 0;
shots_in = 0;
t1 = tstamp();
sigprocmask(SIG_UNBLOCK, &quiset, NULL);
alarm(5);
}
@ -45,6 +53,12 @@ int main(int argc,char * argv[])
double x,y;
t1 = tstamp();
alarm(5);
sigaddset(&alset, SIGINT);
sigaddset(&alset, SIGQUIT);
sigaddset(&inset, SIGALRM);
sigaddset(&inset, SIGQUIT);
sigaddset(&quiset, SIGINT);
sigaddset(&quiset, SIGALRM);
set_signal_handler(SIGALRM, &alarm_handler);
set_signal_handler(SIGINT, &int_handler);
set_signal_handler(SIGQUIT, &quit_handler);

8
SCR3.1/TP4/test.c Normal file
View File

@ -0,0 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
int main(){
int t[4] = {1, 2, 3, 4}, u[2] = t[1:];
return 0;
}