Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/wait.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #define MAXLINE 1024
- void err_sys(char *msg) {
- fprintf(stderr, "%s\n", msg);
- exit(EXIT_FAILURE);
- }
- int main() {
- char buf[MAXLINE];
- int status;
- pid_t pid;
- printf("%% ");
- while (fgets(buf, MAXLINE, stdin) != NULL) {
- if (buf[strlen(buf) - 1] == '\n')
- buf[strlen(buf) - 1] = '\0';
- if ((pid = fork()) < 0)
- err_sys("hata : fork edilemedi!");
- else if (pid == 0) {
- execlp(buf, buf, (char *)0);
- err_sys("hata : calistirilamadi!");
- }
- if ((pid = waitpid(pid, &status, 0)) < 0)
- err_sys("hata : waitpid calismadi!");
- printf("%% ");
- }
- exit(0);
- }
Add Comment
Please, Sign In to add comment