Ask a question to Desklib · AI bot


System Programming: Assignment

Added on -2019-09-16

| 2 pages
| 839 words

Trusted by 2+ million users,
1000+ happy students everyday

tmp6kx8vhqdrequirementdoc-2574.doc1System Programming: A text- based shell is a program that users often interact with. It accepts commands from the users and carries them out, often by issuing corresponding requests to the underlying operating system. There are quite a few different shellprogram existed, such as sh, bash, csh, tcsh, ksh etc. Bash has been the default shell on many Linux system. The name bash stands for "Bourne again shell" where "Bourne shell" was the name of the original sh shell program for Unix. The bash shell uses much of the same syntax as the original shshell, but adds a number of useful features. Bash shell (or any other shell) is simply an executable program that is started when you open a terminal window(e.g press Ctrl-Alt-T in ubuntu. It can also be executed by simply typing it (e.g. bash) from command line in another shell program. It first prints a prompt, then the user types a command and presses Enter. Soon, the program runs. Usually the shell can be terminated by typing exit from command line. Though each shell may have different styles and strengths, they all serve the same purpose and generally provide three main functions: run programs, manage input and output, and be programmed. Most commands used in the shell are just regular executable programs. Some commands are built-in programs that can be found in /bin directory, such as ls, cp, rm. Others may be the external programs, such as emacs, firefox. The shell loads the programs into memory and runs them. Besides using standard input/output such as keyboard/console, most shell can also attach input/output to files or other processes by using <, > and |. The shell is also a programming language with variables and flow controls. Shell script provides a convenient and powerful way to run 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() to create new process and execute the external commands. You shall NOT use system(). In windows, you shall use win32 API on process creation such as CreateProcess(). In Java, you need use Runtime class and corresponding methods such as exec() to create a new process and execute it. (40%)2.Implement built in command cd (change current directory) using chdir() system call. (10%)3.Enable a command to be executed as a background job by using &. That means the shell can proceed to accept another command without waiting the current command to finish. (Be aware that there can be space before & too, such as emacs& or emacs &). (10% point)4.Implement built in command history which will show the last 10 commands typed. (20 points)

Found this document preview useful?

You are reading a preview
Upload your documents to download
Become a Desklib member to get accesss

Students who viewed this