This commit is contained in:
2025-09-25 13:53:00 +02:00
parent bbb9f49737
commit 87565cf26c
25 changed files with 450 additions and 0 deletions

1
SCR3.1/TP3/Exo2/banane1 Normal file
View File

@@ -0,0 +1 @@
je suis le pereje suis le fils !!!

1
SCR3.1/TP3/Exo2/banane2 Normal file
View File

@@ -0,0 +1 @@
je suis le fils !!!

BIN
SCR3.1/TP3/Exo2/fork_and_fd1 Executable file

Binary file not shown.

View File

@@ -0,0 +1,42 @@
#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 outfd;
pid_t p;
if (argc != 2){
printf("%s file\n",argv[0]);
exit(1);
}
//p=fork();
outfd = open(argv[1],O_WRONLY|O_CREAT,0644);
assert(outfd >= 0);
p=fork();
switch(p){
case (pid_t)-1 :
perror(NULL);
exit(2);
case (pid_t)0 :
write(outfd,msg2,strlen(msg2));
break;
default :
write (outfd,msg1,strlen(msg1));
break;
}
close(outfd);
}

BIN
SCR3.1/TP3/Exo2/fork_and_fd2 Executable file

Binary file not shown.

View File

@@ -0,0 +1,42 @@
#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 outfd;
pid_t p;
if (argc != 2){
printf("%s file\n",argv[0]);
exit(1);
}
p=fork();
outfd = open(argv[1],O_WRONLY|O_CREAT,0644);
assert(outfd >= 0);
//p=fork();
switch(p){
case (pid_t)-1 :
perror(NULL);
exit(2);
case (pid_t)0 :
write(outfd,msg2,strlen(msg2));
break;
default :
write (outfd,msg1,strlen(msg1));
break;
}
close(outfd);
}