Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<stdlib.h>
- #include<unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <string.h>
- int main(int argc, char *argv[]) {
- int status, i, arg_length, half_arg_length;
- arg_length=strlen(argv[1]);
- char *str = malloc(sizeof(char) * (arg_length));
- char *half = malloc(sizeof(char) * (half_arg_length));
- char *half2 = malloc(sizeof(char) * (half_arg_length));
- printf("%d ", getpid());
- printf("%s \n", argv[1]);
- if(strlen(argv[1])==1) {
- _Exit(0);
- }
- else {
- strcpy(str, argv[1]);
- half_arg_length=arg_length/2;
- for(i = 0; i < half_arg_length; i++) {
- half[i]=str[i];
- half2[i]=str[i + half_arg_length];
- }
- if(fork()==0) {
- wait(&status);
- printf("%d ", getpid());
- execl("./1", "1", half, NULL);
- }
- else
- wait(&status);
- if(fork()==0) {
- wait(&status);
- printf("%d ", getpid());
- execl("./1", "1", half2, NULL);
- }
- else
- wait(&status);
- }
- free(half);
- free(str);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement