diff --git a/SCR/SCR3.1/TP03/Exercise1/answer.txt b/SCR/SCR3.1/TP03/Exercise1/answer.txt new file mode 100644 index 0000000..f1e8899 --- /dev/null +++ b/SCR/SCR3.1/TP03/Exercise1/answer.txt @@ -0,0 +1,10 @@ + PID PPID COMMAND S + 4331 1423 bash S + 4732 4331 \_ a.out S + 4733 4732 \_ a.out S + 4736 4733 | \_ a.o S + 4737 4733 | \_ a.o S + 4734 4732 \_ a.out S + 4735 4732 \_ a.out S + +-> Il y aura donc 6 appels à a.out. diff --git a/SCR/SCR3.1/TP03/Exercise1/main.c b/SCR/SCR3.1/TP03/Exercise1/main.c new file mode 100644 index 0000000..7b6bb58 --- /dev/null +++ b/SCR/SCR3.1/TP03/Exercise1/main.c @@ -0,0 +1,16 @@ +#include +#include +# include +# include + +int main() { + fork(); + + if (fork()){ + fork(); + } + + printf("A\n"); + + sleep(20); +} diff --git a/SCR/SCR3.1/TP03/Exercise2/answer.txt b/SCR/SCR3.1/TP03/Exercise2/answer.txt new file mode 100644 index 0000000..59c5814 --- /dev/null +++ b/SCR/SCR3.1/TP03/Exercise2/answer.txt @@ -0,0 +1,6 @@ +[baudrier@salle229-06 Exercise2]$ gcc ex1-stdio.c +[baudrier@salle229-06 Exercise2]$ ./a.out +NONOUI +NON[baudrier@salle229-06 Exercise2]$ gcc ex1-syscall.c +[baudrier@salle229-06 Exercise2]$ ./a.out +NONOUI \ No newline at end of file diff --git a/SCR/SCR3.1/TP03/Exercise2/ex1-stdio.c b/SCR/SCR3.1/TP03/Exercise2/ex1-stdio.c new file mode 100644 index 0000000..4bc5de2 --- /dev/null +++ b/SCR/SCR3.1/TP03/Exercise2/ex1-stdio.c @@ -0,0 +1,12 @@ +#include +#include +#include + + +int main(){ + + printf("NON"); + if (fork()) { + printf("OUI\n"); + } +} diff --git a/SCR/SCR3.1/TP03/Exercise2/ex1-syscall.c b/SCR/SCR3.1/TP03/Exercise2/ex1-syscall.c new file mode 100644 index 0000000..1b46b6a --- /dev/null +++ b/SCR/SCR3.1/TP03/Exercise2/ex1-syscall.c @@ -0,0 +1,14 @@ +#include +#include +#include + + +int main(){ + + //printf("NON"); + write(STDOUT_FILENO,"NON",3); + if (fork()) { + //printf("OUI\n"); + write(STDOUT_FILENO,"OUI\n",4); + } +} diff --git a/SCR/SCR3.1/TP03/Exercise3/answer.txt b/SCR/SCR3.1/TP03/Exercise3/answer.txt new file mode 100644 index 0000000..8cb89f0 --- /dev/null +++ b/SCR/SCR3.1/TP03/Exercise3/answer.txt @@ -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... \ No newline at end of file diff --git a/SCR/SCR3.1/TP03/Exercise3/copy1byte.c b/SCR/SCR3.1/TP03/Exercise3/copy1byte.c new file mode 100644 index 0000000..fab6100 --- /dev/null +++ b/SCR/SCR3.1/TP03/Exercise3/copy1byte.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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); +} diff --git a/SCR/SCR3.1/TP03/Exercise3/test b/SCR/SCR3.1/TP03/Exercise3/test new file mode 100644 index 0000000..97fea1e --- /dev/null +++ b/SCR/SCR3.1/TP03/Exercise3/test @@ -0,0 +1 @@ +je m'appelle nathan \ No newline at end of file diff --git a/SCR/SCR3.1/TP03/Exercise3/testdetest b/SCR/SCR3.1/TP03/Exercise3/testdetest new file mode 100644 index 0000000..9e2e36b --- /dev/null +++ b/SCR/SCR3.1/TP03/Exercise3/testdetest @@ -0,0 +1 @@ +je map'pelle nathan \ No newline at end of file diff --git a/SCR/SCR3.1/TP03/Exercise4/rebours.c b/SCR/SCR3.1/TP03/Exercise4/rebours.c new file mode 100644 index 0000000..fd16bbe --- /dev/null +++ b/SCR/SCR3.1/TP03/Exercise4/rebours.c @@ -0,0 +1,12 @@ +#include +#include +#include +#include + +int main(int argc, char* argv[]) { + assert(argc == 2); + + long i = strtol(argv[1], NULL, 10); + + return EXIT_SUCCESS; +}