Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AyatoKirishima authored Dec 7, 2021
1 parent 4af1147 commit 9d23638
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
Binary file modified TD3/ex5
Binary file not shown.
10 changes: 7 additions & 3 deletions TD3/ex5.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
#include <unistd.h>
#include <stdbool.h>

int main(int argc, char const *argv[])
void main()
{
char nom[50];
/*char nom[50];
char prenom[50];
int res;
printf("Saisissez votre nom suivi de votre prénom : ");
res = scanf("%49s%49s", nom, prenom);
if (res == 2)
printf("Très bien %s %s\n", prenom, nom);
else
else
{
printf("Vous avez fait une erreur lors de la saisie.\n");
}*/

printf("Bonsoir Nom Prénom\n");
}
2 changes: 1 addition & 1 deletion TD3/ex5_bis.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <unistd.h>
#include <stdbool.h>

int main(int argc, char const *argv[])
void main()
{
printf("Très bien\n");
}
Binary file modified TD3/ex5bis
Binary file not shown.
Binary file added TD3/ex6
Binary file not shown.
53 changes: 53 additions & 0 deletions TD3/ex6.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>

int main(int argc, char const *argv[])
{
int n;
if ((n = fork()) == 0)
{
// Fils 1
// exécution programme ex5
execve("./ex5bis", NULL, NULL);
printf("\n");
// on attends on sait jamais
sleep(1);
exit(0);
}
else
{
if ((n > 0))
{
// père
//printf("Père : Processus père avec PID : %i\n", getpid());

// Création de fils
int n2;
if ((n2 = fork()) == 0)
{
// Fils 2
// exécution programme ex5
execve("./ex5", NULL, NULL);
printf("\n");
// on attends on sait jamais
sleep(1);
exit(0);
}
else if (n2 < 0)
{
printf("Erreur\n");
return -1;
}
}
else
{
// Erreur
printf("Erreur de PID\n");
return -1;
}
}
}

0 comments on commit 9d23638

Please sign in to comment.