Advertisement
KNOSERO

Untitled

Mar 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #define _GNU_SOURCE
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. #include <sys/types.h>
  8. #include <unistd.h>
  9. #include <sys/wait.h>
  10.  
  11. int rounding(int value)
  12. {
  13.     int sh = 1;
  14.     while(sh<=value)
  15.     {
  16.         sh = sh*2;
  17.         if((sh*2) > value)
  18.         break;
  19.     }
  20.     return sh;
  21. }
  22.  
  23. char *save_history(char*argv1, char *argv2)
  24. {
  25.     char*temp;
  26.     if (argv1 == NULL) {
  27.         asprintf(&temp, "%s", argv1);
  28.     }
  29.     else {
  30.         asprintf(&temp, "%s %s", argv1, argv2);
  31.     }
  32.     return temp;
  33. }
  34.  
  35. int IsPowerOfTwo(int value)
  36. {
  37.     if (value ==0 )
  38.     return 0;
  39.     while (value != 1)
  40.     {
  41.         if(value%2 !=0)
  42.             return 0;
  43.         value = value / 2;
  44.     }
  45.     return 0;
  46. }
  47.  
  48.  
  49. int main(int argc, char **argv)
  50. {
  51.    
  52.     //brak argumentu
  53.     if(argc == 1)
  54.         return -1;
  55.    
  56.     //wielkosc
  57.     size_t a = strlen(argv[1]);
  58.    
  59.     if(a == 1)
  60.     {
  61.         printf("%s\n", argv[2]);
  62.     }
  63.     else
  64.     {
  65.         pid_t ppid_1, ppid_2;
  66.         ppid_1 = fork();
  67.         if(ppid_1 == 0)
  68.         {
  69.             execlp("./main", "", "1", argv[1], NULL);
  70.             exit(0);
  71.         }
  72.         else{
  73.             ppid_2 = fork();
  74.             if (ppid_2 == 0)
  75.             {
  76.                 execlp("./main", "", "1", argv[1], NULL);
  77.                 exit(0);
  78.             }
  79.         }
  80.         wait(0);
  81.     }
  82.    
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement