System Programming: Assignment

Added on - 16 Sep 2019

Trusted by 2+ million users,
1000+ happy students everyday
Showing pages 1 to 1 of 2 pages
tmp6kx8vhqdrequirementdoc-2574.doc1System Programming:A text- based shell is a program that users often interact with. It accepts commandsfrom the users and carries them out, often by issuing corresponding requests to theunderlying operating system.There are quite a few different shellprogram existed, such as sh, bash, csh, tcsh, ksh etc.Bashhas been the default shell on many Linux system. The namebashstands for"Bourne again shell" where "Bourne shell" was the name of the originalshshellprogram for Unix. Thebashshell uses much of the same syntax as the originalshshell, but adds a number of useful features.Bash shell (or any other shell) is simply an executable program that is started whenyou open a terminal window(e.g press Ctrl-Alt-T in ubuntu. It can also be executedby simply typing it (e.g.bash) from command line in another shell program. It firstprints a prompt, then the user types a command and presses Enter. Soon, the programruns. Usually the shell can be terminated by typingexitfrom command line. Thougheach shell may have different styles and strengths, they all serve the same purposeand generally provide three main functions: run programs, manage input and output,and be programmed. Most commands used in the shell are just regular executableprograms. Some commands are built-in programs that can be found in/bindirectory,such asls, cp, rm. Others may be the external programs, such as emacs, firefox. Theshell loads the programs into memory and runs them. Besides using standardinput/output such as keyboard/console, most shell can also attach input/output to filesor other processes by using<,>and|. The shell is also a programming language withvariables and flow controls. Shell script provides a convenient and powerful way torun commands with special environments. Open a terminal by pressing Ctrl+Alt+T,run the following commands (separated by comma) each in a separate line and checkthe results:ps, pwd, bash, ps, ls, ls /bin, firefox &, ps aux | grep firefox, ls /bin >builtincmds, less builtincmds, history, gedit.In this assignment, you are required to extend the very basic shell I provided to you orrewrite it from scratch. You can use C or C++ or even Java.1.The basic shell that accepts a single command with parameters from keyboard,fork a child process and run it. In Linux, you shall use fork() and execvp() tocreate new process and execute the external commands. You shall NOT usesystem(). In windows, you shall use win32 API on process creation such asCreateProcess(). In Java, you need use Runtime class and corresponding methodssuch as exec() to create a new process and execute it. (40%)2.Implement built in commandcd(change current directory) using chdir() systemcall. (10%)3.Enable a command to be executed as a background job by using&. That meansthe shell can proceed to accept another command without waiting the currentcommand to finish. (Be aware that there can be space before & too, such asemacs&oremacs &). (10% point)4.Implement built in command history which will show the last 10 commandstyped. (20 points)
Desklib Logo
You are reading a preview
Upload your documents to download or

Become a Desklib member to get access