Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <unistd.h>
- void function(int n){
- while(n>0){
- printf("v1 %d\n",getpid());
- pid_t pid = fork();
- if(pid>0){
- waitpid(-1,NULL,0);
- printf("v2 %d\n", getpid());
- exit(EXIT_SUCCESS);
- }
- n--;
- }
- exit(EXIT_SUCCESS);
- }
- int main(int argc, char *argv[]){
- int n = atoi(argv[1]);
- if(n>0){
- function(n);
- }
- else{
- printf("Erreur\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement