Thus if we rewrite the above command as CSCI3120 cat progc the parent and child

Thus if we rewrite the above command as csci3120 cat

This preview shows page 1 - 3 out of 4 pages.

) 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
Image of page 1
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[0] = "ps" args[1] = "-ael" args[2] = NULL This args array will be passed to the execvp() function, which has the following prototype:
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 4 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture