ASR31-valarche-2021/Exemples/04-Exec/exemple1.c

31 lines
516 B
C
Raw Normal View History

2021-09-29 12:15:32 +02:00
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/wait.h>
int main(int argc, char *argv[]) {
int pid, fp, i, j;
char ch[4];
fp = open("fichier", O_RDWR);
pid = fork();
if (pid == 0) {
for (i = 0; i < 4; i++) {
read(fp, ch, 4);
printf("hello fils : %s\n", ch);
sleep(4);
}
} else {
for (j = 0; j < 3; j++) {
read(fp, ch, 4);
printf("Hello père : %s\n", ch);
sleep(5);
}
wait(NULL);
close(fp);
}
return 1;
}