Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <unistd.h>
- int main(int argc, char **argv)
- {
- if (argc < 2)
- exit(EXIT_SUCCESS);
- char* string = argv[argc - 1];
- int length = strlen(string);
- double logLength = log2(length);
- if (floor(logLength) != ceil(logLength))
- {
- int diff = abs((int) (pow(2, ceil(logLength)) - length));
- char temp[80] = "";
- for (int i = 0; i < diff; i++)
- temp[i] = 'd';
- string = strcat(string, temp);
- argv[argc - 1] = string;
- length = strlen(string);
- }
- char **argv2 = (char **)malloc((argc + 2)*sizeof(char *));
- if (length > 1)
- {
- for (int i = 0; i < argc; i++)
- argv2[i] = argv[i];
- argv2[argc] = malloc(length / 2);
- argv2[argc + 1] = NULL;
- int process1, process2;
- process1 = fork();
- if (process1 == 0)
- {
- for (int i = 0; i < length / 2; i++)
- argv2[argc][i] = string[i];
- execv(argv[0], argv2);
- }
- else if (process1 > 0)
- {
- process2 = fork();
- if (process2 == 0)
- {
- for (int i = length / 2; i < length; i++)
- argv2[argc][i - length / 2] = string[i];
- execv(argv[0], argv2);
- }
- }
- }
- wait(NULL);
- wait(NULL);
- printf("%d ", getpid());
- for (int i = 1; i < argc; i++)
- printf("%s ", argv[i]);
- printf("\n");
- free(argv2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement