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
| #include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/stat.h>
#define BUFSZ 1024
void sig_hand(int sig) {
}
int main(int argc,char *argv) {
char *fic="./fic";
char message[100]="message ecrit par le pere";
pid_t pid;
sigset_t sig_fils;
struct sigaction action;
char buf[BUFSZ];
int descFic;
descFic=open(fic, 0_RDWR);
write(descFic, message, 20);
perror("write");
if((pid=fork()) == 0) {
sigfillset(&sig_fils);
sigdelset(&sig_fils, SIGUSR1);
action.sa_mask=sig_fils;
action.sa_flags=0;
action.sa_handler=sig_hand;
sigaction(SIGUSR1, &action, 0);
sigsuspend(&sig_fils);
read(descFic,buf,BUFSZ);
perror("read");
printf("%s", buf);
}
return 0;
} |
Partager