UNIX shells typically also allow the child process to run in the background or

Unix shells typically also allow the child process to

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

process that performs the command. UNIX shells typically also allow the child process to run in the background, or concurrently. Unless otherwise specified, the parent process waits for the child to exit before continuing. To enable the parent process to run concurrently with the child process, we add an ampersand ( & ) 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. Dalhousie University Faculty of Computer Science
Image of page 1
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_run equals 1; when the user enters exit at the prompt, your program will set should_run to 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. 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
Image of page 2
Image of page 3
Image of page 4

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