/A-Simple-Interpreter

Build a simple shell interpreter

Primary LanguageC

A-Simple-Interpreter

The interpreter has the commands as below.

  • Quit the interpreter. Format:
    Q //a single character ‘Q’.

  • Run a command. Format:
    R command_path [arg1 to arg4]
    //a single character ‘R’, followed by the path of the command //the user can supply up to 4 command line arguments
    Behavior:
    a. If command exist, run the command in a child process with the supplied command line arguments
    * Wait until the child process is done
    b. Else print error message “XXXX not found”, where XXXX is the user entered command

  • Run a command in the background. Format:
    B command_path [arg1 to arg4]

    //a single character ‘B’, followed by the path of the command
    // the user can supply up to 4 command line arguments

    Behavior:
    a. If command exist, run the command in a child process with the supplied command line arguments
    * Print “Child XXXX in background”, XXXX should be the PID of the child process
    * Continue to accept user request
    b. Else print error message “XXXX not found”, where XXXX is the user entered command

  • Wait for a background process. Format:
    W job_pid

    //a single character ‘W’, followed by an integer job_pid

    Behavior:
    a. If the job_pid is a valid child pid (generated by the "B" request)
    * Wait on this child process until it is done, i.e. the interpreter will stop accepting request.
    b. Else print error message “XXXX not a valid child”, where XXXX is job_pid entered by user

Assumptions:

a. Non-terminating command will NOT be tested on your interpreter.
b. No ctrl-z or ctrl-c will be used during testing. As we have not covered signal handling in Unix, it is hard for you to take care of these at the moment.
c. Each command line arguments for 'R' and 'B' has less than 20 characters.
d. There are at most 10 background jobs in a single test session.
e. Any background job will be waited by the 'W' request at most 1 time only.