OperatingSystem代写:CSE320SFISHShellPart5


代写一个类似Shell功能的命令行工具,第五部分也是最后的部分,实现几个琐碎的需求。

Part V: Custom Features

In this last part you will be adding a few custom features that don’t exist in
other shells.You must add support for the following custom keyboard controls:

Ctrl+S: Store PID

This custom shortcut will copy the PID of the first job (it can be a
foreground or background job) in the job list and store it local variable
called SPID . This will be “earliest” job in the job list. If there are no
jobs in the list then SPID is set to -1.

Ctrl+G: Get PID

This custom shortcut will behave differently depending on the value of SPID .
If SPID is the PID of a background process, send it the SIGTERM signal and
inform the user of SPID’s termination. If SPID represents a foreground
process, send it the SIGSTOP signal and inform the user of SPID’s stoppage. If
SPID doesn’t exist (the process was terminated) or is -1 , do nothing and
inform the user that SPID has not been set. In order for Ctrl+G to function
properly it must have been preceded by Ctrl+S. Multiple presses of Ctrl+G
should do nothing and print an error message.
sfish-user@machine:[/tmp]> jobs
[1] Running 9764 yes | grep s
[2] Stopped 9765 grep free
[3] Running 9766 ./infinite
[4] Stopped 9777 wc -l
sfish-user@machine:[/tmp]> #User presses Ctrl-S and then Ctrl-G
[1] 9764 stopped by signal 15
sfish-user@machine:[/tmp]> #User presses Ctrl-G
SPID does not exist and has been set to -1
sfish-user@machine:[/tmp]> jobs
[2] Stopped 9765 grep free
[3] Running 9766 ./infinite
[4] Stopped 9777 wc -l

Ctrl+H: Print Help Menu

Performs the same action as the help builtin.

Ctrl+P: Print SFISH Info

This custom shortcut will print the following:

  • List all builtins available.
  • List how many commands have been run or have been attempted to be run so far (piped commands count as 1)
  • Display a header line followed by lines containing information about all processes running in the shell. If any running job calls fork(2), you must print information about it’s children.
    • PGID - The id of the process group the process belongs to.
    • PID - The PID of the process.
    • TIME - The time the command was started
    • CMD - The command that is running in the shell

Extra Credit

In addition to all the above tasks, you can score up to 40 extra credit points
on this assignment. Before you consider completing any of the extra credit
tasks, you should first make sure that you have a fully working project. For
each extra credit task that you complete, make sure to label it in your README
file as EC1, EC2, …, EC3, so that we know which ones to grade. All extra
credit must work 100% and there is no partial credit.

If you complete an extra credit task and do not label it, it will not be
graded.

Variables and Echo Support

In some sense, a shell actually defines a simple programming language. Like
any self-respecting language, sfish should have variables. In order to avoid
confusion with commands, our shell will require that all variable names start
with a $ character, and only have either alphanumerical names or a single
“special” character (e.g., ? , @ , etc.), and are terminated by a space or
newline.
Examples include $temp , $123 , $@ , $?
Add a few variables:

  • The environment variables
  • $? : A special variable to store the return code of a program.
    You are welcome to add others if you like.
    A shell user may use a variable in a command, and the shell will automatically
    replace the variable with the value of this variable. Similarly, a user may
    assign a new value to a variable (including an environment variable) using the
    builtin set. A useful tool for debugging variables is the echo command.

Git Repository Info

If the current working directory of the shell is a git repository, add
information about it to the prompt. The prompt should display the current
branch and the branch name should be followed by an * if there are uncommitted
changes.

Quoted Arguments

With your shell’s current implementation, running a program that takes an
argument which is a string containing spaces would cause issues. Your shell
would read the argument as if it were many different arguments.
sfish-user@machine:[/tmp]> ./a.out This shouldn’t be one argument
# output from a.out
sfish-user@machine:[/tmp]>

If you were to split on just spaces this program would have 6 arguments
passed to it.

File Globbing

File globbing should work on both relative and absolute paths. The following
are all valid ways file globbing must work:
sfish-user@machine:[/tmp]> ls .jpg
sfish-user@machine:[/tmp]> ls cse320

sfish-user@machine:[/tmp]> ls ../cse320/solutions/*.c


文章作者: SafePoker
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 SafePoker !
  目录