Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main(int argc, char *argv[])
- {
- int status;
- if(argc!=2)
- {
- fprintf(stderr,"Error1\n");
- exit(1);
- }
- int length=strlen(argv[1]);
- if(length>20)
- {
- fprintf(stderr,"Error2\n");
- exit(1);
- }
- if (length%2==0)
- {
- char *tab1 [length/2];
- char *tab2 [length/2];
- printf("Jestem tu 1\n");
- strncpy(tab1,argv[1],length/2);
- strncpy(tab2,argv[1]+length/2,length/2);
- //printf("%s\n",tab1);
- //printf("%s\n",tab2);
- //Pierwszy potomek
- pid_t cpid = fork();
- if (cpid>0)
- {
- //Drugi potomek
- pid_t ccpid = fork();
- if (ccpid>0)
- {
- waitpid(cpid,&status,0);
- waitpid(ccpid,&status,0);
- printf("%d\t%d\t%s\n",getpid(),cpid,tab1);
- printf("%d\t%d\t%s\n",getpid(),ccpid,tab2);
- }
- else
- {
- execlp(argv[0],argv[0],tab2);
- }
- }
- else
- {
- execlp(argv[0],argv[0],tab1);
- }
- }
- if (length%2==1)
- {
- char tab1[length/2];
- char tab2[length/2+1];
- printf("Jestem tu 2\n");
- strncpy(tab1,argv[1],length/2);
- strncpy(tab2,argv[1]+length/2,length/2+1);
- //printf("%s\n",tab1);
- //printf("%s\n",tab2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement