add TP03 SCR
This commit is contained in:
15
SCR/SCR3.1/TP03/Exercise3/answer.txt
Normal file
15
SCR/SCR3.1/TP03/Exercise3/answer.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
-> Le code de cet exercice permet de copier le contenu d'un fichier dans un autre fichier.
|
||||
|
||||
-> Quand on décommente le fork(), il y a des entrelacements possibles duent à l'exécution simultanée des processus.
|
||||
|
||||
Lecture Père = LP
|
||||
Ecriture Père = EP
|
||||
|
||||
Lecture Fils = LF
|
||||
Ecriture Fils = EF
|
||||
|
||||
Il y a plusieurs combinaisons possibles qui peuvent arriver :
|
||||
|
||||
- LP (a) -> LF (b) -> EF (b) -> EP (a)
|
||||
- LP (a) -> EP (a) -> LF (b) -> EF (b)
|
||||
- etc...
|
45
SCR/SCR3.1/TP03/Exercise3/copy1byte.c
Normal file
45
SCR/SCR3.1/TP03/Exercise3/copy1byte.c
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include<stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include<assert.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#define msg1 "je suis le pere"
|
||||
#define msg2 "je suis le fils !!!"
|
||||
|
||||
int main(int argc,char * argv[]){
|
||||
|
||||
int infd,outfd;
|
||||
ssize_t nbread;
|
||||
char buf[1];
|
||||
pid_t p;
|
||||
|
||||
if (argc != 3){
|
||||
|
||||
printf("%s infile outfile\n",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
infd = open(argv[1],O_RDONLY);
|
||||
assert(infd >= 0);
|
||||
outfd = open(argv[2],O_WRONLY|O_CREAT|O_TRUNC,0644);
|
||||
assert(outfd >= 0);
|
||||
|
||||
p=fork(); // <- decommentez cette ligne
|
||||
|
||||
while(1){
|
||||
|
||||
nbread=read(infd,buf,sizeof(buf));
|
||||
if (nbread <=0 ) break;
|
||||
write(outfd,buf,sizeof(buf));
|
||||
|
||||
}
|
||||
|
||||
|
||||
close(infd);
|
||||
close(outfd);
|
||||
}
|
1
SCR/SCR3.1/TP03/Exercise3/test
Normal file
1
SCR/SCR3.1/TP03/Exercise3/test
Normal file
@@ -0,0 +1 @@
|
||||
je m'appelle nathan
|
1
SCR/SCR3.1/TP03/Exercise3/testdetest
Normal file
1
SCR/SCR3.1/TP03/Exercise3/testdetest
Normal file
@@ -0,0 +1 @@
|
||||
je map'pelle nathan
|
Reference in New Issue
Block a user