Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/wait.h>
- int rounding(int value)
- {
- int sh = 1;
- while(sh<=value)
- {
- sh = sh*2;
- if((sh*2) > value)
- break;
- }
- return sh;
- }
- char *save_history(char*argv1, char *argv2)
- {
- char*temp;
- if (argv1 == NULL) {
- asprintf(&temp, "%s", argv1);
- }
- else {
- asprintf(&temp, "%s %s", argv1, argv2);
- }
- return temp;
- }
- int IsPowerOfTwo(int value)
- {
- if (value ==0 )
- return 0;
- while (value != 1)
- {
- if(value%2 !=0)
- return 0;
- value = value / 2;
- }
- return 0;
- }
- int main(int argc, char **argv)
- {
- //brak argumentu
- if(argc == 1)
- return -1;
- //wielkosc
- size_t a = strlen(argv[1]);
- if(a == 1)
- {
- printf("%s\n", argv[2]);
- }
- else
- {
- pid_t ppid_1, ppid_2;
- ppid_1 = fork();
- if(ppid_1 == 0)
- {
- execlp("./main", "", "1", argv[1], NULL);
- exit(0);
- }
- else{
- ppid_2 = fork();
- if (ppid_2 == 0)
- {
- execlp("./main", "", "1", argv[1], NULL);
- exit(0);
- }
- }
- wait(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement