Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1 #include <stdio.h>
  2. 2 #include <stdlib.h>
  3. 3 #include <unistd.h>
  4. 4 #include <sys/types.h>
  5. 5 #include <string.h>
  6. 6 #include <inttypes.h>
  7. 7
  8. 10
  9. 11 int main(int argc, char* argv[])
  10. 12 {
  11. 13 int child_pid;
  12. 14 int count = 0;
  13. 16 int n = 0;
  14. 17 int i;
  15. 18 char bufor[1024], tmp[1024];
  16.  
  17. sprintf(tmp, "%d ", getpid());
  18. strcpy(bufor, argv[2]);
  19. strcat(bufor, tmp);
  20.  
  21. 21 n = atoi(argv[1]);
  22.  
  23. 27 for (i = 0; i < n; i++) {
  24. 29 child_pid = fork();
  25. 30
  26. 31 if (child_pid == 0) {
  27. 47 //char* args[] = { argv[0], n - 1, bufor, NULL };
  28. 48 //execv(args[0], args);
  29. 49 }
  30. 50 }
  31. 51
  32. 52 for (i = 0; i < n; i++) {
  33. 53 int a;
  34. 54 wait(&a);
  35. 55 }
  36. 56
  37. 57 printf("Rodzic: %i\n", getppid());
  38. 58 printf("Potomek: %i\n", getpid());
  39. 61 return 0;
  40. 62 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement