Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdbool.h>
- int main()
- {
- pid_t wpid;
- int status = 0;
- bool exit = false;
- while (exit == false){
- char command[50];
- printf(">");
- fgets(command, 50, stdin);
- if (strcmp("exit\n",command) != 0) {
- int i = 0;
- char *pointer = strtok (command, " \n");
- char *tokens[15];
- while (pointer != NULL)
- {
- tokens[i++] = pointer;
- pointer = strtok (NULL, " \n");
- }
- tokens[i] = NULL;
- int make_fork = fork();
- if (make_fork == 0) {
- execvp(tokens[0],tokens);
- }
- while ((wpid = wait(&status)) > 0);
- }
- else {
- exit = true;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement