ajout
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -8,12 +9,44 @@
|
||||
|
||||
int is_prime(size_t n)
|
||||
{
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int status;
|
||||
pid_t pid = fork();
|
||||
if(pid < 0) return -1;
|
||||
//Child
|
||||
if(pid == 0){
|
||||
for(size_t i = 2; i < n; i ++){
|
||||
if(n % i == 0 && i != n){
|
||||
printf("Child speaking: my number %zu is not a prime number\n", n);
|
||||
printf("We both say hi!\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
printf("Child speaking: my number %zu is a prime number\n", n);
|
||||
printf("We both say hi!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//daddy milk
|
||||
else{
|
||||
if(waitpid(pid, &status, 0) == -1) return -1;
|
||||
|
||||
if(WIFEXITED(status)){
|
||||
if(WEXITSTATUS(status) == 1) printf("Parent speaking: stop wasting my time of course %zu is a prime number\n", n);
|
||||
else printf("Parent speaking: stop wasting my time of course %zu is not a prime number\n", n);
|
||||
}
|
||||
printf("We both say hi!\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return WEXITSTATUS(status);
|
||||
}
|
||||
/*
|
||||
int salute(int num_guests, char *guests[])
|
||||
{
|
||||
// TODO
|
||||
|
||||
return 0;
|
||||
}
|
||||
}*/
|
||||
|
||||
Reference in New Issue
Block a user