Skip to content

Instantly share code, notes, and snippets.

@gdemir
Created October 22, 2010 14:08
Show Gist options
  • Save gdemir/640588 to your computer and use it in GitHub Desktop.
Save gdemir/640588 to your computer and use it in GitHub Desktop.
#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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment