Skip to content

Instantly share code, notes, and snippets.

@s4y
Last active September 13, 2017 03:21
Show Gist options
  • Save s4y/b43cb16371d491cf15e9a0a26515da27 to your computer and use it in GitHub Desktop.
Save s4y/b43cb16371d491cf15e9a0a26515da27 to your computer and use it in GitHub Desktop.
#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