Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<sys/types.h>
  4. #include<unistd.h>
  5. #include "apue.h"
  6.  
  7. int main(void){
  8.  
  9. char buf[MAXLINE];
  10. pid_t pid;
  11. int status;
  12. printf("%% ");
  13.  
  14. while(fgets(buf,MAXLINE,stdin) != NULL){
  15.  
  16. if(buf[strlen(buf)-1] == 'n')
  17. buf[strlen(buf)-1] = 0 ;
  18.  
  19. if((pid = fork()) < 0 ){
  20. printf("fork error");
  21. }else if(pid == 0){
  22. execlp(buf , buf, (char * ) 0);
  23. printf("coulden't exceute : %s",buf);
  24. exit(127);
  25.  
  26. }
  27. if((pid = waitpid(pid,&status,0)) < 0)
  28. printf("waitpid error");
  29. printf("%% ");
  30.  
  31. }
  32. exit(0);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement