Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<sys/types.h>
- #include<unistd.h>
- #include "apue.h"
- int main(void){
- char buf[MAXLINE];
- pid_t pid;
- int status;
- printf("%% ");
- while(fgets(buf,MAXLINE,stdin) != NULL){
- if(buf[strlen(buf)-1] == 'n')
- buf[strlen(buf)-1] = 0 ;
- if((pid = fork()) < 0 ){
- printf("fork error");
- }else if(pid == 0){
- execlp(buf , buf, (char * ) 0);
- printf("coulden't exceute : %s",buf);
- exit(127);
- }
- if((pid = waitpid(pid,&status,0)) < 0)
- printf("waitpid error");
- printf("%% ");
- }
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement