Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<unistd.h>
- #include<stdlib.h>
- #include<sys/wait.h>
- int main ()
- {
- pid_t cpid;
- int c=0;
- char buf[25]="";
- char s[]="exit";
- char *newbuf[25]={0};
- int i=0;
- do { printf("\nprompt> ");
- gets(buf);
- newbuf[0]=strtok(buf," ");
- while(newbuf[i]!=NULL)
- { i++;
- newbuf[i]=strtok(NULL," ");
- }
- i=0;
- do
- { if( buf[i]!=s[i])
- break;
- i++;
- if(i==3)
- { exit(0);}
- }while(i<4);
- cpid=fork();
- if(cpid<0)
- { printf("\nThe fork has failed\n");
- }
- /* if(c=strncmp(buf,p,5)==0)
- { strncpy(newbuf,buf,5);
- for(i=6;i<25;i++)
- printf("%c",buf[i]);
- } */
- if(cpid==0) {
- { execvp(newbuf[0],newbuf);
- }
- }
- memset(buf,0,25);
- memset(newbuf,0,25);
- }while(1);
- return 0;
- }
Add Comment
Please, Sign In to add comment