项目作者: wiwichips

项目描述 :
Superior Quality Unbeatable Interprocess (communication) Shell, or "squish", is a shell that supports running proceses, piping between processes, handle redirection, support variable globbing, support cd and exit. This shell is compatible on Mac OS and Linux
高级语言: C
项目地址: git://github.com/wiwichips/squish.git
创建时间: 2020-09-12T13:38:53Z
项目社区:https://github.com/wiwichips/squish

开源协议:

下载


SQUISH

Superior Quality Unbeatable Interprocess (communication) Shell, or “squish”, is a shell that supports running processes, piping between processes, handle redirection, variable globbing, cd and exit.

How to Compile and Run

  1. make
  2. ./squish

How errors are handled

  • When entering a command that doesn’t exist, squish will ouput “name: command not found”.
  • The exit status of the command will be outputted if running a single command.

    Piping algorithm

    Processes are piped recursively backwards from the last command. The recursive base case is when there is only one command left to be exec’d.

For ex. p1 | p2 | p2 can be represented as:

  1. squish
  2. /\
  3. / \
  4. /\ p3
  5. / \
  6. p1 p2

Pseudo-code follows as such:

  1. ipc (tokens, nTokens)
  2. {
  3. if ( nTokens == 1 ) {
  4. fork new process
  5. exec ( tokens[0] )
  6. return
  7. }
  8. fork new process
  9. if ( pid == 0 ) {
  10. replace stdout with write end of pipe
  11. ipc (tokens, --ntokens)
  12. }
  13. fork new process
  14. if ( pid == 0 ) {
  15. replace stdin with read end of pipe
  16. exec ( tokens[nTokens] )
  17. }
  18. }

File Structure

Tokenization Files by AHW

squish_main.c
squish_run.c
squish_tokenize.c

“Built-in” CD and exit

w_change_dir.c
w_exit.c

Globbing

w_glob.c

Piping and redirection

w_pipe.c
w_redirection.c

Input parser

w_run.c

Exec wrapper

w_run_command.c

Works Cited

Some of the code is copied from the cis-3050 c examples from the linux.socs server. Wherever that is the case, a comment block will be included above the code snippit.