Hi fellows!
I'm writing a mini-shell to get more familiar with Unix process management in C. It's reading stuff from commandline and passes these arguments via execlp to the system.
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
#define MAXSIZE 100
char prompt[MAXSIZE];
int
main(void){
pid_t pid;
printf("> ");
// read stuff
if (fgets(prompt, MAXSIZE, stdin) == NULL){
printf("Input validation error!");
abort();
}
// printf("DEBUG: %s" , prompt);
if (strcmp(prompt, "exit")==0) abort();
if ((pid=fork())<0){ // copy process
printf("Process error!");
abort();
}
if (pid==0){ // exec in son-prcess
char *command=(char*)strtok(prompt, " ");
execlp(command, command, 0); // overwrite memory
printf("Error, command not found!");
abort();
} else {
waitpid(pid, 0, 0);
}
}
In fact this would be it... but I don't get any output from execlp. Does anybody know why that is?
Thanks ;), Marius