Basic C Shell - Any help greatly appreciated !

+1 James Llana · November 17, 2015
Im stuck on a piece of coursework which requires me to write a basic shell in C to be run on minix, following the pseudo code below (1). This is my first time using C and at the minute its all a little over my head. Ive just about managed to write the first part of the program (prompting user for input, then parsing the input into tokens to break down into commands and arguments). 

Im not looking for someone to juts do the work for me and then give me the answer, what i really need is help to understand what it is that i need to do to complete the task (i.e. a general outline, resources i can use, etc.) 

Any help would be greatly appreciated! 

James
_______________________________ 
(1) 

#define TRUE 1 
/* declare cmd, params, envp, stat, prompt, readcmd */  

while (TRUE) {                               /* repeat forever */ 
     prompt();                                   /* display prompt */  
     readcmd(cmd, params);            /* read input from terminal*/ 
     if (fork() != 0) {                           /* fork child process */ 
          /* parent code */ 
          waitpid(-1, &stat, 0);             /* wait for child */ 
          } else { 
          /* child code */ 
          execve(cmd, params, envp); /* execute command */  
          } 
     } 
}

Post a Reply

Replies

Oldest  Newest  Rating
+1 Dan P · November 21, 2015
I'm not sure that the question is specific enough to answer.

There are lots of ways to do things, and quite often the design is what separates a good developer from a bad one.

As this is a task for coursework, I would imagine that they are expecting you to investigate and document what you think you would do to create a shell. Once you have created the shell, you should look back over it and consider what you did badly, or how it could be improved.

There are also lots of shells with source available, I suggest having a look at some of those to see how they have implemented it. I would also try to understand why they have implemented it in the ways that they have, and ask yourself if there are any ways that you feel that it could have been improved.

Remember, they are asking for a basic shell, and one big aspect of programming is working to a spec. If you create something too complex, then you haven't really done what has been asked.
  • 1

C

107,082 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator