Skip to content

Commit 9d23638

Browse files
Add files via upload
1 parent 4af1147 commit 9d23638

File tree

6 files changed

+61
-4
lines changed

6 files changed

+61
-4
lines changed

TD3/ex5

-104 Bytes
Binary file not shown.

TD3/ex5.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
#include <unistd.h>
66
#include <stdbool.h>
77

8-
int main(int argc, char const *argv[])
8+
void main()
99
{
10-
char nom[50];
10+
/*char nom[50];
1111
char prenom[50];
1212
int res;
1313
printf("Saisissez votre nom suivi de votre prénom : ");
1414
res = scanf("%49s%49s", nom, prenom);
1515
if (res == 2)
1616
printf("Très bien %s %s\n", prenom, nom);
17-
else
17+
else
18+
{
1819
printf("Vous avez fait une erreur lors de la saisie.\n");
20+
}*/
21+
22+
printf("Bonsoir Nom Prénom\n");
1923
}

TD3/ex5_bis.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <unistd.h>
66
#include <stdbool.h>
77

8-
int main(int argc, char const *argv[])
8+
void main()
99
{
1010
printf("Très bien\n");
1111
}

TD3/ex5bis

0 Bytes
Binary file not shown.

TD3/ex6

24 KB
Binary file not shown.

TD3/ex6.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <fcntl.h>
5+
#include <unistd.h>
6+
#include <stdbool.h>
7+
8+
int main(int argc, char const *argv[])
9+
{
10+
int n;
11+
if ((n = fork()) == 0)
12+
{
13+
// Fils 1
14+
// exécution programme ex5
15+
execve("./ex5bis", NULL, NULL);
16+
printf("\n");
17+
// on attends on sait jamais
18+
sleep(1);
19+
exit(0);
20+
}
21+
else
22+
{
23+
if ((n > 0))
24+
{
25+
// père
26+
//printf("Père : Processus père avec PID : %i\n", getpid());
27+
28+
// Création de fils
29+
int n2;
30+
if ((n2 = fork()) == 0)
31+
{
32+
// Fils 2
33+
// exécution programme ex5
34+
execve("./ex5", NULL, NULL);
35+
printf("\n");
36+
// on attends on sait jamais
37+
sleep(1);
38+
exit(0);
39+
}
40+
else if (n2 < 0)
41+
{
42+
printf("Erreur\n");
43+
return -1;
44+
}
45+
}
46+
else
47+
{
48+
// Erreur
49+
printf("Erreur de PID\n");
50+
return -1;
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)