wiki:UnaShellEssenziale

Version 2 (modified by Mattia Monga, 6 years ago) ( diff )

--

int printf(char*, ...);
int scanf(char*, ...);
int strcmp(char*, char*);
int fork();
int waitpid(int, int*, int);
void exit(int);
int execve(char*, char**, char**);

#define NULL (void*)0

int main(){
        char command[4096];
        // Sia argv che envp DEVONO terminare con un elemento NULL
        char* argv[] = {"", NULL};
        char* envp[] = {NULL};

        while (1){
                int pid, status;

                printf("MYSHELL$ ");
                scanf("%s", command);
                if (strcmp(command, "exit") == 0)
                        break;
                pid = fork();
                if (pid != 0) {
                        waitpid(pid, &status, 0);
                } else {
                        argv[0] = command; 
                        execve(argv[0], argv, envp); 
                        printf("Da qui in poi esegue solo se l'execve e` fallita\n");
                        exit(0);
                }
        }
        return 0;
}

Note: See TracWiki for help on using the wiki.