Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <getopt.h>
  3. #include <memory.h>
  4. #include <ctype.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include <sys/wait.h>
  8. #include <math.h>
  9. #include <unistd.h>
  10. #include <stdio.h>
  11. int main(int argc, char * argv[]){
  12. int n,c;
  13. double pot;
  14. int dr=atoi(argv[optind+1]);
  15. int pr=atoi(argv[optind]);
  16. for(n = 0; n < pr; n++){
  17. switch(fork()){
  18. case -1:
  19. perror("tezava pri ustvarjanju novega procesa");
  20. return -1;
  21. case 0:
  22. usleep(1000);
  23. int pot = dr;
  24. for(int i = 1; i<=n; i++){
  25. if(n!=1) {
  26. pot = pot * dr;
  27. }
  28. else pot = 1;
  29. }
  30.  
  31. printf("jaz sem otrok st:%d\n",pot);
  32. _exit(0);
  33. }
  34. }
  35. for(n = 0; n < pr; n++)
  36. {
  37. wait(&c);
  38. }
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement