1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#include "initialisation.h"
#include <locale.h>
#include <pthread.h>
#include <locale.h>
int main(void)
{
char buffer[15];
long threadt;
char TubeNommeZBI[TAILLE_NOM_FIFO]="TUBZBI";
pthread_t threadrecu;
while(1) //boucle infini
{
//ouvertue de tube
if((TubeZBI_fd = open(TubeNommeZBI, O_RDWR )) < 0)
{
fprintf(stderr,"erreur d'ouverture du tube nomme %s\n",TubeNommeZBI);
exit(EXIT_FAILURE);
}
fd_set rfds;
struct timeval tv;
int retval;
//intialisation buffer
memset(buffer,'\0',sizeof(buffer));
FD_ZERO(&rfds);
FD_SET(TubeZBI_fd, &rfds);
// Ecouter pendant 5 seconde
tv.tv_sec = 1;
tv.tv_usec = 0;
printf("Ecoute pendant 5 secondes, TubeZBI_fd=%d\n",TubeZBI_fd);
retval = select(TubeZBI_fd+1, &rfds, NULL, NULL, &tv);
if (retval)
{
// Lire le tube
if (read(TubeZBI_fd, buffer,sizeof(pthread_t))==-1)
{
printf("erreur d'écriture du tube nomme\n");
exit(EXIT_FAILURE);
}
close(TubeZBI_fd);
memcpy(&threadrecu,(pthread_t *) buffer,sizeof(pthread_t));
// fprintf (stdout, "threadt : %s ln:%d\n", buffer,strlen(buffer));
pthread_t threadrecu;
fprintf (stdout, "Threadt : %ld\n", threadrecu);
//Suppression thread
if (pthread_cancel(threadrecu)==0)
{
///Listage
}
}
else
{
puts("Pas de thread");
}
}
return (0);
} |
Partager