Last active
September 13, 2017 03:21
-
-
Save s4y/b43cb16371d491cf15e9a0a26515da27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
int main() { | |
for (;;) { | |
char* line = NULL; | |
size_t cap; | |
ssize_t sz; | |
printf("> ", stdout); | |
if ((sz = getline(&line, &cap, stdin)) < 1) | |
break; | |
line[sz-1] = '\0'; | |
char* rest = line,* tok = line; | |
char* args[256] = {0}; | |
for (size_t i = 0; i < 255 && (tok = strsep(&rest, " ")); i++) | |
args[i] = tok; | |
if (!fork()) | |
execvp(args[0], args); | |
wait(NULL); | |
free(line); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment