Guest User

Untitled

a guest
Jun 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/wait.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #define MAXLINE 1024
  7.  
  8.  
  9. void err_sys(char *msg) {
  10.  
  11. fprintf(stderr, "%s\n", msg);
  12. exit(EXIT_FAILURE);
  13. }
  14.  
  15. int main() {
  16. char buf[MAXLINE];
  17. int status;
  18. pid_t pid;
  19. printf("%% ");
  20. while (fgets(buf, MAXLINE, stdin) != NULL) {
  21. if (buf[strlen(buf) - 1] == '\n')
  22. buf[strlen(buf) - 1] = '\0';
  23.  
  24. if ((pid = fork()) < 0)
  25. err_sys("hata : fork edilemedi!");
  26. else if (pid == 0) {
  27. execlp(buf, buf, (char *)0);
  28. err_sys("hata : calistirilamadi!");
  29. }
  30. if ((pid = waitpid(pid, &status, 0)) < 0)
  31. err_sys("hata : waitpid calismadi!");
  32. printf("%% ");
  33. }
  34. exit(0);
  35. }
Add Comment
Please, Sign In to add comment