) at the end of the command. Thus, if we rewrite the above command as CSCI3120> cat prog.c & the parent and child processes will run concurrently. The separate child process is created using the fork()system call, and the user’s command is executed using one of the system calls in the exec()family. A C program that provides the general operations of a command-line shell is shown in the code snippet below. The main()function presents the prompt CSCI3120>and outlines the steps to be taken after input from the user has been read. The main()function continually loops as long as should_runequals 1; when the user enters exitat the prompt, your program will set should_runto 0 and terminate. This project is organized into two parts: (1) creating the child process and executing the command in the child, and (2) modifying the shell to allow a history feature. Dalhousie University Faculty of Computer Science
Part I — Creating a Child Process The first task is to modify the main() function in the code shown above so that a child process is forked and executes the command specified by the user. This will require parsing what the user has entered into separate tokens and storing the tokens in an array of character strings ( args in above code). For example, if the user enters the command ps -ael at the CSCI3120> prompt, the values stored in the args array are: args = "ps" args = "-ael" args = NULL This args array will be passed to the execvp() function, which has the following prototype:
You've reached the end of your free preview.
Want to read all 4 pages?
- Spring '14
- Operating Systems, Exit, Child process