Merge branch 'master' of https://valarche@dwarves.iut-fbleau.fr/gitiut/valarche/ASR31-valarche-2021.git
This commit is contained in:
31
Exemples/04-Exec/exemple1.c
Normal file
31
Exemples/04-Exec/exemple1.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#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;
|
||||
}
|
Reference in New Issue
Block a user