Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- char split(char *s) {
- char *ss;
- int r = 0;
- int i = 0;
- while (s[i] != EOF)
- i++;
- int j = 0;
- for (j = 0; j < i; j++)
- if (s[j] == '/n' || s[j] == '/t' || s[j] == ' ')
- r = j;
- for (j = 0; j < r; j++)
- strcat (ss, s[j]);
- return ss;
- }
- int main (void) {
- while (1) {
- printf ("osh> ");
- scanf ("%s", &text);
- name = split (text);
- if (strcmp (name , "quit") == 1)
- exit (0);
- else {
- strcat (history, "|");
- strcat (history, name);
- }
- pid_t pid;
- int status;
- if ((pid = fork())< 0){
- printf("*** ERROR: forking child process failed\n");
- exit(1);
- }
- else if (pid == 0) {
- if (execvp(*name, name) < 0) {
- printf("*** ERROR: exec failed\n");
- exit(1);
- }
- }
- else {
- while (wait(&status) != pid)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement