Yes this is a HW assignment, but no im not asking for a solution, but just a general "you should start with this" etc..
Here is the assignment, http://cs.uky.edu/~manivann/cs470/hw2.pdf
Just to get a general gist, but basically it's a simple command line interpreter, except we have to use posix commands I believe, (for separate processes) (pid....etc)
I tried to work up some psuedocode, he said was correct but...obviously it's not done. here is what I have
Pseudocode:
int pid;
bool bg;
char *args[50];
bg=false;
//prompt the user with the shell prompt;
bg =getInputAndParse (args); /* the function getInputAndParse gets command from user,
parses the input and places it in args;
returns true if the command ends with &;
otherewise, returns false.
*/
while (args[0]!="exit"){
if ((pid = fork())==0){ //child process
execvp(args[0],args);
printf("execvp failed");
}
else { // parent code
if (!bg)
{waitpid(pid,0,0);}
prompt the user with the shell prompt;
bg=false;
bg =getInputAndParse (args);
} // end parent
} // end while
Any ideas? We can't use the C "system" function library......so im a bit confused as to where to start
I think your pseudocode makes sense, so I looked at the PDF. From the examples he shows for "myshell", he shows the command "pwd". As you know by now, that is supposed to print the full path of the program's current working directory. So without the system() call how do you do it? There is a Standard C Library Function called getcwd(3C). Once you figure out how to do this one, the rest should be a piece of cake!
Hint: You probably want to have a list of commands that your command line interpreter will handle and set up the calls to execvp() from the arguments passed in, unless there is a Standard C Library Function that can handle the command (like getcwd() above.)