Witam ;)
Mam problem z pewnym zadankiem.
Muszę przygotować prostą wersję shella:
która pokazuje prompt, przyjmuje polecenie, forkuje i wykonuje exec.
Zadanie mam przygotować z pomocą biblioteki readline.
#include <stdlib.h>
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <pwd.h>
#include <sys/types.h>
#include<sys/wait.h>
#include <unistd.h>
#define CWD 255
#define MAX_SIZE 40
#define MAXC 100
int main (void) {
char ps[MAXC] = "";
char cwd [CWD];
char *input = NULL;
int status;
//nazwa uzytkownika
struct passwd *pw = getpwuid(getuid());
char *user = pw->pw_name;
//katalog biezacy
char *user1 = getcwd(cwd, sizeof(cwd));
sprintf(ps, " > %s %s@ > ", user, user1);
pid_t pid;
while ((input = readline(ps))) {
if (( pid = fork ()) < 0) {
perror("Blad:\n") ;
}
else if (pid == 0) {
//exec ??
return 0;
}
else {
wait(&status);
}
if (!input)
break;
free(input);
}
return 0;
}
Jak teraz to co w input przekazać jako argument do exec?